version: "3.1"
services:
# 节点1
fat-zk1:
# 镜像名称
image: zookeeper:3.8.0
# 容器名称
container_name: fat-zk1
# docker重启后自动重启容器
restart: always
# 当前容器主机名
hostname: fat-zk1
# 端口 宿主机:容器
ports:
- 2181:2181
volumes:
- ./zk1/data:/data
- ./zk1/datalog:/datalog
# 环境变量
environment:
# myid,一个集群内唯一标识一个节点
ZOO_MY_ID: 1
# 集群内节点列表
ZOO_SERVERS: server.1=fat-zk1:2888:3888;2181 server.2=fat-zk2:2888:3888;2181 server.3=fat-zk3:2888:3888;2181
# 节点2
fat-zk2:
image: zookeeper:3.8.0
container_name: fat-zk2
restart: always
hostname: fat-zk2
ports:
- 2182:2181
volumes:
- ./zk2/data:/data
- ./zk2/datalog:/datalog
environment:
ZOO_MY_ID: 2
ZOO_SERVERS: server.1=fat-zk1:2888:3888;2181 server.2=fat-zk2:2888:3888;2181 server.3=fat-zk3:2888:3888;2181
# 节点3
fat-zk3:
image: zookeeper:3.8.0
container_name: fat-zk3
restart: always
hostname: fat-zk3
ports:
- 2183:2181
volumes:
- ./zk3/data:/data
- ./zk3/datalog:/datalog
environment:
ZOO_MY_ID: 3
ZOO_SERVERS: server.1=fat-zk1:2888:3888;2181 server.2=fat-zk2:2888:3888;2181 server.3=fat-zk3:2888:3888;2181
fat-kafka1:
image: wurstmeister/kafka
restart: always
hostname: fat-kafka1
container_name: fat-kafka1
ports:
- "9092:9092"
environment:
KAFKA_ADVERTISED_LISTENERS: PLAINTEXT://192.168.0.28:9092 #宿主机ip
KAFKA_ADVERTISED_HOST_NAME: 0.0.0.0
KAFKA_ADVERTISED_PORT: 9092
KAFKA_ZOOKEEPER_CONNECT: fat-zk1:2181,fat-zk2:2181,fat-zk3:2181
JMX_PORT: 9999
volumes:
- ./kafka1/logs:/kafka
external_links:
- fat-zk1
- fat-zk2
- fat-zk3
fat-kafka2:
image: wurstmeister/kafka
restart: always
hostname: fat-kafka2
container_name: fat-kafka2
ports:
- "9093:9092"
environment:
KAFKA_ADVERTISED_LISTENERS: PLAINTEXT://192.168.0.28:9093
KAFKA_ADVERTISED_HOST_NAME: 0.0.0.0
KAFKA_ADVERTISED_PORT: 9093
KAFKA_ZOOKEEPER_CONNECT: fat-zk1:2181,fat-zk2:2181,fat-zk3:2181
JMX_PORT: 9988
volumes:
- ./kafka2/logs:/kafka
external_links: # 连接本compose文件以外的container
- fat-zk1
- fat-zk2
- fat-zk3
fat-kafka3:
image: wurstmeister/kafka
restart: always
hostname: fat-kafka3
container_name: fat-kafka3
ports:
- "9094:9092"
environment:
KAFKA_ADVERTISED_LISTENERS: PLAINTEXT://192.168.0.28:9094
KAFKA_ADVERTISED_HOST_NAME: 0.0.0.0
KAFKA_ADVERTISED_PORT: 9094
KAFKA_ZOOKEEPER_CONNECT: fat-zk1:2181,fat-zk2:2181,fat-zk3:2181
JMX_PORT: 9977
volumes:
- ./kafka3/logs:/kafka
external_links: # 连接本compose文件以外的container
- fat-zk1
- fat-zk2
- fat-zk3
fat-kafka-manager:
image: sheepkiller/kafka-manager:latest
restart: always
container_name: fat-kafa-manager
hostname: fat-kafka-manager
ports:
- "9000:9000"
links: # 连接本compose文件创建的container
- fat-kafka1
- fat-kafka2
- fat-kafka3
external_links: # 连接本compose文件以外的container
- fat-zk1
- fat-zk2
- fat-zk3
environment:
ZK_HOSTS: fat-zk1:2181,fat-zk2:2181,fat-zk3:2181
KAFKA_BROKERS: fat-kafka1:9092,fat-kafka2:9093,fat-kafka3:9094
KM_ARGS: -Djava.net.preferIPv4Stack=true
APPLICATION_SECRET: wanfu!@#
KAFKA_MANAGER_AUTH_ENABLED: "true" # 开启kafka-manager权限校验
KAFKA_MANAGER_USERNAME: kafka # 登陆账户
KAFKA_MANAGER_PASSWORD: wanfu!@# # 登陆密码
访问kafka-manager,并创建kafka集群和topic