Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can't connect to cassandra - NoHostAvailableException

I know there are several threads about the NoHostAvailableException but they simply don't provide a solution to my problem.

I can't connect to Cassandra with the Datastax Java Cassandra Driver. I get the Error:

com.datastax.driver.core.exceptions.NoHostAvailableException: All host(s) tried for query failed (tried: [/54.221.241.107])

I am sure that the configuration is correct. I've set the configuration in cassandra.yaml:

start_native_transport: true 
# port for the CQL native transport to listen for clients on 
native_transport_port: 9042 

My Cassandra installation is a standard installation on a EC2 instance on AWS. I've configured AWS to allow port 9042.

Cassandra is running on Windows Server 2008 R2 and I also configured the firewall to inbound and outbound connection on 9042.

My code looks like the following:

cluster = Cluster.builder()
  .withPort(9042)
  .addContactPoint("54.221.241.107").build();

I don't know what to do anymore since I always get this error. Any suggestions?

like image 210
user2280013 Avatar asked Sep 10 '13 16:09

user2280013


2 Answers

Check your casssandra.yaml file. The native_transport uses the same address binding as the rpc_address. If it is bound to another address than "54.221.241.107" you would get this problem. Try setting it to

rpc_address: 0.0.0.0 

or to

rpc_address: 54.221.241.107  

and see if it helps. Keep in mind that ec2-ips might change on restarts.

My guess is that is is bound to the internal ip of the ec-2. And remember to add some security if you are opening up your database to the public this way :-)

like image 100
polve Avatar answered Sep 20 '22 01:09

polve


Change public IP to private IP.

  • If your cassandra is in EC2, you need to configure private IP in yaml configurations rpc_address: PRIVATE_IP.

  • If your client program (java app used to connect cassandra) is also in EC2 then you should add private IP in your code .addContactPoint("PRIVATE_IP").build();.

  • If your cassandra is in EC2 and your client app is in out of EC2 (means client java app in your local network) you need to configure private IP in yaml configurations and public IP in your java app

Then important point is mentioning native_transport_port: 9042, allow access for port 9042 and Firewall configurations. I think these things you did correctly. And also ensure that you have properly configured your endpoint snitch endpoint_snitch: Ec2Snitch in your yaml file. I Hope it will work if you follow these steps....

like image 20
Jaya Ananthram Avatar answered Sep 21 '22 01:09

Jaya Ananthram