Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
581 views
in Technique[技术] by (71.8m points)

datastax java driver - 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?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...