7

I am trying to access a remote Cassandra cluster using python cassandra-driver like this:

cluster = Cluster(['192.168.19.1'], port=9042)
session = cluster.connect()

However, it gives me:

cassandra.cluster.NoHostAvailable: ('Unable to connect to any servers',
'192.168.19.1': error(None, "Tried connecting to [('192.168.19.1', 9042)].
Last error: timed out")})

My Cassandra cluster on nodetool status shows:

Datacenter: datacenter1
=======================
Status=Up/Down
|/ State=Normal/Leaving/Joining/Moving
--  Address       Load       Tokens       Owns (effective)  Host ID                                  Rack
UN  192.168.19.1  239,55 KiB  256          67,0%             e45b9451-0081-4b12-9acb-1bc9   92953846  rack1
UN  192.168.19.2  263,95 KiB  256          63,8%             662df0f8-4209-4b06-9d46-f558   ad10ff0a  rack1
UN  192.168.19.3  293,59 KiB  256          69,2%             aa00fc80-6a8a-4bb0-8645-ef3f   58a72754  rack1

For example - my cassandra.yaml parameters on the 192.168.19.1 host are as follows:

rpc_address: 192.168.19.1

listen_address: 192.168.19.1

native_transport_port: 9042

start_native_transport: true

What could be the reason of the problem?

mirekphd
  • 4,799
  • 3
  • 38
  • 59
jOasis
  • 394
  • 2
  • 10
  • 32
  • Did you mention keyspace? – Rubayat Jinnah Jan 06 '18 at 12:10
  • did you check that the port is really available, with something like: `telnet IP 9042`, etc. – Alex Ott Jan 06 '18 at 12:18
  • Are you in the same subnet ? From which IP are you accessing? – Chakri Stark Jan 07 '18 at 16:59
  • @ChakriStark I just noticed I am in different subnet. And I was using its private IP 192.168.19.1 to access it. Should I change the cassandra.yaml file of each of the node with the following: rpc_address: 0.0.0.0 broadcast_rpc_address: And then do cluster = Cluster([''], port=9042) session = cluster.connect() ? – jOasis Jan 07 '18 at 17:48
  • Then it will become Ec2Snitch configuration. It should work with present configuration that you are using.. I am using C driver and its working fine for me – Chakri Stark Jan 09 '18 at 04:53

1 Answers1

1

Try to increase connection timeout, it may be surprisingly long even on the same host (not to mention your remote one).

conn_timeout_ms = 200

cas_cluster = Cluster(contact_points=['192.168.19.1'], 
                      port=9042,
                      connect_timeout=conn_timeout_ms / 1000 # ms -> s
                      )

cas_session = cas_cluster.connect()

mirekphd
  • 4,799
  • 3
  • 38
  • 59