docker错误:kafka shell中的kafka.zookeeper.zookeeperclienttimeoutexception

nuypyhwy  于 2021-06-06  发布在  Kafka
关注(0)|答案(2)|浏览(476)

我想用docker来管理Kafka。
我开始为Kafka服务。
docker撰写ps

Name                        Command               State                         Ports

kafka-docker\u kafka\u 1 start-kafka.sh up 0.0.0.0:9092->9092/tcp
kafka-docker\u zookeeper\u 1/bin/sh-c/usr/sbin/sshd。。。向上0.0.0.0:2181->2181/tcp、22/tcp、2888/tcp、3888/tcp
docker-compose.yml公司
cat docker-compose.yml目录

version: '2'
services:
  zookeeper:
    image: wurstmeister/zookeeper
    ports:
      - "2181:2181"
  kafka:
    build: .
    ports:
      - "9092:9092"
    environment:
      KAFKA_ADVERTISED_HOST_NAME: kafka
      KAFKA_ZOOKEEPER_CONNECT: zookeeper:2181
      KAFKA_ZOOKEEPER_CONNECTION_TIMEOUT_MS: 36000
      KAFKA_ADVERTISED_PORT: 9092
    volumes:
      - /var/run/docker.sock:/var/run/docker.sock

当我试图通过输入inside shell来创建一个主题时,它抛出了下面的错误。
./start-kafka-shell.shKafkazookeeper:2181
bash-4.4#$kafka_home/bin/kafka-topics.sh--创建--主题情感--分区1--缩放器$zk--复制因子1

[2019-02-12 08:07:59,097] WARN Session 0x0 for server zookeeper:2181, unexpected error, closing socket connection and attempting reconnect (org.apache.zookeeper.ClientCnxn)
java.nio.channels.UnresolvedAddressException
    at sun.nio.ch.Net.checkAddress(Net.java:101)
    at sun.nio.ch.SocketChannelImpl.connect(SocketChannelImpl.java:622)
    at org.apache.zookeeper.ClientCnxnSocketNIO.registerAndConnect(ClientCnxnSocketNIO.java:277)
    at org.apache.zookeeper.ClientCnxnSocketNIO.connect(ClientCnxnSocketNIO.java:287)
    at org.apache.zookeeper.ClientCnxn$SendThread.startConnect(ClientCnxn.java:1021)
    at org.apache.zookeeper.ClientCnxn$SendThread.run(ClientCnxn.java:1064)

尝试了两种可能性:
在将hostname:zookeeper(尽管我在docker-compose.yml中也提到过)更改为ip:0.0.0时出现超时异常
./start-kafka-shell.shKafka0.0.0.0:2181
bash-4.4#$kafka_home/bin/kafka-topics.sh--创建--主题情感--分区1--缩放器$zk--复制因子1

Exception in thread "main" kafka.zookeeper.ZooKeeperClientTimeoutException: Timed out waiting for connection while in state: CONNECTING
    at kafka.zookeeper.ZooKeeperClient.$anonfun$waitUntilConnected$3(ZooKeeperClient.scala:268)
    at scala.runtime.java8.JFunction0$mcV$sp.apply(JFunction0$mcV$sp.java:12)
    at kafka.utils.CoreUtils$.inLock(CoreUtils.scala:251)
    at kafka.zookeeper.ZooKeeperClient.waitUntilConnected(ZooKeeperClient.scala:264)
    at kafka.zookeeper.ZooKeeperClient.<init>(ZooKeeperClient.scala:97)
    at kafka.zk.KafkaZkClient$.apply(KafkaZkClient.scala:1694)
    at kafka.admin.TopicCommand$.main(TopicCommand.scala:57)
    at kafka.admin.TopicCommand.main(TopicCommand.scala)

为了避免上述错误,我在docker-compose.yml-->kafka\u zookeeper\u connection\u timeout\u ms:36000中将timeout参数从6000增加到36000
我得到了同样的超时错误。如果有人能帮忙,请告诉我。

ruoxqz4g

ruoxqz4g1#

昨天我开始在《 Docker 》中使用Kafkahttps://github.com/wurstmeister/kafka-docker.git
我的脚步声

https://github.com/wurstmeister/kafka-docker.git

nano kafka-docker/docker-compose.yml

我的形态

version: '3'
services:
  zookeeper:
    image: wurstmeister/zookeeper
    ports:
      - "2181:2181"
  kafka:
    image: wurstmeister/kafka
    ports:
      - "9092"
    environment:
      KAFKA_ADVERTISED_HOST_NAME: localhost
      KAFKA_ZOOKEEPER_CONNECT: zookeeper:2181
      KAFKA_CREATE_TOPICS: "test-topic:5:2"
    volumes:
      - /var/run/docker.sock:/var/run/docker.sock

之后

docker-compose up -d 

