python - 无法从 Python 应用程序连接到 DataStax Enterprise 集群

标签 python cassandra datastax

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

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

我在 cassandra.yaml 文件中尝试过的事情 -

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

如上所述 - 操作系统-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 通。

非常感谢任何帮助。

谢谢

最佳答案

https://community.datastax.com/questions/12174/ 上也提出了同样的问题所以我在这里重新发布我的答案。

此错误表明您连接到的节点未监听 IP 192.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 中的日志,以获取有关其未运行原因的线索。

另一个可能的问题是您尚未配置 native_transport_address(开源 Cassandra 中的 rpc_address)。您需要将其设置为客户端(您的应用程序)可以访问的 IP 地址,否则它将默认为 localhost (127.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"

关于python - 无法从 Python 应用程序连接到 DataStax Enterprise 集群,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/68920517/

相关文章:

python - 如何在 geodjango 中使用带有 OpenStreetMap 的 openlayers 显示数据?

Cassandra - 基于时间范围的多个计数器

unix下Java未安装的问题

python - float 布局使用 Kivy 添加自定义大小的小部件

python - xml.sax 解析器和行号等

python - Django 在模型内调用另一个模型的 upload_to

cassandra - Caasandra PRIMARY KEY column "user"cannot be restricted as preceding column "eventtype"is not restricted

hadoop - Cassandras Map Reduce 支持

nosql - 列族数据库分片和复制 [NoSQL Distilled]

java - Spring Cassandra 模型映射