mkdir kafka
cd kafka
编写docker-compose.yml
version: '3'
services:
zookeeper:
image: 'bitnami/zookeeper:3.7'
ports:
- '2190:2181'
environment:
- ZOO_ENABLE_AUTH=yes
- ZOO_SERVER_USERS=zoo
- ZOO_SERVER_PASSWORDS=zoo
- ZOO_CLIENT_USER=zoo
- ZOO_CLIENT_PASSWORD=zoo
kafka1:
depends_on:
- zookeeper
image: 'bitnami/kafka:2.6.0'
ports:
- '19092:9093'
environment:
- KAFKA_BROKER_ID=1
- KAFKA_CFG_LISTENER_SECURITY_PROTOCOL_MAP=INTERNAL:PLAINTEXT,CLIENT:PLAINTEXT
- KAFKA_CFG_LISTENERS=INTERNAL://kafka1:9092,CLIENT://kafka1:9093
- KAFKA_CFG_ADVERTISED_LISTENERS=INTERNAL://kafka1:9092,CLIENT://10.0.2.15:19092
- KAFKA_CFG_INTER_BROKER_LISTENER_NAME=INTERNAL
- KAFKA_CLIENT_USER=kafka
- KAFKA_CLIENT_PASSWORD=kafka
- ALLOW_PLAINTEXT_LISTENER=yes
# - KAFKA_INTER_BROKER_USER=kafka
# - KAFKA_INTER_BROKER_PASSWORD=kafka
- KAFKA_CFG_ZOOKEEPER_CONNECT=zookeeper:2181
- KAFKA_ZOOKEEPER_PROTOCOL=SASL
- KAFKA_ZOOKEEPER_USER=zoo
- KAFKA_ZOOKEEPER_PASSWORD=zoo
kafka2:
depends_on:
- zookeeper
image: 'bitnami/kafka:2.6.0'
ports:
- '19093:9093'
environment:
- KAFKA_BROKER_ID=2
- KAFKA_CFG_LISTENER_SECURITY_PROTOCOL_MAP=INTERNAL:PLAINTEXT,CLIENT:PLAINTEXT
- KAFKA_CFG_LISTENERS=INTERNAL://kafka2:9092,CLIENT://kafka2:9093
- KAFKA_CFG_ADVERTISED_LISTENERS=INTERNAL://kafka2:9092,CLIENT://10.0.2.15:19093
- KAFKA_CFG_INTER_BROKER_LISTENER_NAME=INTERNAL
- KAFKA_CLIENT_USER=kafka
- KAFKA_CLIENT_PASSWORD=kafka
- ALLOW_PLAINTEXT_LISTENER=yes
# - KAFKA_INTER_BROKER_USER=kafka
# - KAFKA_INTER_BROKER_PASSWORD=kafka
- KAFKA_CFG_ZOOKEEPER_CONNECT=zookeeper:2181
- KAFKA_ZOOKEEPER_PROTOCOL=SASL
- KAFKA_ZOOKEEPER_USER=zoo
- KAFKA_ZOOKEEPER_PASSWORD=zoo
kafka3:
depends_on:
- zookeeper
image: 'bitnami/kafka:2.6.0'
ports:
- '19094:9093'
environment:
- KAFKA_BROKER_ID=3
- KAFKA_CFG_LISTENER_SECURITY_PROTOCOL_MAP=INTERNAL:PLAINTEXT,CLIENT:PLAINTEXT
- KAFKA_CFG_LISTENERS=INTERNAL://kafka3:9092,CLIENT://kafka3:9093
- KAFKA_CFG_ADVERTISED_LISTENERS=INTERNAL://kafka3:9092,CLIENT://10.0.2.15:19094
- KAFKA_CFG_INTER_BROKER_LISTENER_NAME=INTERNAL
- KAFKA_CLIENT_USER=kafka
- KAFKA_CLIENT_PASSWORD=kafka
- ALLOW_PLAINTEXT_LISTENER=yes
# - KAFKA_INTER_BROKER_USER=kafka
# - KAFKA_INTER_BROKER_PASSWORD=kafka
- KAFKA_CFG_ZOOKEEPER_CONNECT=zookeeper:2181
- KAFKA_ZOOKEEPER_PROTOCOL=SASL
- KAFKA_ZOOKEEPER_USER=zoo
- KAFKA_ZOOKEEPER_PASSWORD=zoo
启动
COMPOSE_PROJECT_NAME=kafka_cluster docker-compose up
# 后台启动
COMPOSE_PROJECT_NAME=kafka_cluster docker-compose up -d
# 查看状态
COMPOSE_PROJECT_NAME=kafka_cluster docker-compose ps