docker-compose 安装kafka

cat docker-compose.yml
version: "2.2"
services:
  zookeeper:
    image: bitnami/zookeeper:latest
    restart: always
    ports:
      - 2181:2181
    environment:
      # 匿名登录--必须开启
      - ALLOW_ANONYMOUS_LOGIN=yes
    volumes:
      - ./.zookeeper:/bitnami/zookeeper
      - /etc/localtime:/etc/localtime:ro
    cpus: '1'
    mem_limit: 500m
    container_name: zookeeper
  # 该镜像具体配置参考 https://github.com/bitnami/bitnami-docker-kafka/blob/master/README.md
#  kafka:
#    image: bitnami/kafka:latest
#    restart: always
#    ports:
#      - 9092:9092
#      - 9999:9999
#    environment:
#      - KAFKA_BROKER_ID=1
#      - KAFKA_CFG_LISTENERS=PLAINTEXT://:9092
#      - KAFKA_CFG_ADVERTISED_LISTENERS=PLAINTEXT://172.17.0.216:9092
#      - KAFKA_CFG_ZOOKEEPER_CONNECT=zookeeper:2181
#      # 允许使用PLAINTEXT协议(镜像中默认为关闭,需要手动开启)
#      - ALLOW_PLAINTEXT_LISTENER=yes
#      # 关闭自动创建 topic 功能
#      - KAFKA_CFG_AUTO_CREATE_TOPICS_ENABLE=false
#      # 全局消息过期时间 6 小时(测试时可以设置短一点)
#      - KAFKA_CFG_LOG_RETENTION_HOURS=6
#      # 开启JMX监控
#      - JMX_PORT=9999
#    volumes:
#      - ./.kafka:/bitnami/kafka
#      - /etc/localtime:/etc/localtime:ro
#    cpus: '2'
#    mem_limit: 2048m
#    depends_on:
#      - zookeeper
#    container_name: kafka
  # Web 管理界面 另外也可以用exporter+prometheus+grafana的方式来监控 https://github.com/danielqsj/kafka_exporter
  kafka1:
    image: wurstmeister/kafka
    restart: always
    container_name: kafka1
    hostname: kafka1
    ports:
      - "9092:9092"
    environment:
      KAFKA_BROKER_ID: 1
      KAFKA_LISTENERS: PLAINTEXT://0.0.0.0:9092
      KAFKA_ADVERTISED_LISTENERS: PLAINTEXT://172.17.0.216:9092    ## 宿主机IP
      KAFKA_ADVERTISED_HOST_NAME: kafka1
      KAFKA_ADVERTISED_PORT: 9092
      KAFKA_ZOOKEEPER_CONNECT: "zookeeper:2181"
    volumes:
      - "./kafka/kafka1/data/:/kafka"
      - /etc/localtime:/etc/localtime:ro
    cpus: '2'
    mem_limit: 2048m
    depends_on:
      - zookeeper


  kafka2:
    image: wurstmeister/kafka
    restart: always
    container_name: kafka2
    hostname: kafka2
    ports:
      - "9093:9092"
    environment:
      KAFKA_BROKER_ID: 2
      KAFKA_LISTENERS: PLAINTEXT://0.0.0.0:9092
      KAFKA_ADVERTISED_LISTENERS: PLAINTEXT://172.17.0.216:9093    ## 宿主机IP
      KAFKA_ADVERTISED_HOST_NAME: kafka2
      KAFKA_ADVERTISED_PORT: 9093
      KAFKA_ZOOKEEPER_CONNECT: "zookeeper:2181"
    volumes:
      - "./kafka/kafka2/data/:/kafka"
      - /etc/localtime:/etc/localtime:ro
    cpus: '2'
    mem_limit: 2048m
    depends_on:
      - zookeeper

  kafka3:
    image: wurstmeister/kafka
    restart: always
    container_name: kafka3
    hostname: kafka3
    ports:
      - "9094:9092"
    environment:
      KAFKA_BROKER_ID: 3
      KAFKA_LISTENERS: PLAINTEXT://0.0.0.0:9092
      KAFKA_ADVERTISED_LISTENERS: PLAINTEXT://172.17.0.216:9094   ## 宿主机IP
      KAFKA_ADVERTISED_HOST_NAME: kafka3
      KAFKA_ADVERTISED_PORT: 9094
      KAFKA_ZOOKEEPER_CONNECT: "zookeeper:2181"
    volumes:
      - "./kafka/kafka3/data/:/kafka"
      - /etc/localtime:/etc/localtime:ro
    cpus: '2'
    mem_limit: 2048m
    depends_on:
      - zookeeper

#  kafka_manager:
#    image: 'hlebalbau/kafka-manager:latest'
#    restart: always
#    ports:
#      - "9000:9000"
#    environment:
#      ZK_HOSTS: "zookeeper:2181"
#      APPLICATION_SECRET: letmein
#    volumes:
#      - /etc/localtime:/etc/localtime:ro
#    depends_on:
#      - zookeeper
#      - kafka1
#      - kafka2
#      - kafka3
#    cpus: '1'
#    mem_limit: 1024m
#    container_name: kafka_manager

  kafdrop:
    image: obsidiandynamics/kafdrop
    restart: always
    ports:
       - "9000:9000"
    environment:
       KAFKA_BROKERCONNECT: "kafka1:9092,kafka2:9092,kafka3:9092"
    depends_on:
      - zookeeper
      - kafka1
      - kafka2
      - kafka3
    cpus: '1'
    mem_limit: 1024m
    container_name: kafdrop

启动

docker-compose up -d

查看日志,目录权限是否正确。

你可能感兴趣的:(docker-compose 安装kafka)