Windows使用docker desktop 安装kafka、zookeeper集群

docker-compose安装zookeeper集群

参考文章:http://t.csdn.cn/TtTYI

https://blog.csdn.net/u010416101/article/details/122803105?spm=1001.2014.3001.5501

准备工作:

​ 在开始新建集群之前,新建好文件夹,用来挂载kafka、zookeeper数据,如下:
zookeeper文件夹

D:\soft\docker\zookeeper\zoo1\data
D:\soft\docker\zookeeper\zoo1\datalog

D:\soft\docker\zookeeper\zoo2\data
D:\soft\docker\zookeeper\zoo2\datalog

D:\soft\docker\zookeeper\zoo3\data
D:\soft\docker\zookeeper\zoo3\datalog

kafka文件夹

D:\soft\docker\kafka\kafka1\data
D:\soft\docker\kafka\kafka2\data
D:\soft\docker\kafka\kafka3\data

Windows使用docker desktop 安装kafka、zookeeper集群_第1张图片 Windows使用docker desktop 安装kafka、zookeeper集群_第2张图片

Windows使用docker desktop 安装kafka、zookeeper集群_第3张图片 Windows使用docker desktop 安装kafka、zookeeper集群_第4张图片

1、下载zk镜像

docker pull zookeeper:3.6.3

Windows使用docker desktop 安装kafka、zookeeper集群_第5张图片

2、创建docker网络

docker network create zk-net

image-20230806165135181

3、创建zk集群

yml文件路径:D:\soft\docker\docker-compose-zookeeper-cluster.yml

yml文件内容:

version: '2'

networks:
  zk-net:
    external:
      name: zk-net

services:
  zoo1:
    image: 'zookeeper:3.6.3'
    container_name: zoo1
    hostname: zoo1
    environment:
      ZOO_MY_ID: 1
      ZOO_SERVERS: server.1=0.0.0.0:2888:3888;2181 server.2=zoo2:2888:3888;2181 server.3=zoo3:2888:3888;2181
      ALLOW_ANONYMOUS_LOGIN: "yes"
    networks:
      - zk-net
    ports:
      - 2181:2181
      - 8081:8080
    volumes:
      - /D/soft/docker/zookeeper/zoo1/data:/data
      - /D/soft/docker/zookeeper/zoo1/datalog:/datalog
  zoo2:
    image: 'zookeeper:3.6.3'
    container_name: zoo2
    hostname: zoo2
    environment:
      ZOO_MY_ID: 2
      ZOO_SERVERS: server.1=zoo1:2888:3888;2181 server.2=0.0.0.0:2888:3888;2181 server.3=zoo3:2888:3888;2181
      ALLOW_ANONYMOUS_LOGIN: "yes"
    networks:
      - zk-net
    ports:
      - 2182:2181
      - 8082:8080
    volumes:
      - /D/soft/docker/zookeeper/zoo2/data:/data  
      - /D/soft/docker/zookeeper/zoo2/datalog:/datalog  
  zoo3:
    image: 'zookeeper:3.6.3'
    container_name: zoo3
    hostname: zoo3
    environment:
      ZOO_MY_ID: 3
      ZOO_SERVERS: server.1=zoo1:2888:3888;2181 server.2=zoo2:2888:3888;2181 server.3=0.0.0.0:2888:3888;2181
      ALLOW_ANONYMOUS_LOGIN: "yes"
    networks:
      - zk-net
    ports:
      - 2183:2181
      - 8083:8080
    volumes:
      - /D/soft/docker/zookeeper/zoo3/data:/data  
      - /D/soft/docker/zookeeper/zoo3/datalog:/datalog   

4、docker-compose启动、停止(指定配置文件)

docker-compose -f D:\soft\docker\docker-compose-zookeeper-cluster.yml up -d

启动成功:

image-20230806172731215

image-20230806174412849

指定配置文件停止

docker-compose -f D:\soft\docker\docker-compose-zookeeper-cluster.yml stop

docker-compose安装Kafka集群

参考文章:https://blog.csdn.net/u010416101/article/details/122916190

1、下载kafka镜像

docker pull bitnami/kafka:2.7.0

2、创建网络

因为上面zk创建过了,这里不需要再创建

3、创建kafka集群

文件路径:D:\soft\docker\docker-compose-kafka-cluster.yml

文件内容:

version: "3"

networks:
  zk-net:
    external:
      name: zk-net

services:
  kafka01:
    image: 'bitnami/kafka:2.7.0'
    restart: always    
    container_name: kafka01
    hostname: kafka01
    ports:
      - '9092:9092'
    environment:
      - KAFKA_BROKER_ID=1
      - KAFKA_CFG_LISTENERS=PLAINTEXT://:9092
      - KAFKA_CFG_ADVERTISED_LISTENERS=PLAINTEXT://kafka01:9092
      - KAFKA_CFG_ZOOKEEPER_CONNECT=zoo1:2181,zoo2:2181,zoo3:2181
      - ALLOW_PLAINTEXT_LISTENER=yes
    volumes:
      - /D/soft/docker/kafka/kafka1:/bitnami/kafka     
    networks:
      - zk-net
  kafka02:
    image: 'bitnami/kafka:2.7.0'
    restart: always       
    container_name: kafka02
    hostname: kafka02
    ports:
      - '9093:9092'
    environment:
      - KAFKA_BROKER_ID=2
      - KAFKA_CFG_LISTENERS=PLAINTEXT://:9092
      - KAFKA_CFG_ADVERTISED_LISTENERS=PLAINTEXT://kafka02:9092
      - KAFKA_CFG_ZOOKEEPER_CONNECT=zoo1:2181,zoo2:2181,zoo3:2181
      - ALLOW_PLAINTEXT_LISTENER=yes
    volumes:
      - /D/soft/docker/kafka/kafka2:/bitnami/kafka       
    networks:
      - zk-net
  kafka03:
    image: 'bitnami/kafka:2.7.0'
    restart: always       
    container_name: kafka03
    hostname: kafka03
    ports:
      - '9094:9092'
    environment:
      - KAFKA_BROKER_ID=3
      - KAFKA_CFG_LISTENERS=PLAINTEXT://:9092    
      - KAFKA_CFG_ADVERTISED_LISTENERS=PLAINTEXT://kafka03:9092
      - KAFKA_CFG_ZOOKEEPER_CONNECT=zoo1:2181,zoo2:2181,zoo3:2181
      - ALLOW_PLAINTEXT_LISTENER=yes
    volumes:
      - /D/soft/docker/kafka/kafka3:/bitnami/kafka   
    networks:
      - zk-net

4、docker-compose启动、停止(指定配置文件)

docker-compose -f D:\soft\docker\docker-compose-kafka-cluster.yml up -d

kafka启动的时候,没有成功,后面参考了这篇文章:https://www.cnblogs.com/mihutao/p/16664588.html

如果kafka连接不上zookeeper,使用下面的命令加入zk-net网络:

docker network connect zk-net kafka01
docker network connect zk-net kafka02
docker network connect zk-net kafka03

重启:

docker-compose -f D:\soft\docker\docker-compose-zookeeper-cluster.yml restart
docker-compose -f D:\soft\docker\docker-compose-kafka-cluster.yml restart

由于kafka一直在自动重启,需要查看日志,docker查看容器日志:

docker logs a679f5a4a1d4

Windows使用docker desktop 安装kafka、zookeeper集群_第6张图片

你可能感兴趣的:(windows,docker,kafka)