1、安装zookeeper
# kafka使用
docker network create app-bridge --driver bridge
# 安装zookeeper
docker run -e JVMFLAGS="-Xmx512m" -p 2181:2181 \
--network app-bridge \
-e ALLOW_ANONYMOUS_LOGIN=yes \
-v /Users/liushiwei/tools/zookeeper/data:/data \
-v /Users/liushiwei/tools/zookeeper/conf:/conf \
--name zookeeper -d zookeeper:3.5.8
2、安装kafka
# 下载kafka镜像
docker pull bitnami/kafka:2.4.1
# 节点1
docker run -d --name=kafka2 \
-p 9092:9092 \
--network app-bridge \
-e ALLOW_PLAINTEXT_LISTENER=yes \
-e KAFKA_CFG_ZOOKEEPER_CONNECT=zookeeper:2181 \
-e KAFKA_BROKER_ID=2 \
-e KAFKA_ADVERTISED_LISTENERS=PLAINTEXT://192.168.0.113:9092 \
-e KAFKA_LISTENERS=PLAINTEXT://0.0.0.0:9092 \
-v /home/kafka/data2:/bitnami/kafka/data \
bitnami/kafka:2.4.1
# 节点2
docker run -d --name=kafka3 \
-p 9093:9093 \
--network app-bridge \
-e ALLOW_PLAINTEXT_LISTENER=yes \
-e KAFKA_CFG_ZOOKEEPER_CONNECT=zookeeper:2181 \
-e KAFKA_BROKER_ID=3 \
-e KAFKA_ADVERTISED_LISTENERS=PLAINTEXT://192.168.0.113:9093 \
-e KAFKA_LISTENERS=PLAINTEXT://0.0.0.0:9093 \
-v /home/kafka/data3:/bitnami/kafka/data \
bitnami/kafka:2.4.1
# 节点4
docker run -d --name=kafka4 \
-p 9094:9094 \
--network app-bridge \
-e ALLOW_PLAINTEXT_LISTENER=yes \
-e KAFKA_CFG_ZOOKEEPER_CONNECT=zookeeper:2181 \
-e KAFKA_BROKER_ID=4 \
-e KAFKA_ADVERTISED_LISTENERS=PLAINTEXT://192.168.0.113:9094 \
-e KAFKA_LISTENERS=PLAINTEXT://0.0.0.0:9094 \
-v /home/kafka/data4:/bitnami/kafka/data \
bitnami/kafka:2.4.1
-
ALLOW_PLAINTEXT_LISTENER=yes:允许使用PLAINTEXT侦听器
-
KAFKA_CFG_ZOOKEEPER_CONNECT:zookeeper集群地址,多节点,分割
-
KAFKA_BROKER_ID:节点id,用来指定 Kafka 集群中 broker 的唯一标识,默认值为 -1。如果没有设置,那么 Kafka会自动生成一个
-
KAFKA_ADVERTISED_LISTENERS:绑定公网 IP 供外部客户端使用
-
KAFKA_LISTENERS:绑定私网 IP 地址供 broker 间通信使用
-
-v /home/kafka/data4:/bitnami/kafka/data:挂载数据目录
版权声明:本文为Extraordinarylife原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。