Now I have a VM on google cloud platform which was created by someone else
and he configured a cassandra on the VM.I'd like to access this cassandra node.
I used the IP to access it, but I failed.I don't know whether the cassandra is running on the VM.
How can I verify that?
If you can access over ssh then ps aux | grep cassandra or try to telnet 9042 port.
At first, ssh to the server by using your username , password and ip:
For Example:
$ ssh jack#11.1.41.1
Use jps to find the cassandra process:
[jack#11.1.41.1 ~]$ jps
1136 CassandraDaemon
15314 Jps
If you see, CassandraDaemon is running with a process id, then you can be assured that cassandra is running on this server.
You can try Nodetool to check the status too. If Nodetool command worked, then it's confirmed that cassandra is running.
[jack#11.1.41.1 ~]$ nodetool status
By default, Google Compute Engine VMs only expose port 22 (SSH), not any application ports, because that would be insecure.
If you want to connect to a Cassandra server running on a GCE VM, you should create an SSH tunnel with port forwarding, and then access the Cassandra server via that SSH tunnel.
Specifically, follow the tutorial by running this command (adjusted from the original to use the Cassandra port 9042 for native clients):
gcloud compute ssh example-instance \
--project my-project \
--zone us-central1-a \
--ssh-flag="-L" \
--ssh-flag="2222:localhost:9042"
In the above command, the parameters are defined as follows:
example-instance is the name of the instance to which you'd like to
connect.
my-project is your Google Cloud Platform project ID.
us-central1-a is the zone in which your instance is running.
2222 is the local port you're listening on.
9042 is the remote port you're connecting to.
[...]
The gcloud command creates and maintains an SSH connection, and this approach only works while the SSH session is active. As soon as you exit the SSH session that gcloud creates, port forwarding via localhost:2222 will stop working.
If you want to create more than one port forwarding rule, you can specify multiple rules on a single command line by repeating the flags:
gcloud compute ssh example-instance \
--project my-project \
--zone us-central1-a \
--ssh-flag="-L" \
--ssh-flag="2222:localhost:9042" \
--ssh-flag="-L" \
--ssh-flag="2299:localhost:8000"
Alternatively, you can run a new gcloud command each time to create a separate tunnel. Note that you cannot add or remove port forwarding from an existing connection without exiting and re-establishing the connection from scratch.
Make appropriate substitutions as necessary; for example, according to the Cassandra docs on port usage:
By default, Cassandra uses 7000 for cluster communication (7001 if SSL is enabled), 9042 for native protocol clients, and 7199 for JMX (and 9160 for the deprecated Thrift interface). The internode communication and native protocol ports are configurable in the Cassandra Configuration File. The JMX port is configurable in cassandra-env.sh (through JVM options). All ports are TCP.
If you have a custom configuration for Cassandra ports, you will need to take that into account, of course.
Related
I'm just getting started with gcloud vm's and trying to secure them up a bit. If I change the ssh port, what switch/flag do I add to the gcloud command when using the gcloud command like this
gcloud beta compute ssh --zone "us-east4-c" "base" --project "testproject"
Thanks!
After checking this GCP doc, you can see that you'll be able to set a custom port by adding a flag called --ssh-flag.
For example:
gcloud compute ssh example-instance --zone=us-central1-a --project=project-id --ssh-flag="-p 8000"
It is also applicable for gcloud beta:
gcloud beta compute ssh example-instance --zone=us-central1-a --project=project-id --ssh-flag="-p 8000"
The sample commands will SSH to your Compute Engine instance on port 8000.
Note: Before connecting, make sure you have an ingress Firewall Rule that accepts TCP on the port you've chosen.
UPDATE: If above is not working and you are getting connection refused, it means you need to configure your VM to listen to the port you wanted. Here are the steps:
Go to sshd configuration file : sudo vi /etc/ssh/sshd_config
Add your chosen port for example:
Save the file.
Restart sshd service : sudo systemctl reload sshd.service
I am setting up two nodes, one node where cassandra is running and other node where my spring-boot service is running which uses cassandra database. I am unable to connect to the cassandra node from other service node(tried with- telnet 'cassandra node ip' 'cassandra port number'). I tried with modifying cassandra.yml. I changed "listen_address" and "rpc_address" to node address but cassandra is not starting with this configuration(Connection refused). Is there any other configuration i need to do? Java version-8, Cassandra version- 3.11.4.
If you can't telnet to it, then you definitely won't be able to connect to it. Are you sure there are no firewalls in place? On the cassandra server you're trying to telnet to, can you run:
netstat -nap | grep 9042 | grep LISTEN
Whatever port you specified for your native_transport_port in cassandra.yaml.
or
lsof -i TCP | grep cassandraPid | grep LISTEN"
Where the "cassandraPid" is the process ID of the cassandra process
Can you connect using cqlsh on the cassandra host when specifying the host and port? If you can, then there is a firewall blocking your client server. If not, then again, check your port settings.
I have a cassandra node at a machine. When I access cqlsh from the same machne it works properly.
But when I tried to connect to it's cqlsh using "192.x.x.x" from another machine, I'm getting an error saying
Connection error: ('Unable to connect to any servers', {'192.x.x.x': error(111, "Tried connecting to [('192.x.x.x', 9042)]. Last error: Connection refused")})
What is the reason for this? How can I fix it?
Probably the remote Cassandra node is not bound to the external network interface but to the loopback one (this is the default configuration). You can ensure this by using "telnet thecassandrahost 9042" from the remote machine, it should not work.
In order to bind Cassandra to the external network interface you need to edit the cassandra.yaml configuration file and set the properties "listen_address" and "rpc_address" to your remote IP or "0.0.0.0" (not all versions of Cassandra support wildcard addresses).
Check also that the firewall is properly configured or disabled (sudo service iptables stop).
Set the config parameter where this file is located. Possibly /etc/cassandra/cassandra.yaml.
cassandra.yaml
listen_address: 192.x.x.x
rpc_address: 192.x.x.x
Then, restart the service.
1.Update:./conf/cassandra.yaml
rpc_address: 0.0.0.0 ("0.0.0.0" allow anywhere IP,but you can appoint an IP)
\# broadcast_rpc_address: 1.2.3.4 (Delete comment if rpc_address=0.0.0.0)
2.restart
./bin/cassandra
Case: I met a problem that I can't remote access cassandra When I using java access cassandra
I got the same issue. And I am following answer in this post. Unfortunately, I have no luck to make it work. I did some research. And it works now. Here is my change.
Environment
Ubuntu Server 16.04.3 LTS on VirtualBox,
DSE version 5.1
Install DSE
I am installing DSE follow this page
https://docs.datastax.com/en/dse/5.1/dse-dev/datastax_enterprise/install/installGUIdse.html
Go to /etc/dse/cassandra/cassandra.yaml
Change 'seeds' from 127.0.0.1 to {seriver ip} exp. mine is 172.20.10.9
listen_address
In DSE 5.1 official document says 'Never specify 0.0.0.0; it is always wrong.'
What I did is comment out 'listen_address' setting
'rpc_address' change from localhost to 0.0.0.0
'broadcast_address' change to server IP. Mine is 172.20.10.9
'broadcast_rpc_address' change to server ip
restart dse wait for couple minute,it is changing. If still not work, restart machine.
This is my log in 15 seconds.
`ubuntu08#ubuntu08:~$ nodetool status
nodetool: Failed to connect to '127.0.0.1:7199' - ConnectException: 'Connection refused (Connection refused)'.
ubuntu08#ubuntu08:~$ nodetool status
Error: The node does not have system_traces yet, probably still bootstrapping
ubuntu08#ubuntu08:~$ nodetool status
Datacenter: SearchGraphAnalytics
Status=Up/Down
|/ State=Normal/Leaving/Joining/Moving
-- Address Load Tokens Owns Host ID Rack
UN 10.0.0.44 278.51 KiB 32 ? 19db0016-df63-4470-9921-f3b5fe4e9341 rack1
`
I can access by run 'cqlsh 172.20.10.9' from local or another machine.
This is another document for Cassandra https://docs.datastax.com/en/developer/java-driver/3.3/manual/address_resolution/
I had the same issue, I was not allowed to listen to 0.0.0.0 and Cassandra was running on a VM with Bridged network. The solution I found was to let the VM SSH to itself, port forwarding the port on the bridged network interface to localhost:
ssh -L 192.168.x.x:9042:127.0.0.1:9042 myvmuser#localhost
Since the IP of the bridged network card would change (depending on which developers machine it was run) the ssh-command had to first get the IP, this snipped worked for that:
ifconfig | grep -Eo 'inet (addr:)?([0-9]*\.){3}[0-9]*' | grep -Eo '([0-9]*\.){3}[0-9]*' | grep -v '127.0.0.1'
Also, as this should happen on boot you have to create a SSH key for the vm-user and trust it via .ssh/authorized_keys.
Even after I set the RPC_ADDRESS, it didn't work for me , until I set the -e CASSANDRA_START_RPC=true option.
It was always set to false in my case. I have tried this with Ubuntu, Docker and Cassandra.
Set the following config parameter in cassandra.yaml file (For CentOS it is located in /etc/cassandra/default.conf)
rpc_address: 0.0.0.0
Verify that following values are same as below(usually they are default)
start_native_transport:true
native_transport_port:9042
Last step for CentOS , Update the firewall configuration and allow port 9042 through for incoming connections
Access the firewall from “System / Administration / Firewall” in the CentOS menu
Add the port under “Other Ports”
I edit cassandra.yaml set listen_address and roc_address as ip address resolve the problem.
I set rpc_port to the public IP address, and now I can connect to Cassandra just fine from an outside server.
However, I cannot connect from the Cassandra server itself, using cqlsh
I am getting an error.Thar are:
Connection error: Could not connect to localhost:9160
Is there a configuration, I can change to be able to connect from the server itself ?
Check the cassandra.yaml file on the line with rpc_port : normally by default = 9160
Login to the machine hosting cassandra
Try cqlsh 127.0.0.1 9160 : should be ok in any case
try cqlsh [IP of host] 9160 : if ok then cassandra reachable from lan, if ok then cassandra is not reachable from lan but only localhost 127.0.0.1
You need to connect to cassandra through the rpc_address defined in cassandra.yaml. For example, I use cqlsh 10.0.80.49 9160.
Consider changing /etc/cassandra.yaml:
# Whether to start the thrift rpc server.
start_rpc: false
to
start_rpc: true
if you see this in cassandra logs:
INFO [main] 2015-07-21 12:06:27,426 CassandraDaemon.java:406 - Not starting RPC server as requested. Use JMX (StorageService->startRPCServer()) or nodetool (enablethrift) to start it
then just open a terminal and
$ nodetool enablethrift
as written in the INFO message. Should now work. Got this when my system upgraded to cassandra 2.2.0
If you are on OSX
brew install cassandra
First start the Cassandra
cassandra
Connect via CQL shell
cqlsh 127.0.0.1
Maybe start cassandra on your local machine by bin/cassandra -f first?
It's not listening on 127.0.0.1 since you told it to only listen on <public IP>. Make the listen address 0.0.0.0 to listen on all addresses (or just omit it if possible as this is usually the default). See Listening Sockets .NET tutorial or any other socket tutorial to get a basic understanding of socket binding.
Update (#c45556037):
Note that listen_address is the one for other nodes to use to connect to this one (a misleading name). rpc_address is the actual address to locally bind to. It's unclear from the 2.0 docs and is explained better in the 1.0 docs.
I faced same situation while starting cqlsh . I got following error while starting cassandra
Enter only ----cassandra----- in terminal.
it will show all jars and log files . if terminal hang , just escape from it and then enter cqlsh. then it will enter to cassandra cli.
This worked for me
for 2.0.5 the following works for me ..
$CASSANDRA_HOME/bin/cqlsh xx.xx.xxx.xxx 9160
Exception connecting to localhost/9160. reason: connection refused
Connection refused to cassandra cli mode .
goto the root directory of cassandra :
bin/cassandra -- host {host-ip} --port {9160}
if you are having trouble with this , check your {cassandra-root-directory}/conf/cassandra.yaml
the thrift ip or rpc_address is the address used as the host-ip for connecting to cli .
make it your local IP and if you are having trouble connecting using the port 9160 , try changing the rpc_port to 8070 and now try connecting to cassandra-cli mode using the command
bin/cassandra --host {local-IP} --port 8070
This worked for me, hope it works for you too .
Please execute the below query to resolve the issue
#!/bin/bash
export CASSANDRA_HOME=/opt/apache-cassandra-2.1.8
export CQLSH_HOST=192.168.1.200
export CQLSH_PORT=9042
echo $#
$CASSANDRA_HOME/bin/cqlsh $#'
Make sure to change the IP and location of cassandra Home Directory
Use this command
sudo service cassandra start
to start cassandra and then use
cqlsh command
Consider changing /etc/cassandra-env.sh:
JVM_OPTS="$JVM_OPTS -Dcom.sun.management.jmxremote.ssl=true"
not "true" but "false"
JVM_OPTS="$JVM_OPTS -Dcom.sun.management.jmxremote.ssl=false"
sudo service cassandra restart
How to change default port 9042 in Cassandra ?
I resolved issue using below steps :
1) Stop cassandara services
sudo su -
systemctl stop datastax-agent
systemctl stop opscenterd
systemctl stop app-dse
2) Take backup and Change port from 9042 to 9035
cp /opt/dse/resources/cassandra/conf/cassandra.yaml /opt/dse/resources/cassandra/conf/bkp_cassandra.yaml
vi /opt/dse/resources/cassandra/conf/cassandra.yaml
native_transport_port: 9035
3) Start Cassandra services
systemctl start datastax-agent
systemctl start opscenterd
systemctl start app-dse
4) create cqlshrc file.
vi /root/.cassandra/cqlshrc
[connection]
hostname = 198.168.1.100
port = 9035
OS: CentOS 6.4 (server)
I have successfully installed (yum install dsc20) the cassandra database layer in my server and can connect to it using the CQL SHel (cqlsh). But I need to run queries remotely using the DataStax's DevCenter software. So I installed it (DevCenter) in a separate workstation. (CentOS 6.4 - desktop) and tried to add a new connection in order to connect to the cassandra db.
So I gave the IP of the "CentOS 6.4 - server" (in which cassandra database is running) for the host and the port as 9160. But when testing the connection it fails.
I also tried to turn off the firewall in the server, (/etc/init.d/iptables stop). But was no luck.
I'm sure this may be due to some misconfiguration which I cannot figure out. I'll be grateful, if someone can give me a solution for this as I was researching for this and found no answers. Thank you very much in advance.
DataStax DevCenter being built on top of the DataStax Java driver has the same connectivity requirements as the driver. Namely:
start_native_transport: true
rpc_address: IP or hostname reachable from the client
Machines in the cluster accept connections on port 9042 (the native_transport_port config option)
If rpc_address is set to either a private IP or to 0.0.0.0, DevCenter will not know what node to connect to.
If your cluster has multiple nodes and these are using rpc_address: 0.0.0.0, even if you configure DevCenter with the IP(s) of a couple of nodes, it will still have issues discovering the other nodes in the cluster.
In cassandra.yaml there's a comment/warning about using rpc_address: 0.0.0.0:
Note that unlike ListenAddress above, it is allowed to specify 0.0.0.0
here if you want to listen on all interfaces, but that will break clients
that rely on node auto-discovery.
Note: it is possible that in the future DevCenter might be able to ignore/filter out nodes in the cluster configured with rpc_address: 0.0.0.0.
Try this.. It worked for me!
Run the following command on your machine where you have DevCenter installed
$> ssh -L 9042:localhost:9042 <username>#<ip-address-cassandra-db> -N
After running this command, it will prompt for password
Now in your DevCenter > Contact Hosts, provide "127.0.0.1" and test connection. Bingo, you see the magic...
In the cassandra.yaml, I set
listen_address: localhost
rpc_address: 1.2.3.4
broadcast_rpc_address: 1.2.3.4
After doing a
sudo service cassandra restart
DevCenter was able to successfully connect.
After this change, cqlsh would not start without the address:
cqlsh 1.2.3.4
You can set the environment variable $CQLSH_HOST=1.2.3.4. Then simply type cqlsh.
If there's somebody working with docker locally, it can run this command.
docker run --name cassandra -p 127.0.0.1:9042:9042 -p 127.0.0.1:9160:9160
-e CASSANDRA_LISTEN_ADDRESS=localhost
-e CASSANDRA_BROADCAST_ADDRESS=localhost
-e CASSANDRA_RPC_ADDRESS=localhost -d cassandra