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?
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 :-)