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
注意:如果是外部使用,需要加入变量KAFKA_CFG_ADVERTISED_LISTENERS: PLAINTEXT://<外部访问IP>:9092