基于Docker搭建kafka单机版
-
环境
centos 7.5
Docker version 18.09.7, build 2d0083d -
拉取zookeeper并运行
docker pull wurstmeister/zookeeper docker run -d --name zookeeper -p 2181:2181 -t wurstmeister/zookeeper
-
拉取kafka镜像并运行
docker pull wurstmeister/kafka docker run -d --name kafka -p 9092:9092 --link zookeeper -e KAFKA_ZOOKEEPER_CONNECT=xxx.xxx.x.xxx:2181 -e KAFKA_ADVERTISED_HOST_NAME=xxx.xxx.x.xxx -e KAFKA_ADVERTISED_PORT=9092 -v /etc/localtime:/etc/localtime wurstmeister/kafka
-
命令配置
KAFKA_ZOOKEEPER_CONNECT :指定 zookeeper 的 “地址:端口”,请更换自己的ip和端口;
KAFKA_ADVERTISED_HOST_NAME:kafka安装机器ip;
-
注意
启动kafka后,如果连接不上zookeeper,提示
Socket error occurred: xxx.xxx.x.xxx:2181: Host is unreachable (org.apache.zookeeper.ClientCnxn) -
防火墙放行2181端口,命令(CentOS 7):
firewall-cmd --add-port=2181/tcp --permanent
systemctl restart firewalld9092端口可能也需要加入防火墙策略,具体根据日志提示
(我遇到的情况:telnet 2181是通的,但还是要加防火墙策略才能正常启动kafka)
-