docker-compose部署kafka
本文章会启动三个容器:kafka,zk, kafka-manage
kafka依赖zk来存储数据
kafka-manage用来管理kafka服务
$ vim docker-compose.yaml
# 注意volumes请自行修改宿主机映射目录,你自己决定,不创建也会自动生成
# kafka监听ip需要改下
version: '3.7'
services:
zookeeper:
image: wurstmeister/zookeeper
volumes:
- /root/kafka/zk-data:/opt/zookeeper-3.4.13/data
container_name: zookeeper
ports:
- 2181:2181
- 2182:2182
restart: always
kafka:
image: wurstmeister/kafka
container_name: kafka_node1
depends_on:
- zookeeper
ports:
- 9092:9092
volumes:
- /root/kafka/kafka-logs:/kafka
environment:
KAFKA_CREATE_TOPICS: "test"
KAFKA_BROKER_NO: 0
KAFKA_LISTENERS: PLAINTEXT://kafka_node1:9092
KAFKA_ADVERTISED_LISTENERS: PLAINTEXT://192.168.2.240:9092
KAFKA_INTER_BROKER_LISTENER_NAME: PLAINTEXT
KAFKA_ZOOKEEPER_CONNECT: zookeeper:2181
KAFKA_OFFSETS_TOPIC_REPLICATION_FACTOR: 1
KAFKA_HEAP_OPTS: "-Xmx512M -Xms16M"
restart: always
kafka_manager:
image: sheepkiller/kafka-manager
ports:
- 9000:9000
environment:
ZK_HOSTS: zookeeper:2181
depends_on:
- zookeeper
- kafka
restart: always
访问 http://ip:9000 添加kafka集群即可