在应用程序容器中的泊坞窗内的cassandra客户端连接问题

batchWorker_1 | [DEBUG] 2017-10-30 12:42:10.035 [cluster1-nio-worker-0] Connection - Connection[/172.17.0.3:9042-1, inFlight=0, closed=false] Error connecting to /172.17.0.3:9042 (connection timed out: /172.17.0.3:9042) batchWorker_1 | [DEBUG] 2017-10-30 12:42:10.037 [cluster1-nio-worker-0] STATES - Defuncting Connection[/172.17.0.3:9042-1, inFlight=0, closed=false] because: [/172.17.0.3:9042] Cannot connect batchWorker_1 | [DEBUG] 2017-10-30 12:42:10.038 [cluster1-nio-worker-0] STATES - [/172.17.0.3:9042] preventing new connections for the next 1000 ms batchWorker_1 | [DEBUG] 2017-10-30 12:42:10.038 [cluster1-nio-worker-0] STATES - [/172.17.0.3:9042] Connection[/172.17.0.3:9042-1, inFlight=0, closed=false] failed, remaining = 0 batchWorker_1 | [DEBUG] 2017-10-30 12:42:10.039 [cluster1-nio-worker-0] Connection - Connection[/172.17.0.3:9042-1, inFlight=0, closed=true] closing connection batchWorker_1 | [DEBUG] 2017-10-30 12:42:10.042 [main] ControlConnection - [Control connection] error on /172.17.0.3:9042 connection, no more host to try batchWorker_1 | com.datastax.driver.core.exceptions.TransportException: [/172.17.0.3:9042] Cannot connect batchWorker_1 | at com.datastax.driver.core.Connection$1.operationComplete(Connection.java:165) ~[batch_worker_server.jar:0.01] batchWorker_1 | at com.datastax.driver.core.Connection$1.operationComplete(Connection.java:148) ~[batch_worker_server.jar:0.01] ... 

我正在运行我的应用程序和一个cassandra容器,试图build立从应用程序容器到cassandra容器的连接。

  1. 我试图与docker撰写。 它引发同样的错误。 它能够解决正确的容器IP(如您所见),但无法连接。
  2. 我尝试通过单独启动cassandra容器来运行,并在应用程序容器中对IP进行硬编码,但仍然失败。
  3. cassandra容器工作正常,如果我在外面运行相同的应用程序,它连接。

问题是,它无法从应用程序容器中parsingcassandra容器IP。 不知道为什么。

我也启用了start_rpc并暴露了所有与cassandra相关的端口。 仍然没有运气。

您可以按文档中所述创buildDockernetworking,并将Cassandra和您的应用程序连接到同一networking。

您还需要检查Cassandra正在监听的接口是单接口还是全接口?

在cassandraconfiguration中更改IP地址

rpc_address (默认:localhost)客户端连接的监听地址(Thrift RPC服务和本地传输)。 有效值:

  1. 未设置:使用节点的已configuration主机名configuration来parsing地址。 如果未设置,主机名将使用/ etc / hostname,/ etc / hosts或DNSparsing为此节点的IP地址。

  2. 0.0.0.0:侦听所有configuration的接口。 您必须将broadcast_rpc_address设置为0.0.0.0以外的值。

  3. IP地址

  4. 主机名

RPC_ADDRESS = 0.0.0.0

这里是docker-compose.yml文件

 version: '2' services: cassandra: container_name: cassandra image: cassandra:3.9 volumes: - /path/of/host/for/cassandra/:/var/lib/cassandra/ ports: - 7000:7000 - 7001:7001 - 7199:7199 - 9042:9042 - 9160:9160 environment: - CASSANDRA_CLUSTER_NAME='cassandra-cluster' - CASSANDRA_NUM_TOKENS=256 - CASSANDRA_RPC_ADDRESS=0.0.0.0 restart: always