创建数据目录
# mkdir -pv /data/apps/kafka/{kafka_data,zookeeper_data}
# chown -R 1001.1001 /data/apps/kafka/kafka_data
# chown -R 1001.1001 /data/apps/kafka/zookeeper_data
docker-compose.yaml
# 宿主机IP: 172.16.18.8
version: "3"
services:
zookeeper:
image: 'bitnami/zookeeper:latest'
container_name: zookeeper
ports:
- '2181:2181'
environment:
- ALLOW_ANONYMOUS_LOGIN=yes
volumes:
- "/data/apps/kafka/zookeeper_data:/bitnami"
networks:
kafka:
aliases:
- zookeeper
kafka:
image: 'bitnami/kafka:3.2.3'
container_name: kafka
ports:
- '9092:9092'
- '9093:9093'
environment:
- KAFKA_ENABLE_KRAFT=yes
- KAFKA_CFG_PROCESS_ROLES=broker,controller
- KAFKA_CFG_CONTROLLER_LISTENER_NAMES=CONTROLLER
- KAFKA_CFG_LISTENERS=PLAINTEXT://:9092,CONTROLLER://:9093
- KAFKA_CFG_LISTENER_SECURITY_PROTOCOL_MAP=CONTROLLER:PLAINTEXT,PLAINTEXT:PLAINTEXT
- KAFKA_CFG_ADVERTISED_LISTENERS=PLAINTEXT://172.16.18.8:9092 # 传递回客户端的元数据,填写宿主机IP地址
- KAFKA_BROKER_ID=1
- KAFKA_CFG_NODE_ID=1
- KAFKA_HEAP_OPTS=-Xmx1024m -Xms1024m
- KAFKA_CFG_CONTROLLER_QUORUM_VOTERS=1@127.0.0.1:9093
- ALLOW_PLAINTEXT_LISTENER=yes
depends_on:
- zookeeper
volumes:
- "/data/apps/kafka/kafka_data:/bitnami"
networks:
kafka:
aliases:
- kafka
kafka-ui:
image: provectuslabs/kafka-ui
container_name: kafka-ui
ports:
- "8080:8080"
restart: always
environment:
- KAFKA_CLUSTERS_0_NAME=local
- KAFKA_CLUSTERS_0_BOOTSTRAPSERVERS=kafka:9092
- KAFKA_CLUSTERS_0_ZOOKEEPER=zookeeper:2181
- KAFKA_CLUSTERS_0_READONLY=true
depends_on:
- kafka
- zookeeper
networks:
kafka:
aliases:
- kafka-ui
networks:
kafka:
driver: bridge
dashboard