-
问题描述:
在通过docker-compose安装wurstmeister/kafka的docker镜像提示错误: zookeeper连接不上。kafka | [2020-08-24 05:32:16,393] INFO Opening socket connection to server zookeeper/172.18.0.2:2181. Will not attempt to authenticate using SASL (unknown error) (org.apache.zookeeper.ClientCnxn) kafka | [2020-08-24 05:32:17,404] INFO Socket error occurred: zookeeper/172.18.0.2:2181: Host is unreachable (org.apache.zookeeper.ClientCnxn)
-
环境:
-
docker 版本:Docker version 19.03.12, build 48a66213fe
-
docker compose 版本: docker-compose version 1.26.2, build eefe0d31
-
操作系统:CentOS8
-
docker-compose.yml 文件
version: '2' services: zookeeper: image: wurstmeister/zookeeper container_name: zookeeper restart: always volumes: - /data/docker/zookeeper/conf:/conf - /etc/localtime:/etc/localtime ports: - "2181:2181" kafka: image: wurstmeister/kafka:2.13-2.6.0 container_name: kafka restart: always ports: - "9092:9092" environment: KAFKA_ADVERTISED_HOST_NAME: 192.168.31.15 KAFKA_ADVERTISED_LISTENERS: PLAINTEXT://:9092 KAFKA_MESSAGE_MAX_BYTES: 2000000 KAFKA_CREATE_TOPICS: "TopicTest:2:1:compact" KAFKA_ZOOKEEPER_CONNECT: zookeeper:2181 volumes: - /data/docker/kafka/kafka-logs:/kafka - /var/run/docker.sock:/var/run/docker.sock - /etc/localtime:/etc/localtime depends_on: - zookeeper
-
运行命令
docker-compose up
,容器会自动创建,并使用自定义的docker bridge网络
-
-
问题排查:
- 通过启动docker container 容器
docker run -it --name box --rm --network my_app busybox sh
,然后在这个容器内,使用下面的命令,发现ping zookeeper ##成功 ping <ip> ## 成功 telnet zookeeper 2181 ##失败:telnet: can't connect to remote host (192.168.31.15): No route to host
- 通过启动docker container 容器
-
原因
应该是docker宿主机(Centos 8)虚拟机的防火墙,屏蔽了容器间通过宿主机发送的ICMP协议报文。 -
解决办法:
在docker的宿主机上,运行下面的命令##开启IP伪装 sudo firewall-cmd --zone=public --add-masquerade --permanent sudo firewall-cmd --reload
-
参考信息:https://stackoverflow.com/questions/40214617/docker-no-route-to-host
CentOS8上安装wurstmeister/kafka的docker镜像的问题
最新推荐文章于 2023-07-28 00:03:33 发布