cat docker-compose.yml
version: "2.2"
services:
zookeeper:
image: bitnami/zookeeper:latest
restart: always
ports:
- 2181:2181
environment:
# 匿名登錄--必須開啟
- ALLOW_ANONYMOUS_LOGIN=yes
volumes:
- ./.zookeeper:/bitnami/zookeeper
- /etc/localtime:/etc/localtime:ro
cpus: '1'
mem_limit: 500m
container_name: zookeeper
# 該鏡像具體配置參考 https://github.com/bitnami/bitnami-docker-kafka/blob/master/README.md
# kafka:
# image: bitnami/kafka:latest
# restart: always
# ports:
# - 9092:9092
# - 9999:9999
# environment:
# - KAFKA_BROKER_ID=1
# - KAFKA_CFG_LISTENERS=PLAINTEXT://:9092
# - KAFKA_CFG_ADVERTISED_LISTENERS=PLAINTEXT://172.17.0.216:9092
# - KAFKA_CFG_ZOOKEEPER_CONNECT=zookeeper:2181
# # 允許使用PLAINTEXT協(xié)議(鏡像中默認為關閉,需要手動開啟)
# - ALLOW_PLAINTEXT_LISTENER=yes
# # 關閉自動創(chuàng)建 topic 功能
# - KAFKA_CFG_AUTO_CREATE_TOPICS_ENABLE=false
# # 全局消息過期時間 6 小時(測試時可以設置短一點)
# - KAFKA_CFG_LOG_RETENTION_HOURS=6
# # 開啟JMX監(jiān)控
# - JMX_PORT=9999
# volumes:
# - ./.kafka:/bitnami/kafka
# - /etc/localtime:/etc/localtime:ro
# cpus: '2'
# mem_limit: 2048m
# depends_on:
# - zookeeper
# container_name: kafka
# Web 管理界面 另外也可以用exporter+prometheus+grafana的方式來監(jiān)控 https://github.com/danielqsj/kafka_exporter
kafka1:
image: wurstmeister/kafka
restart: always
container_name: kafka1
hostname: kafka1
ports:
- "9092:9092"
environment:
KAFKA_BROKER_ID: 1
KAFKA_LISTENERS: PLAINTEXT://0.0.0.0:9092
KAFKA_ADVERTISED_LISTENERS: PLAINTEXT://172.17.0.216:9092 ## 宿主機IP
KAFKA_ADVERTISED_HOST_NAME: kafka1
KAFKA_ADVERTISED_PORT: 9092
KAFKA_ZOOKEEPER_CONNECT: "zookeeper:2181"
volumes:
- "./kafka/kafka1/data/:/kafka"
- /etc/localtime:/etc/localtime:ro
cpus: '2'
mem_limit: 2048m
depends_on:
- zookeeper
kafka2:
image: wurstmeister/kafka
restart: always
container_name: kafka2
hostname: kafka2
ports:
- "9093:9092"
environment:
KAFKA_BROKER_ID: 2
KAFKA_LISTENERS: PLAINTEXT://0.0.0.0:9092
KAFKA_ADVERTISED_LISTENERS: PLAINTEXT://172.17.0.216:9093 ## 宿主機IP
KAFKA_ADVERTISED_HOST_NAME: kafka2
KAFKA_ADVERTISED_PORT: 9093
KAFKA_ZOOKEEPER_CONNECT: "zookeeper:2181"
volumes:
- "./kafka/kafka2/data/:/kafka"
- /etc/localtime:/etc/localtime:ro
cpus: '2'
mem_limit: 2048m
depends_on:
- zookeeper
kafka3:
image: wurstmeister/kafka
restart: always
container_name: kafka3
hostname: kafka3
ports:
- "9094:9092"
environment:
KAFKA_BROKER_ID: 3
KAFKA_LISTENERS: PLAINTEXT://0.0.0.0:9092
KAFKA_ADVERTISED_LISTENERS: PLAINTEXT://172.17.0.216:9094 ## 宿主機IP
KAFKA_ADVERTISED_HOST_NAME: kafka3
KAFKA_ADVERTISED_PORT: 9094
KAFKA_ZOOKEEPER_CONNECT: "zookeeper:2181"
volumes:
- "./kafka/kafka3/data/:/kafka"
- /etc/localtime:/etc/localtime:ro
cpus: '2'
mem_limit: 2048m
depends_on:
- zookeeper
# kafka_manager:
# image: 'hlebalbau/kafka-manager:latest'
# restart: always
# ports:
# - "9000:9000"
# environment:
# ZK_HOSTS: "zookeeper:2181"
# APPLICATION_SECRET: letmein
# volumes:
# - /etc/localtime:/etc/localtime:ro
# depends_on:
# - zookeeper
# - kafka1
# - kafka2
# - kafka3
# cpus: '1'
# mem_limit: 1024m
# container_name: kafka_manager
kafdrop:
image: obsidiandynamics/kafdrop
restart: always
ports:
- "9000:9000"
environment:
KAFKA_BROKERCONNECT: "kafka1:9092,kafka2:9092,kafka3:9092"
depends_on:
- zookeeper
- kafka1
- kafka2
- kafka3
cpus: '1'
mem_limit: 1024m
container_name: kafdrop
啟動
docker-compose up -d
查看日志昔汉,目錄權限是否正確。