docker-compose.yml
version: '3.3'
services:
zookeeper:
image: confluentinc/cp-zookeeper:${CONFLUENT_PLATFORM_VERSION:-5.2.2}
ports:
- "2181:2181"
- "2888:2888"
- "3888:3888"
healthcheck:
test: echo stat | nc localhost 2181
interval: 10s
timeout: 10s
retries: 3
environment:
- ZOOKEEPER_SERVER_ID=1
- ZOOKEEPER_CLIENT_PORT=2181
- ZOOKEEPER_TICK_TIME=2000
- ZOOKEEPER_INIT_LIMIT=5
- ZOOKEEPER_SYNC_LIMIT=2
- ZOOKEEPER_SERVERS=zookeeper:2888:3888
kafka1:
image: confluentinc/cp-kafka:${CONFLUENT_PLATFORM_VERSION:-5.2.2}
healthcheck:
test: ps augwwx | egrep [S]upportedKafka
depends_on:
- zookeeper
ports:
- "9091:9091"
environment:
- KAFKA_ADVERTISED_LISTENERS=PLAINTEXT://kafka1:9091
- KAFKA_LISTENERS=PLAINTEXT://0.0.0.0:9091
- KAFKA_ZOOKEEPER_CONNECT=zookeeper:2181
- KAFKA_BROKER_ID=1
- BOOTSTRAP_SERVERS=kafka1:9091,kafka2:9092,kafka3:9093,kafka4:9094,kafka5:9095
- ZOOKEEPER=zookeeper:2181
kafka2:
image: confluentinc/cp-kafka:${CONFLUENT_PLATFORM_VERSION:-5.2.2}
healthcheck:
test: ps augwwx | egrep [S]upportedKafka
depends_on:
- zookeeper
ports:
- "9092:9092"
environment:
- KAFKA_ADVERTISED_LISTENERS=PLAINTEXT://kafka2:9092
- KAFKA_LISTENERS=PLAINTEXT://0.0.0.0:9092
- KAFKA_ZOOKEEPER_CONNECT=zookeeper:2181
- KAFKA_BROKER_ID=2
- BOOTSTRAP_SERVERS=kafka1:9091,kafka2:9092,kafka3:9093,kafka4:9094,kafka5:9095
- ZOOKEEPER=zookeeper:2181
kafka3:
image: confluentinc/cp-kafka:${CONFLUENT_PLATFORM_VERSION:-5.2.2}
healthcheck:
test: ps augwwx | egrep [S]upportedKafka
depends_on:
- zookeeper
ports:
- "9093:9093"
environment:
- KAFKA_ADVERTISED_LISTENERS=PLAINTEXT://kafka3:9093
- KAFKA_LISTENERS=PLAINTEXT://0.0.0.0:9093
- KAFKA_ZOOKEEPER_CONNECT=zookeeper:2181
- KAFKA_BROKER_ID=3
- BOOTSTRAP_SERVERS=kafka1:9091,kafka2:9092,kafka3:9093,kafka4:9094,kafka5:9095
- ZOOKEEPER=zookeeper:2181
kafka4:
image: confluentinc/cp-kafka:${CONFLUENT_PLATFORM_VERSION:-5.2.2}
healthcheck:
test: ps augwwx | egrep [S]upportedKafka
depends_on:
- zookeeper
ports:
- "9094:9094"
environment:
- KAFKA_ADVERTISED_LISTENERS=PLAINTEXT://kafka4:9094
- KAFKA_LISTENERS=PLAINTEXT://0.0.0.0:9094
- KAFKA_ZOOKEEPER_CONNECT=zookeeper:2181
- KAFKA_BROKER_ID=4
- BOOTSTRAP_SERVERS=kafka1:9091,kafka2:9092,kafka3:9093,kafka4:9094,kafka5:9095
- ZOOKEEPER=zookeeper:2181
kafka5:
image: confluentinc/cp-kafka:${CONFLUENT_PLATFORM_VERSION:-5.2.2}
healthcheck:
test: ps augwwx | egrep [S]upportedKafka
depends_on:
- zookeeper
ports:
- "9095:9095"
environment:
- KAFKA_ADVERTISED_LISTENERS=PLAINTEXT://kafka5:9095
- KAFKA_LISTENERS=PLAINTEXT://0.0.0.0:9095
- KAFKA_ZOOKEEPER_CONNECT=zookeeper:2181
- KAFKA_BROKER_ID=5
- BOOTSTRAP_SERVERS=kafka1:9091,kafka2:9092,kafka3:9093,kafka4:9094,kafka5:9095
- ZOOKEEPER=zookeeper:2181
brokermanager:
image: kafkamanager/kafka-manager
restart: always
hostname: brokermanager
container_name: brokermanager
ports:
- "9000:9000"
depends_on:
- zookeeper
environment:
ZK_HOSTS: zookeeper:2181
kafa 单机
dockerhub地址:https://hub.docker.com/r/bitnami/kafka
安装docker-compose 组件
sudo wget "https://github.com/docker/compose/releases/download/v2.3.3/docker-compose-$(uname -s)-$(uname -m)" -O /usr/local/bin/docker-compose
sudo chmod +x /usr/local/bin/docker-compose
sudo ln -s /usr/local/bin/docker-compose /usr/bin/docker-compose
zk-kafka 配置文件
默认是kafka最新版本,若是使用低版本的kafka,直接拷贝下面的 zk-kafka-docker-compose-2.8.1.yml
wget https://raw.githubusercontent.com/bitnami/bitnami-docker-kafka/master/docker-compose.yml -O zk-kafka-docker-compose.yml
zk-kafka-docker-compose-2.8.1.yml
配置文件
version: "2"
services:
zookeeper:
image: docker.io/bitnami/zookeeper:3.7
ports:
- "2181:2181"
volumes:
- "zookeeper_data:/bitnami"
environment:
- ALLOW_ANONYMOUS_LOGIN=yes
kafka:
image: docker.io/bitnami/kafka:2.8.1
ports:
- "9092:9092"
volumes:
- "kafka_data:/bitnami"
environment:
- KAFKA_CFG_ZOOKEEPER_CONNECT=zookeeper:2181
- ALLOW_PLAINTEXT_LISTENER=yes
depends_on:
- zookeeper
volumes:
zookeeper_data:
driver: local
kafka_data:
driver: local
服务命令
启动服务
docker-compose -f zk-kafka-docker-compose.yml up -d
停止服务
docker-compose -f zk-kafka-docker-compose.yml stop
停止并删除服务
docker-compose -f docker-compose.yml down
查看控制台
提供两种ui界面
docker run -d --name kafka-manager -p 9000:9000 -e ZK_HOSTS=192.168.88.100:2181 -e KAFKA_BROKERS=192.168.88.100:9092 sheepkiller/kafka-manager
docker run -d -p 9000:9000 -e ZK_HOSTS=192.168.88.100:2181 solsson/kafka-manager