1、下载kafka镜像和zookeeper镜像
docker pull wurstmeister/kafka
docker pull wurstmeister/zookeeper
PS:如果没有配置阿里云加速或翻墙,下载会非常慢
2、服务器环境准备
- leader服务器有kafka和zookeeper镜像
- 两台worker服务器都有kafka镜像
- 都安装了docker-compose,且都在同一网段下
3、leader服务器上启动zookeeper、kafka
docker-compose up -d
docker-compose文件 docker-compose.yml
version: '2' services: zookeeper: image: wurstmeister/zookeeper ports: - "2181:2181" kafka: image: wurstmeister/kafka ports: - "9092:9092" environment: KAFKA_ADVERTISED_HOST_NAME: LEADER_IP KAFKA_ZOOKEEPER_CONNECT: LEADER_IP:2181 KAFKA_CREATE_TOPICS: "TOPIC:16:1" volumes: - /var/run/docker.sock:/var/run/docker.sock
4、worker服务器上启动kafka
docker-compose up -d
docker-compose文件 docker-compose.yml
version: '2' services: kafka: image: wurstmeister/kafka ports: - "9092:9092" environment: KAFKA_ADVERTISED_HOST_NAME: WORKER_IP KAFKA_ZOOKEEPER_CONNECT: LEADER_IP:2181 KAFKA_CREATE_TOPICS: "TOPIC:16:1" volumes: - /var/run/docker.sock:/var/run/docker.sock