glmapper

使用 docker 部署 kafka 集群

字数统计: 421阅读时长: 2 min
2021/07/13 Share

参考文档:https://github.com/wurstmeister/kafka-docker

在你的文件系统中找个目录,然后新建一个 docker-compose.yaml 文件

1
2
3
➜  kafka-guides 
total 8
-rw-r--r--@ 1 sgl staff 1.1K 7 13 21:56 docker-compose.yaml

编辑 docker-compose.yaml 文件

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
version: '2'
services:
zookeeper:
image: wurstmeister/zookeeper ## zk 镜像
ports:
- "2181:2181" ## 对外暴露的端口号
kafka:
image: wurstmeister/kafka ## kafka 镜像
volumes:
- /etc/localtime:/etc/localtime ## 挂载位置(kafka镜像和宿主机器之间时间保持一致)
ports:
- "9092:9092"
environment:
KAFKA_ADVERTISED_HOST_NAME: 192.168.10.67 ## 修改:宿主机IP ---- 192.168.10.67 是我当前的机器ip
KAFKA_ZOOKEEPER_CONNECT: zookeeper:2181 ## kafka 运行是基于zookeeper的
KAFKA_ADVERTISED_PORT: 9092
KAFKA_LOG_RETENTION_HOURS: 120
KAFKA_MESSAGE_MAX_BYTES: 10000000
KAFKA_REPLICA_FETCH_MAX_BYTES: 10000000
KAFKA_GROUP_MAX_SESSION_TIMEOUT_MS: 60000
KAFKA_NUM_PARTITIONS: 3
KAFKA_DELETE_RETENTION_MS: 1000
kafka-manager:
image: sheepkiller/kafka-manager ## 镜像:kafka-manager
environment:
ZK_HOSTS: 192.168.10.67 ## 修改:宿主机IP
ports:
- "9001:9000" ## 暴露端口 9001

启动服务:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
~ docker-compose up -d
# 执行日志大致如下
Pulling kafka (wurstmeister/kafka:)...
latest: Pulling from wurstmeister/kafka
540db60ca938: Pull complete
789c480dd801: Pull complete
0705a4c47ffe: Pull complete
661f40345821: Pull complete
a84fa3c6a2b3: Pull complete
Digest: sha256:4bad02cf8f07d0bf65d5cc73cce7aa75f9a90e32b585f867fce7c3fff229bd6d
Status: Downloaded newer image for wurstmeister/kafka:latest
Pulling kafka-manager (sheepkiller/kafka-manager:)...
latest: Pulling from sheepkiller/kafka-manager
469cfcc7a4b3: Pull complete
4458b033eac3: Pull complete
838a0ff6e24f: Pull complete
0128a98dafdb: Pull complete
Digest: sha256:615f3b99d38aba2d5fdb3fb750a5990ba9260c8fb3fd29c7e776e8c150518b78
Status: Downloaded newer image for sheepkiller/kafka-manager:latest
Creating kafka-guides_kafka-manager_1 ... done
Creating kafka-guides_zookeeper_1 ... done
Creating kafka-guides_kafka_1 ... done

此时可以通过访问 http://localhost:9001/ 来打开 kafka manager 页面进行验证。也可以通过 docker-compose ps 查看

1
2
3
4
5
6
7
➜  kafka-guides docker-compose ps
Name Command State Ports
------------------------------------------------------------------------------------------------------------------------
kafka-guides_kafka-manager_1 ./start-kafka-manager.sh Up 0.0.0.0:9001->9000/tcp,:::9001->9000/tcp
kafka-guides_kafka_1 start-kafka.sh Up 0.0.0.0:9092->9092/tcp,:::9092->9092/tcp
kafka-guides_zookeeper_1 /bin/sh -c /usr/sbin/sshd ... Up 0.0.0.0:2181->2181/tcp,:::2181->2181/tcp,
22/tcp, 2888/tcp, 3888/tcp

停止服务 docker-compose stop

1
2
3
4
5
# 停止服务
➜ kafka-guides docker-compose stop
Stopping kafka-guides_kafka_1 ... done
Stopping kafka-guides_zookeeper_1 ... done
Stopping kafka-guides_kafka-manager_1 ... done

停止并删除服务 docker-compose down

原文作者:GuoLei Song

原文链接:http://www.glmapper.com/2021/07/13/docker/docker-compose-kakfa-install/

发表日期:July 13th 2021, 10:18:55 pm

更新日期:July 18th 2021, 12:03:07 pm

版权声明:转载请注明出处

CATALOG