【发布时间】:2022-11-04 19:31:01
【问题描述】:
我在 docker 容器中本地运行 Scylladb,我想访问 docker 容器外的集群。那是我收到以下错误的时候:cassandra.cluster.NoHostAvailable: ('Unable to connect to any servers')
Datacenter: datacenter1
=======================
Status=Up/Down
|/ State=Normal/Leaving/Joining/Moving
-- Address Load Tokens Owns Host ID Rack
UN 172.17.0.2 776 KB 256 ? ad698c75-a465-4deb-a92c-0b667e82a84f rack1
Note: Non-system keyspaces don't have the same replication settings, effective ownership information is meaningless
Cluster Information:
Name: Test Cluster
Snitch: org.apache.cassandra.locator.SimpleSnitch
DynamicEndPointSnitch: disabled
Partitioner: org.apache.cassandra.dht.Murmur3Partitioner
Schema versions:
443048b2-c1fe-395e-accd-5ae9b6828464: [172.17.0.2]
我在端口 9042 上使用 cqlsh 访问集群没有问题:
Connected to at 172.17.0.2:9042.
[cqlsh 5.0.1 | Cassandra 3.0.8 | CQL spec 3.3.1 | Native protocol v4]
现在我正在尝试从 docker 容器外部的我的 fastapi 应用程序访问集群。
from cassandra.cluster import Cluster
cluster = Cluster(['172.17.0.2'])
session = cluster.connect('Test Cluster')
这是我得到的错误:
raise NoHostAvailable("Unable to connect to any servers", errors)
cassandra.cluster.NoHostAvailable: ('Unable to connect to any servers', {'172.17.0.2:9042': OSError(51, "Tried connecting to [('172.17.0.2', 9042)]. Last error: Network is unreachable")})
【问题讨论】:
-
你的主机是 Mac 吗?已知的限制之一是您不能直接将流量从主机路由到 Mac 中的容器。如果不是,那么请演示一下你的 Python 程序的相关连接部分。
-
@FelipeMendes 是的,我的主机是 Mac。您知道任何解决方法吗?
-
是的,在 Docker 容器中运行您的程序,您将能够将流量路由到 Scylla。这是 Mac 的限制。
标签: docker cassandra scylla cassandra-python-driver