【问题标题】:Connecting local cassandra cluster with docker container将本地 cassandra 集群与 docker 容器连接起来
【发布时间】:2016-09-12 13:12:46
【问题描述】:

我有一组作为 docker 容器运行的微服务。一个微服务说 A 想连接到在我的笔记本电脑上本地运行的 cassnadra。为了做到这一点,我有以下配置

来自服务A的yaml文件的sn-p

cassandra:
    hosts: [127.0.0.1]     
    keyspace: "My keyspace"
    protocol_version: 3
    ports: 9042

另一方面,我通过调用 ./bin/cassandra 来运行 cassandra。然后我在本地连接到cqlsh,其输出如下

Connected to Test Cluster at 127.0.0.1:9042.
[cqlsh 5.0.1 | Cassandra 3.0.6 | CQL spec 3.4.0 | Native protocol v4]
Use HELP for help.

现在,当我的容器启动并尝试连接到我的机器上托管的这个正在运行的 cassandra 时,它会说连接被拒绝。请看下面的痕迹

File "cassandra/cluster.py", line 2076, in cassandra.cluster.ControlConnection._reconnect_internal (cassandra/cluster.c:36914)
cassandra.cluster.NoHostAvailable: ('Unable to connect to any servers', {'127.0.0.1': ConnectionRefusedError(111, "Tried connecting to [('127.0.0.1', 9042)]. Last error: Connection refused")})
[start] application exit with code 1, killing container

更多信息 我正在使用 apache-cassandra-3.0.6。

请指教。谢谢

【问题讨论】:

  • 您是如何在本地环境中运行 docker-daemon 的?如果你用的是oracle虚拟盒子或者docker机器,能不能ssh进机器,看看能不能访问cassandra服务?

标签: docker cassandra docker-compose


【解决方案1】:

正如 Shibashis 所提到的,您可能无法通过带有127.0.0.1 的 docker 容器访问主机

请找出表示为 HOST 的 IP。 How to get the IP address of the docker host from inside a docker container

通过更改 conf\cassandra.yaml 启动 cassandra 实例

  • listen_address
  • rpc_address

到已识别的主机 IP。

希望对你有帮助!

【讨论】:

  • 是的,这对我来说看起来不错。让我试试这个我会再次更新
猜你喜欢
  • 2016-07-14
  • 2020-10-03
  • 2023-01-14
  • 2018-05-17
  • 2017-05-20
  • 2020-03-08
  • 2022-06-15
  • 1970-01-01
  • 2019-04-24
相关资源
最近更新 更多