首页 > 解决方案 > 带有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

标签: python-3.xdockercassandra

解决方案


实际上,我通过提供 docker 内部的容器 IP 地址来解决这个问题。我很困惑我应该给哪个地址。但是在运行这个命令之后。

docker inspect -f '{{range .NetworkSettings.Networks}}{{.IPAddress}}{{end}}' container_name_or_id. 

我不知道我需要指定具有集群节点的容器 ID。所以我总是给出机器的IP地址。


推荐阅读