概述
单节点移步 ==> docker-compose快速部署Kafka,以及常见问题解决
注意事项
- 不要配置restart: always,如果有问题,会一直重启。
- 将数据挂载到本地并指定路径,可能会有Permission denied问题。
- KAFKA_CFG_LISTENERS=CLIENT://:9092,端口前不要加IP,否则无法启动。
- kafka3需要jdk11,容器内置。
- 启动完成之后,ps命令检查一下,如果未完全启动,则down掉再up几遍。
脚本
docker-compose.yml
version: '2'
services:
zk1:
image: bitnami/zookeeper:3.7
container_name: zk1
hostname: zk1
ports:
- "2181:2181"
volumes:
- "zk1_data:/bitnami"
environment:
- ZOO_SERVER_ID=1
- ZOO_SERVERS=zk1:2888:3888,zk2:2888:3888,zk3:2888:3888
- ALLOW_ANONYMOUS_LOGIN=yes
zk2:
image: bitnami/zookeeper:3.7
container_name: zk2
hostname: zk1
ports:
- "2182:2181"
volumes:
- "zk2_data:/bitnami"
environment:
- ZOO_SERVER_ID=2
- ZOO_SERVERS=zk1:2888:3888,zk2:2888:3888,zk3:2888:3888
- ALLOW_ANONYMOUS_LOGIN=yes
zk3:
image: bitnami/zookeeper:3.7
container_name: zk3
hostname: zk1
ports:
- "2183:2181"
volumes:
- "zk3_data:/bitnami"
environment:
- ZOO_SERVER_ID=3
- ZOO_SERVERS=zk1:2888:3888,zk2:2888:3888,zk3:2888:3888
- ALLOW_ANONYMOUS_LOGIN=yes
kafka1:
image: bitnami/kafka:3
container_name: kafka1
depends_on:
- zk1
- zk2
- zk3
hostname: kafka1
ports:
- 20123:20123
volumes:
- "kafka1_data:/bitnami"
environment:
- KAFKA_BROKER_ID=1
- KAFKA_CFG_ZOOKEEPER_CONNECT=zk1:2181,zk2:2181,zk3:2181
- ALLOW_PLAINTEXT_LISTENER=yes
- KAFKA_CFG_LISTENER_SECURITY_PROTOCOL_MAP=CLIENT:PLAINTEXT,EXTERNAL:PLAINTEXT
- KAFKA_CFG_LISTENERS=CLIENT://:9092,EXTERNAL://:20123
- KAFKA_CFG_ADVERTISED_LISTENERS=CLIENT://kafka1:9092,EXTERNAL://192.168.2.134:20123
- KAFKA_INTER_BROKER_LISTENER_NAME=CLIENT
- KAFKA_CFG_AUTO_CREATE_TOPICS_ENABLE=true
kafka2:
image: bitnami/kafka:3
container_name: kafka2
depends_on:
- zk1
- zk2
- zk3
hostname: kafka2
ports:
- 20124:20124
volumes:
- "kafka2_data:/bitnami"
environment:
- KAFKA_BROKER_ID=2
- KAFKA_CFG_ZOOKEEPER_CONNECT=zk1:2181,zk2:2181,zk3:2181
- ALLOW_PLAINTEXT_LISTENER=yes
- KAFKA_CFG_LISTENER_SECURITY_PROTOCOL_MAP=CLIENT:PLAINTEXT,EXTERNAL:PLAINTEXT
- KAFKA_CFG_LISTENERS=CLIENT://:9092,EXTERNAL://:20124
- KAFKA_CFG_ADVERTISED_LISTENERS=CLIENT://kafka2:9092,EXTERNAL://192.168.2.134:20124
- KAFKA_INTER_BROKER_LISTENER_NAME=CLIENT
- KAFKA_CFG_AUTO_CREATE_TOPICS_ENABLE=true
kafka3:
image: bitnami/kafka:3
container_name: kafka3
depends_on:
- zk1
- zk2
- zk3
hostname: kafka3
ports:
- 20125:20125
volumes:
- "kafka3_data:/bitnami"
environment:
- KAFKA_BROKER_ID=3
- KAFKA_CFG_ZOOKEEPER_CONNECT=zk1:2181,zk2:2181,zk3:2181
- ALLOW_PLAINTEXT_LISTENER=yes
- KAFKA_CFG_LISTENER_SECURITY_PROTOCOL_MAP=CLIENT:PLAINTEXT,EXTERNAL:PLAINTEXT
- KAFKA_CFG_LISTENERS=CLIENT://:9092,EXTERNAL://:20125
- KAFKA_CFG_ADVERTISED_LISTENERS=CLIENT://kafka3:9092,EXTERNAL://192.168.2.134:20125
- KAFKA_INTER_BROKER_LISTENER_NAME=CLIENT
- KAFKA_CFG_AUTO_CREATE_TOPICS_ENABLE=true
kafdrop:
image: obsidiandynamics/kafdrop:latest
container_name: kafdrop
depends_on:
- kafka1
- kafka2
- kafka3
ports:
- 9000:9000
environment:
- KAFKA_BROKERCONNECT=kafka1:9092,kafka2:9092,kafka3:9092
volumes:
zk1_data:
driver: local
zk2_data:
driver: local
zk3_data:
driver: local
kafka1_data:
driver: local
kafka2_data:
driver: local
kafka3_data:
driver: local
管理页面
http://localhost:9000/
基础命令
# 启动
docker-compose up -d
# 停止
docker-compose down
# 查看
docker-compose ps
# 日志
docker-compose logs <container_name>