我正在运行Cassandra docker container:
// consider
List<Order> orders;
using (var work = new MyDbContext())
{
orders = work.Orders.Where(...).ToList();
}
foreach (var order in orders)
{
// now this line throws an exception, so the developer
// will go back and add the .Include() statement instead
// of just silently creating slow code
Console.WriteLine(order.Customer.Name);
}
netstat -tpln是:
docker pull cassandra
run --name cassandra -p 9042:9042 -p 9160:9160 -d cassandra
从本地cqlsh连接到C *是好的:
Proto Recv-Q Send-Q Local Address Foreign Address State PID/Program name
LISTEN - tcp6 0 0 [::]:9160 [::]:*
LISTEN - tcp6 0 0 [::]:9042 [::]:*
我安装了本地cqlsh:
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.
但是,我没有从localhost:
连接docker容器$cqlsh --version
cqlsh 4.1.1
所以,我没有从localhost php-driver连接。
如何使用我的php脚本连接cassandra docker&amp; cqlsh吗
为什么docker将端口映射到tcp6,不要tcp4? 解析
为什么本地cqlsh(版本4.1)通过9160端口连接,但是docker容器cqlsh(版本5.0.1)通过9042端口连接?
添加信息
如果运行conteiner为:
$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
我听ip4端口:
run --name cassandra -p 127.0.0.1:9042:9042 -p 127.0.0.1:9160:9160 -d cassandra
但我没有与cqlsh&amp; PHP
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
答案 0 :(得分:18)
尝试将docker run命令更改为:
docker pull cassandra
docker run --name cassandra -p 127.0.0.1:9042:9042 -p 127.0.0.1:9160:9160 -d cassandra
这将确保docker容器映射到IPv4。
9160 - Thrift client API
9042 - CQL native transport port
从PHP应用程序中,您必须连接到Thrift端口。请按照http://support.qualityunit.com/942764-Example-of-PHP-application-readingwriting-to-Cassandra中的示例进行操作
在上面的示例中,要从运行容器的同一台计算机连接到cassandra容器,您仍然可以使用相同的TSocket('127.0.0.1', 9160)
。
如果您计划从另一台计算机进行连接,则必须在此使用TSocket('IP/Domain name', 9160)
,IP /域名称是运行docker容器的计算机的标识符。
如果您的PHP应用程序位于同一台计算机上的另一个docker容器中,首先您必须链接容器,然后您可以使用此中的TSocket('alias name', 9160)
,别名是您为该链接指定的名称。
try {
// Make a connection to the Thrift interface to Cassandra
$socket = new TSocket('127.0.0.1', 9160);