无法从Python应用程序连接到DataStax企业集群

2024-09-19 20:31:24 发布

您现在位置:Python中文网/ 问答频道 /正文

连接到Centos 7.x服务器托管的DataStax Cassandra 6.8时遇到一些困难

我能够成功地在Centos外壳内部本地连接,nodetool状态显示集群已启动且正常

我在cassandra.yaml文件中尝试过的东西-

  1. 将listen_address参数从localhost更改为服务器的IP地址。结果->;DSE没有启动
  2. 注释了listen_地址行。结果->;DSE没有启动
  3. 将listen_address的参数留空。结果->;DSE没有启动

如上所述- OS-CentOS 7 DSE版本-6.8 安装方法RPM

Python程序-

#cluster = Cluster()
cluster = Cluster(['192.168.1.223'])

# To establish connection and begin executing queries, need a session
session = cluster.connect()

row = session.execute("select release_version from system.local;").one()
if row:
    print(row[0])
else:
    print("An error occurred.")

从python引发异常->

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

我的电脑和服务器都在同一个网络上,我可以相互ping

非常感谢您的帮助

谢谢


Tags: togt服务器参数addresssessionconnectconnection
1条回答
网友
1楼 · 发布于 2024-09-19 20:31:24

https://community.datastax.com/questions/12174/上也有人问过同样的问题,所以我把我的答案贴在这里

此错误表示您正在连接的节点未侦听IP192.168.1.223和CQL端口9042上的CQL连接:

No connection could be made because the target machine actively refused it

最可能的两个原因是:

  1. DSE没有运行
  2. DSE未在正确的IP上侦听客户端连接

您已经指出无法启动DSE。默认情况下,您需要查看位于/var/log/cassandra中的日志,以了解它为什么没有运行

另一个可能的问题是您没有在开源Cassandra中配置native_transport_addressrpc_address)。您需要将其设置为客户端(您的应用程序)可以访问的IP地址,否则,它将默认为localhost127.0.0.1

cassandra.yaml中,使用以下配置节点:

listen_address: private_ip
native_transport_address: public_ip

如果只是在本地网络上测试,请将这两个属性都设置为服务器的IP地址。干杯

[编辑]我刚看到你与@Alex Ott的对话。我在这里发布我的回复,因为它不适合评论

此启动错误意味着节点无法与任何种子节点通信,因此无法加入群集:

ERROR [DSE main thread] 2021-08-25 06:40:11,413 CassandraDaemon.java:932 - \
  Exception encountered during startup
java.lang.RuntimeException: Unable to gossip with any peers

如果集群中只有1个节点,请使用服务器自己的IP地址配置cassandra.yaml中的seeds列表:

seed_provider:
    - class_name: org.apache.cassandra.locator.SimpleSeedProvider
      parameters:
          - seeds: "192.168.1.223"

相关问题 更多 >