docker之kafka安装
一、带zookeeper和UI版本
version: '3' services: xbd-zk-1: image: bitnami/zookeeper:3.8.1 restart: always container_name: xbd-zk-1 privileged: true ports: - 2181:2181 environment: - TZ=Asia/Shanghai - ZOO_PORT_NUMBER=2181 - ZOO_SERVER_ID=1 - ZOO_SERVERS=xbd-zk-1:2888:3888,xbd-zk-2:2888:3888 - ALLOW_ANONYMOUS_LOGIN=yes - ZOO_ENABLE_ADMIN_SERVER=no - ZOO_ADMIN_SERVER_PORT_NUMBER=12181 xbd-zk-2: image: bitnami/zookeeper:3.8.1 restart: always container_name: xbd-zk-2 privileged: true ports: - 2182:2182 environment: - TZ=Asia/Shanghai - ZOO_PORT_NUMBER=2182 - ZOO_SERVER_ID=2 - ZOO_SERVERS=xbd-zk-1:2888:3888,xbd-zk-2:2888:3888 - ALLOW_ANONYMOUS_LOGIN=yes - ZOO_ENABLE_ADMIN_SERVER=no - ZOO_ADMIN_SERVER_PORT_NUMBER=12182 xbd-kafka-1: image: bitnami/kafka:3.3.2 restart: always container_name: xbd-kafka-1 privileged: true user: root ports: - 9092:9092 environment: - TZ=Asia/Shanghai - ALLOW_PLAINTEXT_LISTENER=yes - KAFKA_CFG_LISTENERS=PLAINTEXT://:9092 - KAFKA_CFG_ADVERTISED_LISTENERS=PLAINTEXT://:9092 - KAFKA_ENABLE_KRAFT=no - KAFKA_BROKER_ID=1 - KAFKA_CFG_ZOOKEEPER_CONNECT=xbd-zk-1:2181,xbd-zk-2:2182 volumes: - /var/lib/kafka-1:/bitnami/kafka depends_on: - xbd-zk-1 - xbd-zk-2 xbd-kafka-2: image: bitnami/kafka:3.3.2 restart: always container_name: xbd-kafka-2 privileged: true user: root ports: - 9093:9092 environment: - TZ=Asia/Shanghai - ALLOW_PLAINTEXT_LISTENER=yes - KAFKA_CFG_LISTENERS=PLAINTEXT://:9092 - KAFKA_CFG_ADVERTISED_LISTENERS=PLAINTEXT://:9092 - KAFKA_ENABLE_KRAFT=no - KAFKA_BROKER_ID=2 - KAFKA_CFG_ZOOKEEPER_CONNECT=xbd-zk-1:2181,xbd-zk-2:2182 volumes: - /var/lib/kafka-2:/bitnami/kafka depends_on: - xbd-zk-1 - xbd-zk-2 xbd-kafka-manager: image: sheepkiller/kafka-manager:stable restart: always container_name: xbd-kafka-manager privileged: true ports: - 9000:9000 environment: - TZ=Asia/Shanghai - ZK_HOSTS=xbd-zk-1:2181,xbd-zk-2:2182 - APPLICATION_SECRET=xbd depends_on: - xbd-zk-1 - xbd-zk-2
二、基于KRAFT协议
version: '3' services: xbd-kafka-1: image: bitnami/kafka:3.3.2 restart: always container_name: xbd-kafka-1 privileged: true user: root ports: - 9092:9092 environment: - TZ=Asia/Shanghai - KAFKA_ENABLE_KRAFT=yes - KAFKA_KRAFT_CLUSTER_ID=LelM2dIFQkiUFvXCEcqRWA - KAFKA_BROKER_ID=1 - KAFKA_CFG_NODE_ID=1 - KAFKA_CFG_PROCESS_ROLES=broker,controller - KAFKA_CFG_CONTROLLER_LISTENER_NAMES=CONTROLLER - KAFKA_CFG_LISTENER_SECURITY_PROTOCOL_MAP=CONTROLLER:PLAINTEXT,PLAINTEXT:PLAINTEXT - KAFKA_CFG_LISTENERS=PLAINTEXT://:9092,CONTROLLER://:9093 - KAFKA_CFG_CONTROLLER_QUORUM_VOTERS=1@xbd-kafka-1:9093,2@xbd-kafka-2:9093 - ALLOW_PLAINTEXT_LISTENER=yes volumes: - /var/lib/kafka-1:/bitnami/kafka xbd-kafka-2: image: bitnami/kafka:3.3.2 restart: always container_name: xbd-kafka-2 privileged: true user: root ports: - 9093:9092 environment: - TZ=Asia/Shanghai - KAFKA_ENABLE_KRAFT=yes - KAFKA_KRAFT_CLUSTER_ID=LelM2dIFQkiUFvXCEcqRWA - KAFKA_BROKER_ID=2 - KAFKA_CFG_NODE_ID=2 - KAFKA_CFG_PROCESS_ROLES=broker,controller - KAFKA_CFG_CONTROLLER_LISTENER_NAMES=CONTROLLER - KAFKA_CFG_LISTENER_SECURITY_PROTOCOL_MAP=CONTROLLER:PLAINTEXT,PLAINTEXT:PLAINTEXT - KAFKA_CFG_LISTENERS=PLAINTEXT://:9092,CONTROLLER://:9093 - KAFKA_CFG_CONTROLLER_QUORUM_VOTERS=1@xbd-kafka-1:9093,2@xbd-kafka-2:9093 - ALLOW_PLAINTEXT_LISTENER=yes volumes: - /var/lib/kafka-2:/bitnami/kafka xbd-kafka-ui: image: provectuslabs/kafka-ui:v0.7.1 restart: always container_name: xbd-kafka-ui privileged: true ports: - 19092:8080 environment: - TZ=Asia/Shanghai - KAFKA_CLUSTERS_0_NAME=xbd-kafka - KAFKA_CLUSTERS_0_BOOTSTRAPSERVERS=xbd-kafka-1:9092,xbd-kafka-2:9092 depends_on: - xbd-kafka-1 - xbd-kafka-2
三、基于KRAFT的安全协议SASL模式
version: '3' services: xbd-kafka-1: image: bitnami/kafka:3.3.2 restart: always container_name: xbd-kafka-1 privileged: true user: root ports: - 9092:9092 environment: - TZ=Asia/Shanghai - KAFKA_ENABLE_KRAFT=yes - KAFKA_KRAFT_CLUSTER_ID=LelM2dIFQkiUFvXCEcqRWA - KAFKA_BROKER_ID=1 - KAFKA_CFG_NODE_ID=1 - KAFKA_CFG_PROCESS_ROLES=broker,controller - KAFKA_CFG_INTER_BROKER_LISTENER_NAME=SASL_PLAINTEXT - KAFKA_CFG_CONTROLLER_LISTENER_NAMES=CONTROLLER - KAFKA_CFG_LISTENER_SECURITY_PROTOCOL_MAP=CONTROLLER:PLAINTEXT,SASL_PLAINTEXT:SASL_PLAINTEXT - KAFKA_CFG_LISTENERS=SASL_PLAINTEXT://:9092,CONTROLLER://:9093 - KAFKA_CFG_CONTROLLER_QUORUM_VOTERS=1@xbd-kafka-1:9093,2@xbd-kafka-2:9093 - KAFKA_CFG_SASL_MECHANISM_INTER_BROKER_PROTOCOL=PLAIN - KAFKA_CFG_SASL_ENABLED_MECHANISMS=PLAIN - KAFKA_CLIENT_USERS=admin - KAFKA_CLIENT_PASSWORDS=admin - ALLOW_PLAINTEXT_LISTENER=yes volumes: - /var/lib/kafka-1:/bitnami/kafka xbd-kafka-2: image: bitnami/kafka:3.3.2 restart: always container_name: xbd-kafka-2 privileged: true user: root ports: - 9093:9092 environment: - TZ=Asia/Shanghai - KAFKA_ENABLE_KRAFT=yes - KAFKA_KRAFT_CLUSTER_ID=LelM2dIFQkiUFvXCEcqRWA - KAFKA_BROKER_ID=2 - KAFKA_CFG_NODE_ID=2 - KAFKA_CFG_PROCESS_ROLES=broker,controller - KAFKA_CFG_INTER_BROKER_LISTENER_NAME=SASL_PLAINTEXT - KAFKA_CFG_CONTROLLER_LISTENER_NAMES=CONTROLLER - KAFKA_CFG_LISTENER_SECURITY_PROTOCOL_MAP=CONTROLLER:PLAINTEXT,SASL_PLAINTEXT:SASL_PLAINTEXT - KAFKA_CFG_LISTENERS=SASL_PLAINTEXT://:9092,CONTROLLER://:9093 - KAFKA_CFG_CONTROLLER_QUORUM_VOTERS=1@xbd-kafka-1:9093,2@xbd-kafka-2:9093 - KAFKA_CFG_SASL_MECHANISM_INTER_BROKER_PROTOCOL=PLAIN - KAFKA_CFG_SASL_ENABLED_MECHANISMS=PLAIN - KAFKA_CLIENT_USERS=admin - KAFKA_CLIENT_PASSWORDS=admin - ALLOW_PLAINTEXT_LISTENER=yes volumes: - /var/lib/kafka-2:/bitnami/kafka xbd-kafka-ui: image: provectuslabs/kafka-ui:v0.7.1 restart: always container_name: xbd-kafka-ui privileged: true ports: - 19092:8080 environment: - TZ=Asia/Shanghai - KAFKA_CLUSTERS_0_NAME=xbd-kafka - KAFKA_CLUSTERS_0_BOOTSTRAPSERVERS=xbd-kafka-1:9092,xbd-kafka-2:9092 - KAFKA_CLUSTERS_0_PROPERTIES_SECURITY_PROTOCOL=SASL_PLAINTEXT - KAFKA_CLUSTERS_0_PROPERTIES_SASL_MECHANISM=PLAIN - KAFKA_CLUSTERS_0_PROPERTIES_SASL_JAAS_CONFIG=org.apache.kafka.common.security.scram.ScramLoginModule required username="admin" password="admin"; depends_on: - xbd-kafka-1 - xbd-kafka-2
注意:如果是外部使用,需要加入变量KAFKA_CFG_ADVERTISED_LISTENERS: PLAINTEXT://<外部访问IP>:9092
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】凌霞软件回馈社区,博客园 & 1Panel & Halo 联合会员上线
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步