docker-compose scale kafka=3

检查docker容器

$docker-compose ps
          Name                        Command               State                         Ports                       
----------------------------------------------------------------------------------------------------------------------
kafka-docker_kafka_1       start-kafka.sh                   Up      0.0.0.0:32784->9092/tcp                           
kafka-docker_kafka_2       start-kafka.sh                   Up      0.0.0.0:32785->9092/tcp                           
kafka-docker_kafka_3       start-kafka.sh                   Up      0.0.0.0:32786->9092/tcp                           
kafka-docker_zookeeper_1   /bin/sh -c /usr/sbin/sshd  ...   Up      0.0.0.0:2181->2181/tcp, 22/tcp, 2888/tcp, 3888/tcp

$ docker ps -a
CONTAINER ID        IMAGE                    COMMAND                  CREATED             STATUS              PORTS                                                NAMES
1479a7dc96fa        wurstmeister/kafka       "start-kafka.sh"         About an hour ago   Up About an hour    0.0.0.0:32785->9092/tcp                              kafka-docker_kafka_2
08e5017dae2b        wurstmeister/kafka       "start-kafka.sh"         About an hour ago   Up About an hour    0.0.0.0:32786->9092/tcp                              kafka-docker_kafka_3
d4f3d17e81b2        wurstmeister/kafka       "start-kafka.sh"         About an hour ago   Up About an hour    0.0.0.0:32784->9092/tcp                              kafka-docker_kafka_1
72b0fbe553b5        wurstmeister/zookeeper   "/bin/sh -c '/usr/sb…"   About an hour ago   Up About an hour    22/tcp, 2888/tcp, 3888/tcp, 0.0.0.0:2181->2181/tcp   kafka-docker_zookeeper_1

在连接到Kafka经纪人1和获得主题从Zookeeper

$ docker exec -it kafka-docker_kafka_1 bash
bash-4.4# /opt/kafka/bin/kafka-topics.sh --zookeeper zookeeper:2181 --list
sample
test-topic
bash-4.4#

按主题获取信息

bash-4.4# /opt/kafka/bin/kafka-topics.sh --zookeeper zookeeper:2181 --describe --topic sample
Topic: sample   PartitionCount: 1   ReplicationFactor: 1    Configs: 
    Topic: sample   Partition: 0    Leader: 1002    Replicas: 1002  Isr: 1002
bash-4.4# /opt/kafka/bin/kafka-topics.sh --zookeeper zookeeper:2181 --describe --topic test-topic
Topic: test-topic   PartitionCount: 5   ReplicationFactor: 2    Configs: 
    Topic: test-topic   Partition: 0    Leader: 1001    Replicas: 1001,1003 Isr: 1001,1003
    Topic: test-topic   Partition: 1    Leader: 1002    Replicas: 1002,1001 Isr: 1002,1001
    Topic: test-topic   Partition: 2    Leader: 1003    Replicas: 1003,1002 Isr: 1003,1002
    Topic: test-topic   Partition: 3    Leader: 1001    Replicas: 1001,1002 Isr: 1001,1002
    Topic: test-topic   Partition: 4    Leader: 1002    Replicas: 1002,1003 Isr: 1002,1003

创建新主题后

bash-4.4# /opt/kafka/bin/kafka-topics.sh --zookeeper zookeeper:2181 --create --topic topic1 --replication-factor 2 --partitions 2
Created topic topic1.

描述

bash-4.4# /opt/kafka/bin/kafka-topics.sh --zookeeper zookeeper:2181 --describe --topic topic1
Topic: topic1   PartitionCount: 2   ReplicationFactor: 2    Configs: 
    Topic: topic1   Partition: 0    Leader: 1003    Replicas: 1003,1001 Isr: 1003,1001
    Topic: topic1   Partition: 1    Leader: 1001    Replicas: 1001,1002 Isr: 1001,1002
oxiaedzo

oxiaedzo2#

有很多Kafka的图像。很难说你到底想做什么,但似乎你在重建一个形象?还是自己建?
不过,您肯定不需要zookeeper地址作为启动kafka的参数
也就是说,0.0.0.0不是一个真正的连接地址。它通常用作绑定地址,意思是“允许所有连接到此服务器”
那么 zookeeper 服务名称只能在docker网络中解析,所以这可能解释了为什么需要 --net ,但这意味着你在使用 docker run 对于某些东西,考虑到你正在使用compose,这一点也不清楚
如果你想进入一个外壳的容器,你应该只是使用 docker-compose exec kafka bash ,并且zookeeper已经是该容器的环境变量
比如说 docker-compose exec kafka bash -c '$KAFKA_HOME/bin/kafka-topics.sh --create --topic sentiment --partitions 1 --zookeeper $KAFKA_ZOOKEEPER_CONNECT --replication-factor 1'

相关问题