如何解决Apache Cassandra连接问题?

时间:2019-09-07 13:55:07

标签: database cassandra cqlsh

我尝试使用 cqlsh

访问Apache Cassandra

但是它返回错误

Connection error: ('Unable to connect to any servers', {'127.0.0.1': error(111, "Tried connecting to [('127.0.0.1', 9042)]. Last error: Connection refused")})

2 个答案:

答案 0 :(得分:1)

有多个选项:

a)使用密钥cassandra.yamllisten_address文件中定义的IP地址

# cat cassandra.yaml | grep listen_address:
listen_address: 172.1.2.3
# cqlsh 172.1.2.3
Connected to keyspace1 at 172.1.2.3:9042.
[cqlsh 5.0.1 | Cassandra 3.11.4 | CQL spec 3.4.4 | Native protocol v4]
Use HELP for help.

b)如果您使用的是Linux,则命令hostname可能会对此有所帮助:

# cqlsh $(hostname)
Connected to keyspace1 at test-c-ca5d61df000b73cb4:9042.
[cqlsh 5.0.1 | Cassandra 3.11.4 | CQL spec 3.4.4 | Native protocol v4]
Use HELP for help.

c)使用nodetool status

从群集中获取任何IP地址
# nodetool status
Datacenter: us-east-vpc
=======================
Status=Up/Down
|/ State=Normal/Leaving/Joining/Moving
--  Address        Load       Tokens       Owns (effective)  Host ID                               
Rack
UN  172.1.2.3  4.7 GiB    256          33.1%             655da17a-xxxx-xxxx-xxxx-xxxxxxxxxxxx  1d
UN  172.1.4.5  4.94 GiB   256          33.5%             23f18c46-xxxx-xxxx-xxxx-xxxxxxxxxxxx  1c
UN  172.1.6.8  4.74 GiB   256          33.4%             f8ad0b6a-xxxx-xxxx-xxxx-xxxxxxxxxxxx  1a
# cqlsh 172.1.6.8
Connected to keyspace1 at 172.1.6.8:9042.
[cqlsh 5.0.1 | Cassandra 3.11.4 | CQL spec 3.4.4 | Native protocol v4]
Use HELP for help.

答案 1 :(得分:1)

您需要检查cassandra.yaml中配置的rpc_address和listen_address,然后如果更改了默认端口,请使用port运行cqlsh命令。您将能够连接cassandra服务器。