1、docker-compose部署单机
version: '2'
services:
kafka-zookeeper:
image: wurstmeister/zookeeper
container_name: kafka-zookeeper
volumes:
- ./zookeeper_data:/opt/zookeeper-3.4.13/data
restart: always
ports:
- "2188:2181"
networks:
- "kafka_net"
kafka:
image: wurstmeister/kafka:2.12-2.3.0
container_name: kafka
restart: always
hostname: kafka-hostname
ports:
- "32770:9092"
environment:
KAFKA_ADVERTISED_HOST_NAME: 192.168.180.47
KAFKA_ZOOKEEPER_CONNECT: kafka-zookeeper:2181
KAFKA_AUTO_CREATE_TOPICS_ENABLE: 'true'
KAFKA_ADVERTISED_PORT: 32770
volumes:
- ./kafka_data:/kafka
networks:
- "kafka_net"
kafka-manage:
image: sheepkiller/kafka-manager
container_name: kafka-manage
restart: always
ports:
- "5001:9000"
environment:
ZK_HOSTS: kafka-zookeeper:2181
networks:
- "kafka_net"
kafdrop:
image: obsidiandynamics/kafdrop
container_name: kafdrop
restart: always
ports:
- "8001:9000"
environment:
KAFKA_BROKERCONNECT: 192.168.180.47:32770
networks:
- "kafka_net"
networks:
kafka_net:
external: true
2、docker-compose部署集群
version: '2.4'
services:
zookeeper:
image: wurstmeister/zookeeper
container_name: zk
ports:
- "2181:2181"
restart: always
volumes:
- ./zookeeper_data:/opt/zookeeper-3.4.13/data
kafka1:
image: wurstmeister/kafka:2.12-2.3.0
container_name: kafka1
ports:
- "32771:9092"
environment:
TZ: Asia/Shanghai
KAFKA_BROKER_ID: 11
KAFKA_ADVERTISED_HOST_NAME: 192.168.180.46
KAFKA_ZOOKEEPER_CONNECT: zookeeper:2181
KAFKA_AUTO_CREATE_TOPICS_ENABLE: 'true'
volumes:
- /var/run/docker.sock:/var/run/docker.sock
- ./kafka_data/kafka1_data:/kafka
restart: always
depends_on:
- zookeeper
kafka2:
image: wurstmeister/kafka:2.12-2.3.0
container_name: kafka2
ports:
- "32772:9092"
environment:
TZ: Asia/Shanghai
KAFKA_BROKER_ID: 12
KAFKA_ADVERTISED_HOST_NAME: 192.168.180.46
KAFKA_ZOOKEEPER_CONNECT: zookeeper:2181
KAFKA_AUTO_CREATE_TOPICS_ENABLE: 'true'
volumes:
- /var/run/docker.sock:/var/run/docker.sock
- ./kafka_data/kafka2_data:/kafka
restart: always
depends_on:
- zookeeper
kafka3:
image: wurstmeister/kafka:2.12-2.3.0
container_name: kafka3
ports:
- "32773:9092"
environment:
TZ: Asia/Shanghai
KAFKA_BROKER_ID: 13
KAFKA_ADVERTISED_HOST_NAME: 192.168.180.46
KAFKA_ZOOKEEPER_CONNECT: zookeeper:2181
KAFKA_AUTO_CREATE_TOPICS_ENABLE: 'true'
volumes:
- /var/run/docker.sock:/var/run/docker.sock
- ./kafka_data/kafka3_data:/kafka
restart: always
depends_on:
- zookeeper
kafdrop:
image: obsidiandynamics/kafdrop
container_name: kafdrop
restart: "no"
ports:
- "5000:9000"
environment:
KAFKA_BROKERCONNECT: 192.168.180.46:32771
TZ: Asia/Shanghai
depends_on:
- zookeeper
- kafka1
- kafka2
- kafka3