使用 docker 镜像部署一套单节点的 Zookeeper + Kafka,但是一直Java却连不上一些处理思路。
为了提高部署效率,这里提供一个简单可启动的docker-compose。
version: "3.3"
services:
zookeeper:
image: zookeeper:3.5.5
restart: always
container_name: zookeeper
ports:
- "2181:2181"
expose:
- "2181"
environment:
- ZOO_MY_ID=1
kafka:
image: wurstmeister/kafka:2.12-2.2.1
restart: always
container_name: kafka
environment:
- KAFKA_BROKER_ID=1
- KAFKA_LISTENERS=PLAINTEXT://kafka:9090
- KAFKA_ZOOKEEPER_CONNECT=zookeeper:2181
- KAFKA_MESSAGE_MAX_BYTES=2000000
ports:
- "9090:9090"
depends_on:
- zookeeper
启动命令:docker-compose -f kafka.yml up -d
查看一下注册信息
docker exec -it zookeeper bash bin/zkCli.sh
-
创建个Topic
宿主机本身对 kafka 作映射
docker run -it --rm --network host wurstmeister/kafka:2.12-2.2.1
bash /opt/kafka/bin/kafka-topics.sh
--bootstrap-server kafka:9090
--create --topic logsTopic --partitions 1 --replication-factor 1