【发布时间】:2016-04-11 07:03:42
【问题描述】:
我正在运行 Cassandra docker 容器:
docker pull cassandra
run --name cassandra -p 9042:9042 -p 9160:9160 -d cassandra
netstat -tpln 是:
Proto Recv-Q Send-Q Local Address Foreign Address State PID/Program name
LISTEN - tcp6 0 0 [::]:9160 [::]:*
LISTEN - tcp6 0 0 [::]:9042 [::]:*
从本地 cqlsh 到 C* 的连接正常:
docker exec -it cassandra /bin/bash
#cqlsh
Connected to Test Cluster at 127.0.0.1:9042.
[cqlsh 5.0.1 | Cassandra 3.1.1 | CQL spec 3.3.1 | Native protocol v4]
Use HELP for help.
cqlsh> show host
Connected to Test Cluster at 127.0.0.1:9042.
我安装本地cqlsh:
$cqlsh --version
cqlsh 4.1.1
但是,我没有从 localhost 连接 docker 容器:
$sqlsh
Traceback (most recent call last):
File "/usr/sbin/cqlsh", line 2067, in <module>
main(*read_options(sys.argv[1:], os.environ))
. . .
File "/home/akalend/src/cqlsh_standalone/lib/thrift-python-internal-only-0.9.1.zip/thrift/transport/TSocket.py", line 103, in read
socket.error: [Errno 104] Connection reset by peer
所以,我没有从 localhost php-driver 连接。
如何将 cassandra docker 与我的 php 脚本和 cqlsh 连接?
为什么 docker 将端口映射到 tcp6,而不是 tcp4? 解决
为什么本地cqlsh(4.1版)连接9160端口,而docker容器cqlsh(5.0.1版)连接9042端口?
添加信息
如果运行容器为:
run --name cassandra -p 127.0.0.1:9042:9042 -p 127.0.0.1:9160:9160 -d cassandra
我有监听 ip4 端口:
Active Internet connections (only servers)
Proto Recv-Q Send-Q Local Address Foreign Address State PID/Program name
tcp 0 0 127.0.0.1:9160 0.0.0.0:* LISTEN 2454/docker-proxy
tcp 0 0 127.0.0.1:9042 0.0.0.0:* LISTEN 2462/docker-proxy
但我没有连接 cqlsh & php
socket.error: [Errno 104] Connection reset by peer
PHP Fatal error: Uncaught exception 'Cassandra\Exception\RuntimeException' with message 'No hosts available for the control connection' in /home/akalend/projects/test/cassa/test.php:7
Stack trace:
#0 /home/akalend/projects/test/cassa/test.php(7): Cassandra\DefaultCluster->connect('system')
#1 {main} thrown in /home/akalend/projects/test/cassa/test.php on line 7
【问题讨论】:
-
如果你在docker中运行Cassandra,它运行在自己的网络中;因此,您可以创建一个 docker 网络并将其用于 Cassandra,并将相同的网络用于需要连接到它的其他容器medium.com/techlogs/cassandra-in-docker-3e5eb98cdb22
标签: docker cassandra-2.0 datastax cqlsh