Kafka
Kafka 需要配合 Zookeeper
HOSTNAME | IP |
---|---|
node1 | 192.168.2.11 |
node2 | 192.168.2.12 |
Docker
node1
-
docker-compose.yml
services: zookeeper: image: zookeeper:3.7.2 container_name: zookeeper volumes: - /etc/localtime:/etc/localtime:ro - /opt/zookeeper/conf:/conf - /opt/zookeeper/data:/data - /opt/zookeeper/logs:/datalog environment: - TZ=Asia/Shanghai - ZOO_MY_ID=1 network_mode: host restart: always kafka: image: docker.io/bitnami/kafka:3.3.2 container_name: kafka volumes: - /etc/localtime:/etc/localtime - /opt/kafka/conf:/opt/bitnami/kafka/config - /mnt/da/kafka/data:/bitnami/kafka environment: - TZ=Asia/Shanghai - KAFKA_BROKER_ID=1 - KAFKA_CFG_LISTENERS=PLAINTEXT://:9091 - KAFKA_CFG_ADVERTISED_LISTENERS=PLAINTEXT://node-1:9091 - KAFKA_CFG_ZOOKEEPER_CONNECT=node-1:2181,node-2:2181 - ALLOW_PLAINTEXT_LISTENER=yes network_mode: host restart: always depends_on: - zookeeper
-
获取 zookeeper 配置
从临时的容器中复制出来 临时容器名称 xxx 随机通过 docker ps 查看
docker run -it --entrypoint bash zookeeper:3.7.2 docker cp xxx:/conf /opt/zookeeper
-
zoo.cfg
dataDir=/data dataLogDir=/datalog tickTime=2000 initLimit=5 syncLimit=2 autopurge.snapRetainCount=3 autopurge.purgeInterval=0 maxClientCnxns=60 standaloneEnabled=true admin.enableServer=true #server.1=localhost:2888:3888;2181 server.1=192.168.2.11:2888:3888;2181 server.2=192.168.2.12:2888:3888;2181
-
log4j.properties
默认配置
-
启动
docker compose -f docker-compose.yml up -d
-
验证 zookeeper
docker exec -it zookeeper bash ./bin/zkServer.sh status
-
kafka 数据目录赋值
chown 1001:1001 /mnt/da/kafka/data
node2
重复 node1