一.安装脚本
version: '3.1'
services:
zoo1:
image: ricky29711/zookeeper
container_name: zoo1
ports:
- "2181:2181"
environment:
ZOO_MY_ID: 1
ZOO_TICK_TIME: 20000
ZOO_SERVERS: server.1=zoo1:2888:3888 server.2=zoo2:2888:3888 server.3=zoo3:2888:3888
volumes:
- ./zoo1/data:/data
- ./zoo1/datalog:/datalog
zoo2:
image: ricky29711/zookeeper
container_name: zoo2
ports:
- "2182:2181"
environment:
ZOO_MY_ID: 2
ZOO_TICK_TIME: 20000
ZOO_SERVERS: server.1=zoo1:2888:3888 server.2=zoo2:2888:3888 server.3=zoo3:2888:3888
volumes:
- ./zoo2/data:/data
- ./zoo2/datalog:/datalog
zoo3:
image: ricky29711/zookeeper
container_name: zoo3
ports:
- "2183:2181"
environment:
ZOO_MY_ID: 3
ZOO_TICK_TIME: 20000
ZOO_SERVERS: server.1=zoo1:2888:3888 server.2=zoo2:2888:3888 server.3=zoo3:2888:3888
volumes:
- ./zoo3/data:/data
- ./zoo3/datalog:/datalog
kafka1:
image: ricky29711/kafka
container_name: kafka1
depends_on:
- zoo1
- zoo2
- zoo3
ports:
- "9092:9092"
environment:
KAFKA_BROKER_ID: 1
KAFKA_ZOOKEEPER_CONNECT: zoo1:2181,zoo2:2181,zoo3:2181
KAFKA_ADVERTISED_LISTENERS: PLAINTEXT://kafka1:9092
KAFKA_LISTENERS: PLAINTEXT://0.0.0.0:9092
KAFKA_OFFSETS_TOPIC_REPLICATION_FACTOR: 1
kafka2:
image: ricky29711/kafka
container_name: kafka2
depends_on:
- zoo1
- zoo2
- zoo3
ports:
- "9093:9093"
environment:
KAFKA_BROKER_ID: 2
KAFKA_ZOOKEEPER_CONNECT: zoo1:2181,zoo2:2181,zoo3:2181
KAFKA_ADVERTISED_LISTENERS: PLAINTEXT://kafka2:9093
KAFKA_LISTENERS: PLAINTEXT://0.0.0.0:9093
KAFKA_OFFSETS_TOPIC_REPLICATION_FACTOR: 1
二.注意事项:
1.KAFKA_ADVERTISED_LISTENERS
环境变量 KAFKA_ADVERTISED_LISTENERS: PLAINTEXT://kafka2:9093 中kafak2为容器名称
(1)方式一: 若直接使用 安装脚本,那么连接kafak容器的spring boot 项目所在的宿主机需要能正确解析kafak2对应的宿主机IP
(2)方式二:将kafka1和kafak2换为宿主机IP
2.ZOO_SERVERS 格式问题:
网上格式:
ZOO_SERVERS: server.1=zoo1:2888:3888; server.2=zoo2:2888:3888; server.3=zoo3:2888:3888
但是我使用的鏡像使用上面格式报错:报错内容为Invalid config, exiting abnormally,