kafka.yml

 

2022-11-23

  • kafka
    • host: 0.0.0.0:9092
    • topic: test
    • partition: 0
  • kafka Web 管理
    • 0.0.0.0:9000

Docker Compose 配置文件:

1
version: '3.5'
2
services:
3
zookeeper:
4
image: wurstmeister/zookeeper
5
container_name: zookeeper
6
ports:
7
- "2181:2181"
8
restart: always
9
10
kafka:
11
image: wurstmeister/kafka
12
container_name: kafka # 容器名
13
volumes:
14
- /etc/localtime:/etc/localtime
15
ports:
16
- "9092:9092"
17
environment:
18
KAFKA_ADVERTISED_HOST_NAME: localhost
19
KAFKA_ZOOKEEPER_CONNECT: zookeeper:2181
20
KAFKA_BROKER_ID: 1 # 不能重复
21
KAFKA_OFFSETS_TOPIC_REPLICATION_FACTOR: 1 # 副本数
22
KAFKA_CREATE_TOPICS: "test:1:1" # 话题:Partition:Replica (数量)
23
restart: always # 重启后自动运行
24
25
kafka-manager: # Web 管理界面
26
image: sheepkiller/kafka-manager
27
container_name: kafka-manager
28
ports:
29
- "9000:9000"
30
environment:
31
ZK_HOSTS: 0.0.0.0:2181 # zookeeper 地址
32
restart: always
  • 进入 kafka 容器: docker exec -it kafka /bin/bash
  • 查看话题: kafka-topics.sh --list --zookeeper zookeeper:2181
  • 生产消息: kafka-console-producer.sh --broker-list kafka:9092 --topic=test
  • 消费消息: kafka-console-consumer.sh --bootstrap-server kafka:9092 --from-beginning --topic test