Docker实战之Kafka集群
创建网络
docker network create docker_net
docker network ls
docker-compose.ymal
version: '3.7'
networks:
docker_net:
external: true
services:
zookeeper:
image: wurstmeister/zookeeper
restart: always
volumes:
- ./data:/data
ports:
- 2181:2181
networks:
- docker_net
kafka1:
image: wurstmeister/kafka
restart: unless-stopped
container_name: kafka1
ports:
- "9093:9092"
external_links:
- zookeeper
environment:
KAFKA_BROKER_ID: 1
KAFKA_ADVERTISED_HOST_NAME: 192.168.91.103 ## 修改:宿主机IP
KAFKA_ADVERTISED_PORT: 9093 ## 修改:宿主机映射port
KAFKA_ADVERTISED_LISTENERS: PLAINTEXT://192.168.91.103:9093 ## 绑定发布订阅的端口。修改:宿主机IP
KAFKA_ZOOKEEPER_CONNECT: "zookeeper:2181"
volumes:
- "./kafka/kafka1/docker.sock:/var/run/docker.sock"
- "./kafka/kafka1/data/:/kafka"
depends_on:
- zookeeper
networks:
- docker_net
kafka2:
image: wurstmeister/kafka
restart: unless-stopped
container_name: kafka2
ports:
- "9094:9092"
external_links:
- zookeeper
environment:
KAFKA_BROKER_ID: 2
KAFKA_ADVERTISED_HOST_NAME: 192.168.91.103 ## 修改:宿主机IP
KAFKA_ADVERTISED_PORT: 9094 ## 修改:宿主机映射port
KAFKA_ADVERTISED_LISTENERS: PLAINTEXT://192.168.91.103:9094 ## 修改:宿主机IP
KAFKA_ZOOKEEPER_CONNECT: "zookeeper:2181"
volumes:
- "./kafka/kafka2/docker.sock:/var/run/docker.sock"
- "./kafka/kafka2/data/:/kafka"
depends_on:
- zookeeper
networks:
- docker_net
kafka3:
image: wurstmeister/kafka
restart: unless-stopped
container_name: kafka3
ports:
- "9095:9092"
external_links:
- zookeeper
environment:
KAFKA_BROKER_ID: 3
KAFKA_ADVERTISED_HOST_NAME: 192.168.91.103 ## 修改:宿主机IP
KAFKA_ADVERTISED_PORT: 9095 ## 修改:宿主机映射port
KAFKA_ADVERTISED_LISTENERS: PLAINTEXT://192.168.91.103:9095 ## 修改:宿主机IP
KAFKA_ZOOKEEPER_CONNECT: "zookeeper:2181"
volumes:
- "./kafka/kafka3/docker.sock:/var/run/docker.sock"
- "./kafka/kafka3/data/:/kafka"
depends_on:
- zookeeper
networks:
- docker_net
kafka-manager:
image: sheepkiller/kafka-manager:latest
restart: unless-stopped
container_name: kafka-manager
hostname: kafka-manager
ports:
- "9000:9000"
links: # 连接本compose文件创建的container
- kafka1
- kafka2
- kafka3
external_links: # 连接本compose文件以外的container
- zookeeper
environment:
ZK_HOSTS: zookeeper:2181 # 修改:宿主机IP zookeeper:2181,zoo2:2181,zoo3:2181
TZ: CST-8
depends_on:
- zookeeper
networks:
- docker_net
启动
docker-comopse up -d
查看kafka版本
# 查看kafka版本
# echo $KAFKA_HOME
/opt/kafka
# cd /opt/
/opt # ls
kafka kafka_2.13-2.8.1 overrides
kafka manager
参考文档:
Docker实战之Kafka集群
https://zhuanlan.zhihu.com/p/110905106