其他分享
首页 > 其他分享> > docker 搭建kafka集群

docker 搭建kafka集群

作者:互联网

1.环境

docker, docker-compose

2.zk-kafka.yml

version: '3'
services:
  zoo1:
    image: wurstmeister/zookeeper
    restart: unless-stopped
    hostname: zoo1
    ports:
      - "2181:2181"
    container_name: zookeeper
  kafka1:
    image: wurstmeister/kafka
    ports:
      - "9092:9092"
    environment:
      KAFKA_ADVERTISED_HOST_NAME: 你的宿主机IP                     ## 修改:宿主机IP
      KAFKA_ADVERTISED_LISTENERS: PLAINTEXT://宿主机IP:9092    ## 修改:宿主机IP
      KAFKA_ZOOKEEPER_CONNECT: "zoo1:2181"
      KAFKA_ADVERTISED_PORT: 9092
      KAFKA_BROKER_ID: 1
      KAFKA_OFFSETS_TOPIC_REPLICATION_FACTOR: 1
    depends_on:
      - zoo1
    container_name: kafka1

  kafka2:
    image: wurstmeister/kafka
    ports:
      - "9093:9092"
    environment:
      KAFKA_ADVERTISED_HOST_NAME: 宿主机IP                    ## 修改:宿主机IP
      KAFKA_ADVERTISED_LISTENERS: PLAINTEXT://宿主机IP:9093   ## 修改:宿主机IP
      KAFKA_ZOOKEEPER_CONNECT: "zoo1:2181"
      KAFKA_ADVERTISED_PORT: 9093
      KAFKA_BROKER_ID: 2
      KAFKA_OFFSETS_TOPIC_REPLICATION_FACTOR: 1
    depends_on:
      - zoo1
    container_name: kafka2
  kafka-manager:
    image: sheepkiller/kafka-manager              ## 镜像:开源的web管理kafka集群的界面
    environment:
        ZK_HOSTS: 宿主机IP                   ## 修改:宿主机IP
    ports:
      - "9000:9000"                               ## 暴露端口

3.启动

进入zk-kafka.yml目录

docker-compose -f zk-kafka.yml up -d

4.查看服务状态

进入zk-kafka.yml目录

docker-compose -f zk-kafka.yml ps

标签:##,IP,宿主机,KAFKA,zoo1,集群,docker,kafka
来源: https://www.cnblogs.com/f-society/p/13949003.html