使用 docker-compose 在单机搭建有三个节点的 kafka 集群。
version: "3"services:kafka1:image: "bitnami/kafka:3.3.1"networks:- kafka-controllercontainer_name: kafka11user: rootports:- 9192:9092environment:### 通用配置# 允许使用kraft,即Kafka替代Zookeeper- KAFKA_ENABLE_KRAFT=yes# kafka角色,做broker,也要做controller- KAFKA_CFG_PROCESS_ROLES=broker,controller# 指定供外部使用的控制类请求信息- KAFKA_CFG_CONTROLLER_LISTENER_NAMES=CONTROLLER# 定义kafka服务端socket监听端口- KAFKA_CFG_LISTENERS=PLAINTEXT://:9092,CONTROLLER://:9093# 定义安全协议- KAFKA_CFG_LISTENER_SECURITY_PROTOCOL_MAP=CONTROLLER:PLAINTEXT,PLAINTEXT:PLAINTEXT# 使用Kafka时的集群id,集群内的Kafka都要用这个id做初始化,生成一个UUID即可- KAFKA_KRAFT_CLUSTER_ID=LelM2dIFQkiUFvXCEcqRWA# 集群地址- KAFKA_CFG_CONTROLLER_QUORUM_VOTERS=1@kafka11:9093,2@kafka22:9093,3@kafka33:9093# 允许使用PLAINTEXT监听器,默认false,不建议在生产环境使用- ALLOW_PLAINTEXT_LISTENER=yes# 设置broker最大内存,和初始内存- KAFKA_HEAP_OPTS=-Xmx512M -Xms256M# 不允许自动创建主题- KAFKA_CFG_AUTO_CREATE_TOPICS_ENABLE=true### broker配置# 定义外网访问地址(宿主机ip地址和端口)- KAFKA_CFG_ADVERTISED_LISTENERS=PLAINTEXT://10.3.63.38:9192# broker.id,必须唯一- KAFKA_BROKER_ID=1volumes:- ./vol/kafka1/kafka/kraft:/bitnami/kafkakafka2:image: 'bitnami/kafka:3.3.1'networks:- kafka-controllercontainer_name: kafka22user: rootports:- 9292:9092environment:### 通用配置# 允许使用kraft,即Kafka替代Zookeeper- KAFKA_ENABLE_KRAFT=yes# kafka角色,做broker,也要做controller- KAFKA_CFG_PROCESS_ROLES=broker,controller# 指定供外部使用的控制类请求信息- KAFKA_CFG_CONTROLLER_LISTENER_NAMES=CONTROLLER# 定义kafka服务端socket监听端口- KAFKA_CFG_LISTENERS=PLAINTEXT://:9092,CONTROLLER://:9093# 定义安全协议- KAFKA_CFG_LISTENER_SECURITY_PROTOCOL_MAP=CONTROLLER:PLAINTEXT,PLAINTEXT:PLAINTEXT# 使用Kafka时的集群id,集群内的Kafka都要用这个id做初始化,生成一个UUID即可- KAFKA_KRAFT_CLUSTER_ID=LelM2dIFQkiUFvXCEcqRWA# 集群地址- KAFKA_CFG_CONTROLLER_QUORUM_VOTERS=1@kafka11:9093,2@kafka22:9093,3@kafka33:9093# 允许使用PLAINTEXT监听器,默认false,不建议在生产环境使用- ALLOW_PLAINTEXT_LISTENER=yes# 设置broker最大内存,和初始内存- KAFKA_HEAP_OPTS=-Xmx512M -Xms256M# 不允许自动创建主题- KAFKA_CFG_AUTO_CREATE_TOPICS_ENABLE=true### broker配置# 定义外网访问地址(宿主机ip地址和端口)- KAFKA_CFG_ADVERTISED_LISTENERS=PLAINTEXT://10.3.63.38:9292# broker.id,必须唯一- KAFKA_BROKER_ID=2volumes:- ./vol/kafka2/kafka/kraft:/bitnami/kafkakafka3:image: 'bitnami/kafka:3.3.1'networks:- kafka-controllercontainer_name: kafka33user: rootports:- 9392:9092environment:### 通用配置# 允许使用kraft,即Kafka替代Zookeeper- KAFKA_ENABLE_KRAFT=yes# kafka角色,做broker,也要做controller- KAFKA_CFG_PROCESS_ROLES=broker,controller# 指定供外部使用的控制类请求信息- KAFKA_CFG_CONTROLLER_LISTENER_NAMES=CONTROLLER# 定义kafka服务端socket监听端口- KAFKA_CFG_LISTENERS=PLAINTEXT://:9092,CONTROLLER://:9093# 定义安全协议- KAFKA_CFG_LISTENER_SECURITY_PROTOCOL_MAP=CONTROLLER:PLAINTEXT,PLAINTEXT:PLAINTEXT# 使用Kafka时的集群id,集群内的Kafka都要用这个id做初始化,生成一个UUID即可- KAFKA_KRAFT_CLUSTER_ID=LelM2dIFQkiUFvXCEcqRWA# 集群地址- KAFKA_CFG_CONTROLLER_QUORUM_VOTERS=1@kafka11:9093,2@kafka22:9093,3@kafka33:9093# 允许使用PLAINTEXT监听器,默认false,不建议在生产环境使用- ALLOW_PLAINTEXT_LISTENER=yes# 设置broker最大内存,和初始内存- KAFKA_HEAP_OPTS=-Xmx512M -Xms256M# 不允许自动创建主题- KAFKA_CFG_AUTO_CREATE_TOPICS_ENABLE=true### broker配置# 定义外网访问地址(宿主机ip地址和端口)- KAFKA_CFG_ADVERTISED_LISTENERS=PLAINTEXT://10.3.63.38:9392# broker.id,必须唯一- KAFKA_BROKER_ID=3volumes:- ./vol/kafka3/kafka/kraft:/bitnami/kafkakafka-ui:image: provectuslabs/kafka-ui:v0.7.1networks:- kafka-controllercontainer_name: kafka-uirestart: alwaysports:- 9400:8080volumes:- /etc/localtime:/etc/localtimeenvironment:# 集群名称- KAFKA_CLUSTERS_0_NAME=local# 集群地址- KAFKA_CLUSTERS_0_BOOTSTRAPSERVERS=kafka11:9092,kafka22:9092,kafka33:9092networks:kafka-controller: