docker compose部署kafka集群

发布于:2025-02-11 ⋅ 阅读:(50) ⋅ 点赞:(0)

先部署zookeeper集群,启动

参考:docker compose部署zookeeper集群-CSDN博客

再部署kafka集群

networks:
  net:
    external: true

services:


  kafka1:
    restart: always
    image: wurstmeister/kafka:2.13_2.8.1
    container_name: kafka1
    hostname: kafka1
    ports:
      - '9092:9092'
    environment:
      - KAFKA_ZOOKEEPER_CONNECT=zookeeper1:2181,zookeeper2:2182,zookeeper3:2183/kafka
      - KAFKA_BROKER_ID=1      
      - KAFKA_LISTENERS=PLAINTEXT://0.0.0.0:9092
      - KAFKA_ADVERTISED_LISTENERS=PLAINTEXT://182.92.152.225:9092
      - ALLOW_PLAINTEXT_LISTENER=yes
      - KAFKA_OFFSETS_TOPIC_REPLICATION_FACTOR=3
      - KAFKA_NUM_PARTITIONS=1
    volumes:
      - /etc/localtime:/etc/localtime
      - /home/sumengnan/apache/kafka/kafka1/data:/kafka/kafka-logs-kafka1
      - /home/sumengnan/apache/kafka/kafka1/logs:/opt/kafka/logs
    networks:
      - net


  kafka2:
    restart: always
    image: wurstmeister/kafka:2.13_2.8.1
    container_name: kafka2
    hostname: kafka2
    ports:
      - '9093:9092'
    environment:
      - KAFKA_ZOOKEEPER_CONNECT=zookeeper1:2181,zookeeper2:2182,zookeeper3:2183/kafka
      - KAFKA_BROKER_ID=2      
      - KAFKA_LISTENERS=PLAINTEXT://0.0.0.0:9092
      - KAFKA_ADVERTISED_LISTENERS=PLAINTEXT://182.92.152.225:9093
      - ALLOW_PLAINTEXT_LISTENER=yes
      - KAFKA_OFFSETS_TOPIC_REPLICATION_FACTOR=3
      - KAFKA_NUM_PARTITIONS=1
    volumes:
      - /etc/localtime:/etc/localtime
      - /home/sumengnan/apache/kafka/kafka2/data:/kafka/kafka-logs-kafka2
      - /home/sumengnan/apache/kafka/kafka2/logs:/opt/kafka/logs
    networks:
      - net


  kafka3:
    restart: always
    image: wurstmeister/kafka:2.13_2.8.1
    container_name: kafka3
    hostname: kafka3
    ports:
      - '9094:9092'
    environment:
      - KAFKA_ZOOKEEPER_CONNECT=zookeeper1:2181,zookeeper2:2182,zookeeper3:2183/kafka
      - KAFKA_BROKER_ID=3      
      - KAFKA_LISTENERS=PLAINTEXT://0.0.0.0:9092
      - KAFKA_ADVERTISED_LISTENERS=PLAINTEXT://182.92.152.225:9094
      - ALLOW_PLAINTEXT_LISTENER=yes
      - KAFKA_OFFSETS_TOPIC_REPLICATION_FACTOR=3
      - KAFKA_NUM_PARTITIONS=1
    volumes:
      - /etc/localtime:/etc/localtime
      - /home/sumengnan/apache/kafka/kafka3/data:/kafka/kafka-logs-kafka3
      - /home/sumengnan/apache/kafka/kafka3/logs:/opt/kafka/logs
    networks:
      - net

  kafka-console-ui:
    restart: always
    image: wdkang/kafka-console-ui:v1.0.10
    container_name: kafka-console-ui
    hostname: kafka-console-ui
    ports:
      - '7766:7766'
    volumes:
      - /etc/localtime:/etc/localtime
      - /home/sumengnan/apache/kafka/kafka-console-ui/data:/app/data
      - /home/sumengnan/apache/kafka/kafka-console-ui/log:/app/log
    networks:
      - net

 其中:KAFKA_ADVERTISED_LISTENERS为外网ip地址

kafka-console-ui为kafka的可视化web界面,访问7676端口。


网站公告

今日签到

点亮在社区的每一天
去签到