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 Cassand
Had the same problem.Later figured out that Driver version and CQL version were not compatible.Get the latest 3.0 Driver according to the compatibility chart
http://www.datastax.com/dev/blog/java-driver-2-1-2-native-protocol-v3
Accessing Cassandra using java driver very much depends on the driver version and the dependencies of the driver. The final thing that worked for me was to take the lib(jars) that are bundled on the server download. In my case it was windows. But I am sure the linux tar balls also will have the driver and the dependencies in them. take the jars shipped in the server download and use them in your java client's classpath instead of downloading the drivers separately from the internet
I also stumbled on that issue recently. My environment was different and reason was also different. We used SpringBoot 1.5.3.RELEASE as parent library and Datastax cassandra driver version 3.3.0:
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>1.5.3.RELEASE</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
............
<dependencies>
<dependency>
<groupId>com.datastax.cassandra</groupId>
<artifactId>cassandra-driver-core</artifactId>
<version>3.3.0</version>
<exclusions>
<exclusion>
<groupId>io.netty</groupId>
<artifactId>netty-handler</artifactId>
</exclusion>
</exclusions>
</dependency>
.......
The Netty library inherited from SpringBoot's parent POM and Datastax has clashed. After excluding Netty the error went away.
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 :-)
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....