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\datalogD:\soft\docker\zookeeper\zoo2\data
D:\soft\docker\zookeeper\zoo2\datalogD:\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镜像
docker pull zookeeper:3.6.3
2、创建docker网络
docker network create zk-net
3、创建zk集群
yml文件路径:D:\soft\docker\docker-compose-zookeeper-cluster.yml
yml文件内容:
version: '2'networks:zk-net:external:name: zk-netservices:zoo1:image: 'zookeeper:3.6.3'container_name: zoo1hostname: zoo1environment:ZOO_MY_ID: 1ZOO_SERVERS: server.1=0.0.0.0:2888:3888;2181 server.2=zoo2:2888:3888;2181 server.3=zoo3:2888:3888;2181ALLOW_ANONYMOUS_LOGIN: "yes"networks:- zk-netports:- 2181:2181- 8081:8080volumes:- /D/soft/docker/zookeeper/zoo1/data:/data- /D/soft/docker/zookeeper/zoo1/datalog:/datalogzoo2:image: 'zookeeper:3.6.3'container_name: zoo2hostname: zoo2environment:ZOO_MY_ID: 2ZOO_SERVERS: server.1=zoo1:2888:3888;2181 server.2=0.0.0.0:2888:3888;2181 server.3=zoo3:2888:3888;2181ALLOW_ANONYMOUS_LOGIN: "yes"networks:- zk-netports:- 2182:2181- 8082:8080volumes:- /D/soft/docker/zookeeper/zoo2/data:/data - /D/soft/docker/zookeeper/zoo2/datalog:/datalog zoo3:image: 'zookeeper:3.6.3'container_name: zoo3hostname: zoo3environment:ZOO_MY_ID: 3ZOO_SERVERS: server.1=zoo1:2888:3888;2181 server.2=zoo2:2888:3888;2181 server.3=0.0.0.0:2888:3888;2181ALLOW_ANONYMOUS_LOGIN: "yes"networks:- zk-netports:- 2183:2181- 8083:8080volumes:- /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
启动成功:
指定配置文件停止
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-netservices:kafka01:image: 'bitnami/kafka:2.7.0'restart: always container_name: kafka01hostname: kafka01ports:- '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=yesvolumes:- /D/soft/docker/kafka/kafka1:/bitnami/kafka networks:- zk-netkafka02:image: 'bitnami/kafka:2.7.0'restart: always container_name: kafka02hostname: kafka02ports:- '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=yesvolumes:- /D/soft/docker/kafka/kafka2:/bitnami/kafka networks:- zk-netkafka03:image: 'bitnami/kafka:2.7.0'restart: always container_name: kafka03hostname: kafka03ports:- '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=yesvolumes:- /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