美文网首页
docker-compose搭建kafka单机集群环境

docker-compose搭建kafka单机集群环境

作者: 销毁first | 来源:发表于2021-03-17 00:01 被阅读0次

    1.配置网络(复用已有网络)

    1.1 创建docker虚拟网络

    # 创建一个名为clickhouse的桥接(bridge)虚拟网络,网关172.26.0.1,网段为172.25.0.0
    docker network create -d bridge --subnet=172.26.0.0/16 --gateway=172.26.0.1 clickhouse
    

    2.启停命令

    在docker-compose.yml路径下:

    构建开启: docker-compose up -d

    停止: docker-compose stop

    开启:docker-compose start

    2.编写docker-compose.yml

    version: '3.7'
    services:
      zoo1:
        image: wurstmeister/zookeeper
        #restart: always
        hostname: zoo1
        ports:
          - "12181:2181"
        container_name: kafka-zookeeper
        volumes:
         - /opt/DockerData/kafka-zookeeper:/opt/zookeeper-3.4.13/data
         - /opt/DockerData/kafka-zookeeper/myid:/opt/zookeeper-3.4.13/data/myid
        networks:
          clickhouse:
            ipv4_address: 172.26.0.106
      kafka1:
        image: wurstmeister/kafka
        #restart: always
        hostname: kafka1
        ports:
          - "9092:9092"
        container_name: kafka1
        environment:
          KAFKA_ADVERTISED_HOST_NAME: 192.168.0.102
          KAFKA_ADVERTISED_LISTENERS: PLAINTEXT://192.168.0.102:9092
          KAFKA_ZOOKEEPER_CONNECT: "zoo1:2181"
          KAFKA_ADVERTISED_PORT: 9092
          KAFKA_BROKER_ID: 1
          KAFKA_OFFSETS_TOPIC_REPLICATION_FACTOR: 1
        volumes:
          - /opt/DockerData/kafka1/logs:/kafka
        depends_on:
          - zoo1
        networks:
          clickhouse:
            ipv4_address: 172.26.0.107
      kafka2:
        image: wurstmeister/kafka
        #restart: always
        hostname: kafka2
        ports:
          - "9093:9092"
        container_name: kafka2
        environment:
          KAFKA_ADVERTISED_HOST_NAME: 192.168.0.102
          KAFKA_ADVERTISED_LISTENERS: PLAINTEXT://192.168.0.102:9093
          KAFKA_ZOOKEEPER_CONNECT: "zoo1:2181"
          KAFKA_ADVERTISED_PORT: 9093
          KAFKA_BROKER_ID: 2
          KAFKA_OFFSETS_TOPIC_REPLICATION_FACTOR: 1
        volumes:
          - /opt/DockerData/kafka2/logs:/kafka
        depends_on:
          - zoo1
        networks:
          clickhouse:
            ipv4_address: 172.26.0.108
      kafka3:
        image: wurstmeister/kafka
        #restart: always
        hostname: kafka3
        ports:
          - "9094:9092"
        container_name: kafka3
        environment:
          KAFKA_ADVERTISED_HOST_NAME: 192.168.0.102
          KAFKA_ADVERTISED_LISTENERS: PLAINTEXT://192.168.0.102:9094
          KAFKA_ZOOKEEPER_CONNECT: "zoo1:2181"
          KAFKA_ADVERTISED_PORT: 9094
          KAFKA_BROKER_ID: 3
          KAFKA_OFFSETS_TOPIC_REPLICATION_FACTOR: 1
        volumes:
          - /opt/DockerData/kafka3/logs:/kafka
        depends_on:
          - zoo1
        networks:
          clickhouse:
            ipv4_address: 172.26.0.109
    ##  kafka-manager:
    ##    image: hlebalbau/kafka-manager              ## 镜像:开源的web管理kafka集群的界面
    ##    environment:
    ##        ZK_HOSTS: 172.26.0.106
    ##    ports:
    ##      - "19000:9000"                               ## 暴露端口
    ##    networks:
    ##      clickhouse:
    ##        ipv4_address: 172.26.0.110
    
    networks:
     clickhouse:
      external: true
    

    客户端

    1. kafka-tool软件
    2. 命令行
    3. kafka-manager界面(新版的连zk有问题)

    相关文章

      网友评论

          本文标题:docker-compose搭建kafka单机集群环境

          本文链接:https://www.haomeiwen.com/subject/ifydcltx.html