You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

DigitalOcean Droplet中Cassandra连接问题求助

Cassandra安装与连接问题排查

问题1:cqlsh连接报错ModuleNotFoundError: No module named 'six.moves'

在DigitalOcean Droplet上按官方指南安装Cassandra后,执行cqlsh时出现如下错误:

root@ubuntu-s-cass-history-chat:~# cqlsh
Traceback (most recent call last):
  File "/usr/bin/cqlsh.py", line 134, in <module>
    from cassandra.cluster import Cluster
  File "/usr/share/cassandra/lib/cassandra-driver-internal-only-3.25.0.zip/cassandra-driver-3.25.0/cassandra/cluster.py", line 33, in <module>
ModuleNotFoundError: No module named 'six.moves'

已尝试apt-get install python3-six但报错仍存在。

原因与解决方法

  • 核心原因:系统通过apt安装的python3-six未被cqlsh关联的Python环境识别,cqlsh可能绑定了特定Python版本或使用内部驱动包,导致依赖无法加载。
  • 解决步骤:
    1. 使用pip3直接安装six库(确保对应Python3环境):
      pip3 install six
      
    2. 若无效,检查cqlsh使用的Python路径:
      head -n1 /usr/bin/cqlsh.py
      
      输出类似#!/usr/bin/python3,验证该环境下是否能导入six:
      /usr/bin/python3 -c "import six.moves"
      
      若报错,直接给该Python环境安装six:
      /usr/bin/python3 -m pip install six
      
    3. 若仍有问题,尝试升级cassandra-driver兼容依赖:
      pip3 install --upgrade cassandra-driver
      

问题2:本地Python远程连接Cassandra被拒绝(ConnectionRefusedError 10061)

本地使用cassandra-driver连接Droplet上的Cassandra时,出现如下错误:

NoHostAvailable: ('Unable to connect to any servers', {'host:port': ConnectionRefusedError(10061, "Tried connecting to [('host', port)]. Last error: Unable to establish a connection since the computer destination expressly denied said connection")})

连接代码:

from cassandra.cluster import Cluster
cluster = Cluster([host], port=port)
session = cluster.connect()

原因与解决方法

  • 核心原因:防火墙限制、Cassandra监听地址配置错误、端口未对外开放三者之一或组合导致。
  • 解决步骤:
    1. 开放Droplet防火墙端口:在DigitalOcean防火墙规则中添加TCP 9042端口的入站允许规则,允许本地IP或所有IP访问(生产环境建议限制特定IP)。
    2. 修改Cassandra配置文件/etc/cassandra/cassandra.yaml:
      • 将listen_address改为Droplet私有IP或0.0.0.0(生产环境不建议用0.0.0.0,需指定特定IP)。
      • 将rpc_address改为Droplet私有IP或0.0.0.0(远程连接依赖RPC端口9042)。
      • 设置broadcast_rpc_address为Droplet的公网IP,确保客户端能正确识别连接地址。
    3. 重启Cassandra服务:
      sudo systemctl restart cassandra
      
    4. 验证端口监听状态:
      netstat -tulpn | grep 9042
      
      输出需显示0.0.0.0:9042或指定IP绑定9042端口。
    5. 本地测试连通性:用telnet或nc命令测试Droplet公网IP与9042端口:
      telnet <Droplet公网IP> 9042
      
      若不通,重新检查防火墙规则与Cassandra配置。

内容的提问来源于stack exchange,提问作者Esteban Ávila Rincón

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.22 09:52:41