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

1、下载zk镜像

shell 复制代码
docker pull zookeeper:3.6.3

2、创建docker网络

shell 复制代码
docker network create zk-net

3、创建zk集群

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

yml文件内容:

shell 复制代码
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启动、停止(指定配置文件)

shell 复制代码
docker-compose -f D:\soft\docker\docker-compose-zookeeper-cluster.yml up -d

启动成功:

指定配置文件停止

shell 复制代码
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镜像

shel 复制代码
docker pull bitnami/kafka:2.7.0

2、创建网络

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

3、创建kafka集群

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

文件内容:

yaml 复制代码
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启动、停止(指定配置文件)

shell 复制代码
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网络:

shel 复制代码
docker network connect zk-net kafka01
docker network connect zk-net kafka02
docker network connect zk-net kafka03

重启:

shell 复制代码
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查看容器日志:

shell 复制代码
docker logs a679f5a4a1d4
相关推荐
Jtti1 小时前
Windows系统服务器怎么设置远程连接?详细步骤
运维·服务器·windows
小奥超人1 小时前
PPT文件设置了修改权限,如何取消权?
windows·经验分享·microsoft·ppt·办公技巧
Mephisto.java3 小时前
【大数据学习 | kafka高级部分】kafka的kraft集群
大数据·sql·oracle·kafka·json·hbase
Mephisto.java3 小时前
【大数据学习 | kafka高级部分】kafka的文件存储原理
大数据·sql·oracle·kafka·json
川石课堂软件测试3 小时前
性能测试|docker容器下搭建JMeter+Grafana+Influxdb监控可视化平台
运维·javascript·深度学习·jmeter·docker·容器·grafana
yx9o4 小时前
Kafka 源码 KRaft 模式本地运行
分布式·kafka
追风林10 小时前
mac 本地docker-mysql主从复制部署
mysql·macos·docker
hairenjing112310 小时前
使用 Mac 数据恢复从 iPhoto 图库中恢复照片
windows·stm32·嵌入式硬件·macos·word
java1234_小锋11 小时前
讲讲RabbitMQ 性能优化
kafka
九鼎科技-Leo12 小时前
了解 .NET 运行时与 .NET 框架:基础概念与相互关系
windows·c#·.net