python-3.x - 带有python的Docker Cassandra给出连接错误
问题描述
我安装了 Docker 并运行了第一个 Cassandra 节点并使用 Cqlsh 运行了一些命令,它运行良好。我安装了python驱动程序,然后当我运行下面的命令时出现以下错误。我看到了很多堆栈问题,但没有多少人能够回答。请给出你的想法。我一直渴望使用 cassandra,但永远无法为这个问题想出一个好的解决方案。谢谢
>>> from cassandra.cluster import Cluster
>>> cluster=Cluster()
>>> keyspace='north'
>>> session=Cluster(['192.168.1.xx']).connect()
错误
cassandra.cluster.NoHostAvailable: ('Unable to connect to any servers', {'192.168.1.xx': ConnectionRefusedError(111, "Tried connecting to [('192.168.1.xx', 9042)]. Last error: Connection refused")})
当我尝试用我创建的 cassandra 节点替换 Ip 地址时,在我的情况下为“node1”,它给了我这个错误
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "cassandra/cluster.py", line 826, in cassandra.cluster.Cluster.__init__
File "/usr/lib/python3.5/socket.py", line 732, in getaddrinfo
for res in _socket.getaddrinfo(host, port, family, type, proto, flags):
socket.gaierror: [Errno -5] No address associated with hostname
解决方案
实际上,我通过提供 docker 内部的容器 IP 地址来解决这个问题。我很困惑我应该给哪个地址。但是在运行这个命令之后。
docker inspect -f '{{range .NetworkSettings.Networks}}{{.IPAddress}}{{end}}' container_name_or_id.
我不知道我需要指定具有集群节点的容器 ID。所以我总是给出机器的IP地址。
推荐阅读
- python - 在 Visual Studio Code 中运行 Python 代码有困难,在 Python shell 中运行,但不在此处
- xml - 如何通过将 xslt 导入另一个 xslt 来获取输入值?
- macos - 使用 docker 在 Mac 和 nginx 中安装 Nginx
- python - 是否可以检查计算机是否使用 python 连接到域?
- python - 康威的生命游戏推进网格(与上一个不同!)
- javascript - 可以设置网站的加载时间吗?
- installation - Silverstripe 4.6 setup .env - vars,缺少 install.php,语言?
- r - 如何在 R 中为纵向设计正确设置 lmer?
- c# - 仅当其他三个 MVVM 对象已启用时才启用 MVVM 对象
- r - 使用 Excel 文件中的 gplot2 创建箱线图