我正在尝试使用python访问远程Cassandra集群cassandra-driver
如下所示:
cluster = Cluster(['192.168.19.1'], port=9042)
session = cluster.connect()
但是,它给了我:
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")})
我在nodetool status
上的Cassandra集群显示:
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
例如 - 我在 192.168.19.1 主机上的cassandra.yaml
参数如下:
rpc_address: 192.168.19.1
listen_address: 192.168.19.1
native_transport_port: 9042
start_native_transport: true
问题的原因可能是什么?
尝试增加连接超时,即使在同一台主机上(更不用说您的远程主机(,它也可能非常长。
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()