前提:
- 首先服务器内存,建议在4G以上。
- 安装docker、docker-compose
- 服务器执行
curl cip.cc
查看公网IP
docker-compose 一键运行yml
将下面的内容中的[your server ip] ——替换成——> 你的公网ip
version: "3.1"
networks:
zk-net: # 网络名
name: zk-net
driver: bridge
services:
# zookeeper集群
zoo1:
image: zookeeper:3.8.0
container_name: zoo1 # 容器名称
restart: always # 开机自启
hostname: zoo1 # 主机名
ports:
- 2181:2181 # 端口号
environment:
ZOO_MY_ID: 1
ZOO_SERVERS: server.1=zoo1:2888:3888;2181 server.2=zoo2:2888:3888;2181 server.3=zoo3:2888:3888;2181
networks:
- zk-net
zoo2:
image: zookeeper:3.8.0
container_name: zoo2
restart: always
hostname: zoo2
ports:
- 2182:2181
environment:
ZOO_MY_ID: 2
ZOO_SERVERS: server.1=zoo1:2888:3888;2181 server.2=zoo2:2888:3888;2181 server.3=zoo3:2888:3888;2181
networks:
- zk-net
zoo3:
image: zookeeper:3.8.0
container_name: zoo3
restart: always
hostname: zoo3
ports:
- 2183:2181
environment:
ZOO_MY_ID: 3
ZOO_SERVERS: server.1=zoo1:2888:3888;2181 server.2=zoo2:2888:3888;2181 server.3=zoo3:2888:3888;2181
networks:
- zk-net
# kafka集群
kafka1:
image: "bitnami/kafka:3.0.0"
container_name: kafka1
hostname: kafka1
networks:
- zk-net
ports:
- "9092:9092"
environment:
- KAFKA_CFG_ZOOKEEPER_CONNECT=zoo1:2181,zoo2:2182,zoo3:2183/kafka
- KAFKA_BROKER_ID=1
- KAFKA_CFG_LISTENERS=PLAINTEXT://:9092
- KAFKA_CFG_ADVERTISED_LISTENERS=PLAINTEXT://[your server ip]:9092
- ALLOW_PLAINTEXT_LISTENER=yes
depends_on:
- zoo1
- zoo2
- zoo3
kafka2:
image: "bitnami/kafka:3.0.0"
container_name: kafka2
hostname: kafka2
networks:
- zk-net
ports:
- "9093:9093"
environment:
- KAFKA_CFG_ZOOKEEPER_CONNECT=zoo1:2181,zoo2:2182,zoo3:2183/kafka
- KAFKA_BROKER_ID=2
- KAFKA_CFG_LISTENERS=PLAINTEXT://:9093
- KAFKA_CFG_ADVERTISED_LISTENERS=PLAINTEXT://[your server ip]:9093
- ALLOW_PLAINTEXT_LISTENER=yes
depends_on:
- zoo1
- zoo2
- zoo3
kafka3:
image: "bitnami/kafka:3.0.0"
container_name: kafka3
hostname: kafka3
networks:
- zk-net
ports:
- "9094:9094"
environment:
- KAFKA_CFG_ZOOKEEPER_CONNECT=zoo1:2181,zoo2:2182,zoo3:2183/kafka
- KAFKA_BROKER_ID=3
- KAFKA_CFG_LISTENERS=PLAINTEXT://:9094
- KAFKA_CFG_ADVERTISED_LISTENERS=PLAINTEXT://[your server ip]:9094
- ALLOW_PLAINTEXT_LISTENER=yes
depends_on:
- zoo1
- zoo2
- zoo3
最后一键执行
docker-compose -f [xxx.yml] up -d
查看是否运行成功:docker-compose ps