Saturday, 8 September 2018

NoHostAvailableError: All host(s) tried for query failed

I've installed Cassandra on one EC2 instance that contains one keyspace with SimpleStrategy and replcation factor 1.

I've also made port 9042 accessible from anywhere in the security group.

I have a Node.js application that contains the following code:

const cassandra = require('cassandra-driver');
const client = new cassandra.Client({ contactPoints: ['12.34.567.890:9042',], keyspace: 'ks1' });

const query = 'CREATE TABLE table.name ( field1 text, field2 text, field3 counter, PRIMARY KEY (field1, field2));';

client.execute(query)
    .then(result => console.log(result));

which produces the following error:

NoHostAvailableError: All host(s) tried for query failed. First host tried, 12.34.567.890:9042: DriverError: Connection timeout. See innerErrors.

I use cassandra-driver.

I've made sure Cassandra is running.

Edit:

As Aaron suggested, I have installed cqlsh on the client machine. When I go cqlsh 12.34.567.890 9042, it returns:

Connection error: ('Unable to connect to any servers', {'12.34.567.890': error(10061, "Tried connecting to [('12.34.567.890', 9042)]. Last error: No connection could be made because the target machine actively refused it")})

As Aaron suggeted, I have edited Cassandra.yaml on the server and replaced localhost with 12.34.567.890. I'm still getting the same error though.



from NoHostAvailableError: All host(s) tried for query failed

No comments:

Post a Comment