Kafka 安装
# Docker Compose 安装 Kafka 3.4.0
本文将会介绍一下,基于 Docker Compose 安装单机的 Kafka
# yaml 配置文件
# docker compose 部署 kafka
# 本示例中宿主机IP: 8.142.110.11
version: "3.9"
services:
zookeeper:
image: 'bitnami/zookeeper:3.8'
container_name: zookeeper
ports:
- '2181:2181'
environment:
- ALLOW_ANONYMOUS_LOGIN=yes # 匿名登录
volumes:
- "$PWD/data/kafka/zk-data:/bitnami"
networks:
kafka:
aliases:
- zookeeper
# kafka
kafka:
image: 'bitnami/kafka:3.4.0'
container_name: kafka
ports:
- '9092:9092'
- '9093:9093'
environment:
- KAFKA_ENABLE_KRAFT=yes
- KAFKA_CFG_PROCESS_ROLES=broker,controller
- KAFKA_CFG_CONTROLLER_LISTENER_NAMES=CONTROLLER
- KAFKA_CFG_LISTENERS=PLAINTEXT://:9092,CONTROLLER://:9093 # 定义 Kafka Broker 的 Listener 的配置项,配置外部访问和内部访问
- KAFKA_CFG_LISTENER_SECURITY_PROTOCOL_MAP=CONTROLLER:PLAINTEXT,PLAINTEXT:PLAINTEXT
- KAFKA_CFG_ADVERTISED_LISTENERS=PLAINTEXT://8.142.110.11:9092 # 传递回客户端的元数据,填写宿主机IP地址
- KAFKA_BROKER_ID=1 # 配置 broker id
- KAFKA_HEAP_OPTS=-Xmx512m -Xms256m
- KAFKA_CFG_CONTROLLER_QUORUM_VOTERS=1@127.0.0.1:9093
- ALLOW_PLAINTEXT_LISTENER=yes
- TZ=Asia/Shanghai # 时区
depends_on:
- zookeeper
# 挂在到 当前路径下的 data/kafka/kafka-data 中
volumes:
- "$PWD/data/kafka/kafka-data:/bitnami"
networks:
kafka:
aliases:
- kafka
# ui 管理界面
kafka-ui:
image: provectuslabs/kafka-ui
container_name: kafka-ui
ports:
- "9999:8080"
restart: always
# 更多环境配置参考 https://github.com/provectus/kafka-ui#-environment-variables
environment:
- KAFKA_CLUSTERS_0_NAME=local
- KAFKA_CLUSTERS_0_BOOTSTRAPSERVERS=kafka:9092
- KAFKA_CLUSTERS_0_ZOOKEEPER=zookeeper:2181
- KAFKA_CLUSTERS_0_READONLY=false # 是否以只读模式运行,只读的话,就不能增删改 topic 等
depends_on:
- zookeeper
- kafka
networks:
kafka:
aliases:
- kafka-ui
networks:
kafka:
driver: bridge
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
# 启动
执行执行指令如下! 注意:在启动脚本同级下的 data 文件夹,一定要赋予读写权限,不然会启动失败
[root@bulk kafka]# ll
总用量 8
drwxrwxrwx 2 root root 4096 3月 9 10:41 data
-rw-r--r-- 1 root root 2035 3月 9 10:41 docker-compose-kafka-single.yml
# 注意 这里一定要 设置读写权限 !! 负责会启动失败
[root@bulk kafka]# chmod -R 777 data/
[root@bulk kafka]# docker-compose -f docker-compose-kafka-single.yml up -d
Creating network "kafka_kafka" with driver "bridge"
Pulling zookeeper (bitnami/zookeeper:3.8)...
3.8: Pulling from bitnami/zookeeper
503dda889fb7: Pull complete
Digest: sha256:42ab7f4f441011df57b4cd86b9bb04be58ae79712e41d2ce99d5d7fd2da85b88
Status: Downloaded newer image for bitnami/zookeeper:3.8
Pulling kafka (bitnami/kafka:3.4.0)...
3.4.0: Pulling from bitnami/kafka
55154658374f: Pull complete
Digest: sha256:659549c08f8a1cfce344d31b608ec2d039a66a9b610423c4bc390c486a8cebbd
Status: Downloaded newer image for bitnami/kafka:3.4.0
Pulling kafka-ui (provectuslabs/kafka-ui:)...
latest: Pulling from provectuslabs/kafka-ui
59bf1c3509f3: Pull complete
f3449ca82c13: Pull complete
c631eae86696: Pull complete
Digest: sha256:69d612ddf1ce38e9c5f59c47a8430247aa40da1822c32c6857cad48570bad791
Status: Downloaded newer image for provectuslabs/kafka-ui:latest
Creating zookeeper ... done
Creating kafka ... done
Creating kafka-ui ... done
[root@bulk kafka]# docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
125e53e46700 provectuslabs/kafka-ui "/bin/sh -c 'java $J…" 10 minutes ago Up 10 minutes 0.0.0.0:9999->8080/tcp, :::9999->8080/tcp kafka-ui
b64138b87c5e bitnami/kafka:3.4.0 "/opt/bitnami/script…" 10 minutes ago Up 18 seconds 0.0.0.0:9092-9093->9092-9093/tcp, :::9092-9093->9092-9093/tcp kafka
17f6c56fbea2 bitnami/zookeeper:3.8 "/opt/bitnami/script…" 10 minutes ago Up 18 seconds 2888/tcp, 3888/tcp, 0.0.0.0:2181->2181/tcp, :::2181->2181/tcp, 8080/tcp zookeeper
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
部署好了之后,访问你的宿主机ip:9999,就可以访问的到 Kafka UI 的界面了
上次更新: 2023/03/18, 09:23:32