容器之间的通信连接失败

时间:2018-07-15 01:40:35

标签: docker

我使用docker,一个用于Zookeeper,另一个用于kafka 我使用docker ps  码头工人ps

CONTAINER ID        IMAGE               COMMAND                  CREATED             STATUS              PORTS                                            NAMES
23dbed8536dc        dc62102ccd75        "/opt/startkafka.sh"     4 minutes ago       Up 4 minutes                                                         inspiring_nobel
8f89ce6a4b57        00088267fb34        "/opt/startzookeeper…"   7 minutes ago       Up 7 minutes        2888/tcp, 192.168.1.5:2181->2181/tcp, 3888/tcp   vigorous_zhukovsky

kafka配置连接到zookeeper是

zookeeper_connect=localhost:2181

当我docker运行kafka容器时

  

[2018-07-15 01:31:58,369]信息打开与服务器的套接字连接   本地主机/127.0.0.1:2181。不会尝试使用SASL进行身份验证   (未知错误)(org.apache.zookeeper.ClientCnxn)[2018-07-15   01:31:58,373]为服务器null,意外错误警告会话0x0,   关闭套接字连接并尝试重新连接   (org.apache.zookeeper.ClientCnxn)java.net.ConnectException:   在拒绝连接   sun.nio.ch.SocketChannelImpl.checkConnect(本机方法)位于   sun.nio.ch.SocketChannelImpl.finishConnect(SocketChannelImpl.java:717)     在   org.apache.zookeeper.ClientCnxnSocketNIO.doTransport(ClientCnxnSocketNIO.java:361)     在   org.apache.zookeeper.ClientCnxn $ SendThread.run(ClientCnxn.java:1141)   [2018-07-15 01:31:59,479]信息打开与服务器的套接字连接   本地主机/127.0.0.1:2181。不会尝试使用SASL进行身份验证   (未知错误)(org.apache.zookeeper.ClientCnxn)[2018-07-15   01:31:59,481]为服务器null,意外错误警告会话0x0,   关闭套接字连接并尝试重新连接   (org.apache.zookeeper.ClientCnxn)java.net.ConnectException:   在拒绝连接   sun.nio.ch.SocketChannelImpl.checkConnect(本机方法)位于   sun.nio.ch.SocketChannelImpl.finishConnect(SocketChannelImpl.java:717)     在   org.apache.zookeeper.ClientCnxnSocketNIO.doTransport(ClientCnxnSocketNIO.java:361)     在   org.apache.zookeeper.ClientCnxn $ SendThread.run(ClientCnxn.java:1141)

我知道kafka容器无法连接到Zookeeper 更改kafka配置 zookeeper_connect = 192.168.1.5:2181

  

[2018-07-15 01:35:40,833] INFO套接字连接建立到   192.168.1.5/192.168.1.5:2181,启动会话(org.apache.zookeeper.ClientCnxn)[2018-07-15 01:35:40,836]信息   无法从服务器会话ID 0x0中读取其他数据   服务器已关闭套接字,正在关闭套接字连接并尝试   重新连接(org.apache.zookeeper.ClientCnxn)[2018-07-15 01:35:42,520]   错误KafkaServer启动期间发生致命错误。准备关机   (kafka.server.KafkaServer)   kafka.zookeeper.ZooKeeperClientTimeoutException:等待超时   处于连接状态:CONNECTING at   kafka.zookeeper.ZooKeeperClient $$ anonfun $ kafka $ zookeeper $ ZooKeeperClient $$ waitUntilConnected $ 1.apply $ mcV $ sp(ZooKeeperClient.scala:225)     在   kafka.zookeeper.ZooKeeperClient $$ anonfun $ kafka $ zookeeper $ ZooKeeperClient $$ waitUntilConnected $ 1.apply(ZooKeeperClient.scala:221)     在   kafka.zookeeper.ZooKeeperClient $$ anonfun $ kafka $ zookeeper $ ZooKeeperClient $$ waitUntilConnected $ 1.apply(ZooKeeperClient.scala:221)     在kafka.utils.CoreUtils $ .inLock(CoreUtils.scala:250)在   kafka.zookeeper.ZooKeeperClient.kafka $ zookeeper $ ZooKeeperClient $$ waitUntilConnected(ZooKeeperClient.scala:221)     在kafka.zookeeper.ZooKeeperClient。(ZooKeeperClient.scala:95)     在kafka.zk.KafkaZkClient $ .apply(KafkaZkClient.scala:1538)在   kafka.server.KafkaServer.kafka $ server $ KafkaServer $$ createZkClient $ 1(KafkaServer.scala:345)     在kafka.server.KafkaServer.initZkClient(KafkaServer.scala:369)在   kafka.server.KafkaServer.startup(KafkaServer.scala:202)位于   kafka.server.KafkaServerStartable.startup(KafkaServerStartable.scala:38)     在kafka.Kafka $ .main(Kafka.scala:92)在   kafka.Kafka.main(Kafka.scala)[2018-07-15 01:35:42,523]信息正在关闭   下来(kafka.server.KafkaServer)[2018-07-15 01:35:42,525]警告   (kafka.utils.CoreUtils $)在以下位置的java.lang.NullPointerException   kafka.server.KafkaServer $$ anonfun $ shutdown $ 5.apply $ mcV $ sp(KafkaServer.scala:569)     在kafka.utils.CoreUtils $ .swallow(CoreUtils.scala:85)在   kafka.server.KafkaServer.shutdown(KafkaServer.scala:569)在   kafka.server.KafkaServer.startup(KafkaServer.scala:326)在   kafka.server.KafkaServerStartable.startup(KafkaServerStartable.scala:38)     在kafka.Kafka $ .main(Kafka.scala:92)在   kafka.Kafka.main(Kafka.scala)[2018-07-15 01:35:42,528]信息已关闭   已完成(kafka.server.KafkaServer)[2018-07-15 01:35:42,528]错误   退出卡夫卡。 (kafka.server.KafkaServerStartable)[2018-07-15   01:35:42,530]资讯关闭(kafka.server.KafkaServer)

我不知道如何让kafka容器连接到zookeeper容器,或测试容器之间的连通性。 感谢您的任何建议!

1 个答案:

答案 0 :(得分:0)

this example中一样,每个kafka节点应在运行时(在docker run上)引用zookpeepr集群节点的IP:

docker run -p 9092:9092 \
  -e ZOOKEEPER_CONNECT=10.0.0.1:2181,10.0.0.2:2181,10.0.0.3:2181 \
  -e KAFKA_HOST=host_kafka1 -e KAFKA_PORT=9092 -e BROKER_ID=0 \
  --name kafka1 jeygeethan/kafka-cluster

一般想法是expressed here

此外,如果您有一个名为zk-01的外部Zookeeper服务器,则还需要传递zookeeper.connect

docker run --tty --interactive --rm \
  --name kafka-01 \
  --publish 9092:9092 \
  --env SERVER__ZOOKEEPER_CONNECT=zk-01 \  <=============
  --env SERVER__BROKER_ID=1 \
  --env SERVER__COMPRESSION_TYPE=gzip \
  --link zk-01 \
  christiangda/kafka bin/kafka-server-start.sh config/server.properties

问题仍然存在:zookeeper不在“ localhost”上,但可以通过其docker容器名称访问。