欢迎来到刘认真的博客

It's not me that's wrong. It's the whole world

docker kafka 安装步骤

首先创建一个网络
app-tier:网络名称
–driver:网络类型为bridge

docker network create app-tier --driver bridge

1、安装zookeeper

Kafka依赖zookeeper所以先安装zookeeper
-p:设置映射端口(默认2181)
-d:后台启动

docker run -d --name zookeeper-server \
--network app-tier \
-e ALLOW_ANONYMOUS_LOGIN=yes \
bitnami/zookeeper:latest 

查看zookeeper容器日志(可省略)

docker logs -f zookeeper

2、安装Kafka

安装并运行Kafka,
–name:容器名称
-p:设置映射端口(默认9092 )
-d:后台启动
ALLOW_PLAINTEXT_LISTENER任何人可以访问
KAFKA_CFG_ZOOKEEPER_CONNECT链接的zookeeper
KAFKA_ADVERTISED_HOST_NAME当前主机IP或地址(重点:如果是服务器部署则配服务器IP或域名否则客户端监听消息会报地址错误)
-e KAFKA_CFG_ADVERTISED_LISTENERS=PLAINTEXT://192.168.0.101:9092 \

docker run -d -p30021:9092 -p30022:9093 -e KAFKA_ENABLE_KRAFT=yes \
--network app-tier \
-e KAFKA_CFG_PROCESS_ROLES=broker,controller \
-e KAFKA_CFG_MESSAGE_MAX_BYTES=23068672 \
-e KAFKA_CFG_MAX_REQUEST_SIZE=23068672 \
-e KAFKA_CFG_MAX_PARTITION_FETCH_BYTES=23068672 \
-e KAFKA_CFG_LOG_RETENTION_HOURS=12 \
-e KAFKA_CFG_NODE_ID=1 \
-e KAFKA_CFG_LOG_RETENTION_CHECK_INTERVAL_MS=300000 \
-e KAFKA_CFG_LOG_RETENTION_BYTES=23068672 \
-e KAFKA_CFG_LISTENERS=PLAINTEXT://:9092,CONTROLLER://:9093 \
-e KAFKA_CFG_LISTENER_SECURITY_PROTOCOL_MAP=CONTROLLER:PLAINTEXT,PLAINTEXT:PLAINTEXT \
-e KAFKA_CFG_CONTROLLER_QUORUM_VOTERS=1@127.0.0.1:9093 \
-e KAFKA_CFG_CONTROLLER_LISTENER_NAMES=CONTROLLER \
-e KAFKA_CFG_ADVERTISED_LISTENERS=PLAINTEXT://10.40.92.28:30021 \
-e KAFKA_BROKER_ID=1 \
-e ALLOW_PLAINTEXT_LISTENER=yes \
--name kafka bitnami/kafka:3.2
-e KAFKA_CFG_ADVERTISED_LISTENERS=PLAINTEXT://10.40.92.28:30021 \    自己的ip:端口
 

查看kafka容器日志(可省略)

docker logs -f kafka

3、kafka-map图形化管理工具


图形化管理工具
访问地址:http://服务器IP:9001/
DEFAULT_USERNAME:默认账号admin
DEFAULT_PASSWORD:默认密码admin

Git 地址:https://github.com/dushixiang/kafka-map/blob/master/README-zh_CN.md

docker run -d --name kafka-map \
--network app-tier \
-p 9001:8080 \
-v /opt/kafka-map/data:/usr/local/kafka-map/data \
-e DEFAULT_USERNAME=admin \
-e DEFAULT_PASSWORD=admin \
--restart always dushixiang/kafka-map:latest



posted @ 2023-02-02 10:38  刘认真  阅读(231)  评论(0编辑  收藏  举报