docker-compose 安装kafka
docker-compose 安装kafka
docker-compose.yml如下:
version: '2'
services:
zookeeper:
container_name: zookeeper
image: wurstmeister/zookeeper
volumes:
- ./zookeeper/data:/data
ports:
- "2181:2181"
kafka:
container_name: kafka
image: wurstmeister/kafka
ports:
- "9092:9092"
environment:
KAFKA_ADVERTISED_HOST_NAME: localhost
KAFKA_MESSAGE_MAX_BYTES: 2000000
KAFKA_CREATE_TOPICS: "test:1:1"
KAFKA_ZOOKEEPER_CONNECT: zookeeper:2181
volumes:
- ./kafka:/kafka
- /var/run/docker.sock:/var/run/docker.sock
kafka-manager:
container_name: kafka-manager
image: sheepkiller/kafka-manager
ports:
- 9020:9000
environment:
ZK_HOSTS: zookeeper:2181
参数说明:
- KAFKA_ADVERTISED_HOST_NAME:Docker宿主机IP(如果你要配置多个brokers,就不能设置为 localhost 或 127.0.0.1)
- KAFKA_MESSAGE_MAX_BYTES:kafka(message.max.bytes) 会接收单个消息size的最大限制,默认值为1000000 , ≈1M
- KAFKA_CREATE_TOPICS:初始创建的topics,可以不设置
- 环境变量./kafka为防止容器销毁时消息数据丢失。
- 容器kafka-manager为yahoo出可视化kafka WEB管理平台。
启动:
docker-compose up -d
docker exec -it kafka /bin/bash
cd /opt/kafka_<version>/bin
:
创建Topic
kafka-topics.sh --create --zookeeper zookeeper:2181 --replication-factor 1 --partitions 1 --topic first_kafka_topic
查看Topic
kafka-topics.sh --list --zookeeper zookeeper:2181
参考:
https://github.com/wurstmeister/kafka-docker
https://towardsdatascience.com/how-to-install-apache-kafka-using-docker-the-easy-way-4ceb00817d8b
不要小瞧女程序员