Can't connect to cassandra node from different host
Asked Answered
S

8

19

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?

Sierrasiesser answered 3/1, 2015 at 19:37 Comment(0)
T
19

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).

Tannenberg answered 3/1, 2015 at 19:45 Comment(5)
When I used 0.0.0.0,I'm getting rg.apache.cassandra.exceptions.ConfigurationException: listen_address cannot be a wildcard address (0.0.0.0)! at system.logSierrasiesser
This depends on the version of cassandra you are using. As you see here, in v 2.0 wildcards are allowed. If you are using a different version, use your remote address.Tannenberg
Is there any other changes to get same result for java driver?Sierrasiesser
The Java driver should be able to connect if there are no network issues (every node of the cluster must be reachable). Check also, with "nodetool status" if every node of the cluster sees each other.Tannenberg
Yeah like servers have only one adapter ! All other servers support 0.0.0.0 (JBoss, etc). Why are datastax folks so special ? If only their product was good, may be they could.Kadiyevka
M
5

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.

Microanalysis answered 24/6, 2015 at 1:14 Comment(1)
In my case, I also had to edit - seeds: "10.131.33.51" instead of 127.0.0.1 in the "seed_provider" field, where 10.131.33.51 is the address of the machine running Cassandra in my case. Use your machine’s IP address in your setup.Sisneros
T
5

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

Tanning answered 6/11, 2015 at 7:32 Comment(0)
G
3

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/

Geronto answered 27/9, 2017 at 20:11 Comment(0)
P
1

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.

Prowl answered 15/10, 2019 at 21:46 Comment(0)
V
0

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.

Variegated answered 22/12, 2016 at 19:8 Comment(0)
L
-1

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

  1. Access the firewall from “System / Administration / Firewall” in the CentOS menu
  2. Add the port under “Other Ports”
Lambency answered 8/8, 2017 at 18:22 Comment(0)
D
-2

I edit cassandra.yaml set listen_address and roc_address as ip address resolve the problem.

Decern answered 10/9, 2016 at 1:45 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.