version: "3.3"
services:
zookeeper-server:
image: zookeeper:3.7
volumes:
# zookeeper快照数据
- "zookeeper_data:/data"
# zookeeper事务日志
- "zookeeper_datalog:/datalog"
ports:
# 对client提供服务
- "3181:2181"
restart: always
zookeeper-ui:
image: juris/zkui:latest
ports:
# zookeeper-ui的http端口,访问http://主机ip:主机映射端口(如3180)
- "3180:9090"
environment:
# zk-server地址和端口(配置服务名:容器端口)
ZK_SERVER: "zookeeper-server:2181"
# admin密码
USER_SET: '{"users":[{"username":"admin", "password":"admin", "role":"ADMIN"}]}'
restart: always
depends_on:
- zookeeper-server
kafka-server:
image: bitnami/kafka:3.4.0
ports:
# kafka客户端连接端口:无须身份认证
- "3092:9092"
# kafka客户端连接端口:需要身份认证
- "3093:9093"
volumes:
# kafka数据卷
- "kafka_data:/bitnami/kafka"
# 启用SASL_PLAINTEXT身份认证
- "./kafka-config/kafka_jaas.conf:/opt/bitnami/kafka/config/kafka_jaas.conf"
# 下面是两个身份认证需要的库文件 jackson-all-1.8.4.jar & VSaslLoginModule-1.0.jar
- "./kafka-libs/jackson-all-1.8.4.jar:/opt/bitnami/kafka/libs/jackson-all-1.8.4.jar"
- "./kafka-libs/VSaslLoginModule-1.0.jar:/opt/bitnami/kafka/libs/VSaslLoginModule-1.0.jar"
environment:
# 详细的环境变量参考:https://github.com/bitnami/containers/tree/main/bitnami/kafka,所有server.properties中的配置可以转化成:KAFKA_CFG_,例如:KAFKA_CFG_BACKGROUND_THREADS等价于background.threads
# zookeeper地址:端口(配置服务名:容器端口)
KAFKA_CFG_ZOOKEEPER_CONNECT: "zookeeper-server:2181"
# 允许客户端 免密码登录、明文通讯
ALLOW_PLAINTEXT_LISTENER: "yes"
# kafka监听端口 9092为免登录端口,9093需要身份认证
KAFKA_CFG_LISTENERS: "PLAINTEXT://:9092,SASL_PLAINTEXT://:9093"
# 本服务供外部访问的地址
KAFKA_CFG_ADVERTISED_LISTENERS: "PLAINTEXT://10.1.27.89:3092,SASL_PLAINTEXT://10.1.27.89:3093"
# 猜测:指示kafka节点之间的访问使用哪种协议-->对应前面的ADVERTISED_LISTENERS参数
KAFKA_CFG_SECURITY_INTER_BROKER_PROTOCOL: "PLAINTEXT"
# 猜测:和SECURITY_INTER_BROKER_PROTOCOL一个含义
KAFKA_CFG_SASL_MECHANISM_INTER_BROKER_PROTOCOL: "PLAIN"
# 猜测:和SECURITY_INTER_BROKER_PROTOCOL一个含义
KAFKA_CFG_SASL_ENABLED_MECHANISMS: "PLAIN"
# SASL_PLAINTEXT协议指定的身份认证回调
KAFKA_CFG_LISTENER_NAME_SASL_PLAINTEXT_PLAIN_SASL_SERVER_CALLBACK_HANDLER_CLASS: "com.toone.v3.platform.kafka.server.login.VSaslServerCallbackHandler"
# kafka集群中本节点的标识
KAFKA_BROKER_ID: "1"
#内存设置
KAFKA_HEAP_OPTS: "-Xms1024m -Xmx2048m"
restart: always
depends_on:
- zookeeper-server
kafka-ui:
# 参见:https://www.kafkamagic.com/start/
image: digitsy/kafka-magic:latest
ports:
# 访问kafka 管理界面:http://主机ip:主机映射端口(如3080)
- "3080:80"
volumes:
# 持久化kafka集群配置
- "./kafka_ui_config:/config"
environment:
KMAGIC_ALLOW_TOPIC_DELETE: "true"
KMAGIC_ALLOW_SCHEMA_DELETE: "true"
KMAGIC_CONFIG_STORE_TYPE: "file"
KMAGIC_CONFIG_STORE_CONNECTION: "Data Source=/config/KafkaMagicConfig.db;"
KMAGIC_CONFIG_ENCRYPTION_KEY: "ENTER_YOUR_KEY_HERE"
restart: always
volumes:
zookeeper_data:
zookeeper_datalog:
kafka_data:
服务器托管,北京服务器托管,服务器租用 http://www.fwqtg.net