使用docker搭建zookeeper集群

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/cuisongliu/article/details/51817203

使用docker搭建zookeeper集群

ZooKeeper是一个分布式的,开放源码的分布式应用程序协调服务,是Google的Chubby一个开源的实现,是Hadoop和Hbase的重要组件。它是一个为分布式应用提供一致性服务的软件,提供的功能包括:配置维护、域名服务、分布式同步、组服务等。

  • docker下zookeeper镜像构建
  • 配置集群zookeeper的网络设置
  • 配置集群zookeeper的公共配置
  • docker-compose的zookeeper集群配置

docker下zookeeper镜像构建

  • 去git clone源码构建自定义镜像

    git clone https://gogs.cuisongliu.com/docker-library/zookeeper.git
  • 构建zookeerper的自定义镜像,需要修改基础镜像(只要是jdk 环境即可)

    
    cd zookeeper
    docker build -t jerry/zookeeper:latest . 

配置集群zookeeper的网络设置

docker network 设置

docker network create zoo

配置集群zookeeper的公共配置

配置zoo.cfg 配置文件

tickTime=2000
initLimit=10
syncLimit=5
dataDir=/opt/data
clientPort=2181
dataLogDir=/opt/log
server.1=zk1:2888:3888
server.2=zk2:2888:3888
server.3=zk3:2888:3888
server.4=zk4:2888:3888
server.5=zk5:2888:3888
server.6=zk6:2888:3888
  • dataDir :zookeeper的数据目录
  • clientPort: 外部访问端口
  • dataLogDir: zookeeper的日志目录
  • server.1=zk1:2888:3888 : 节点端口之间通信

docker-compose的zookeeper集群配置

docker-compose.yml:

zoo1:
   image: jerry/zookeeper:latest
   restart: always
   net: zoo
   container_name: zk1
   volumes:
      - /mnt/data/zoo1:/opt/data
      - /mnt/logs/zoo1:/opt/log
      - /mnt/docker-project/zookeeper/zoo:/opt/zookeeper/conf
   ports:
      - "2181:2181"
   expose:
      - "2888"
      - "3888"   
zoo2:
   image: jerry/zookeeper:latest
   restart: always
   net: zoo
   container_name: zk2
   volumes:
      - /mnt/data/zoo2:/opt/data
      - /mnt/logs/zoo2:/opt/log
      - /mnt/docker-project/zookeeper/zoo:/opt/zookeeper/conf
   ports:
      - "2182:2181"
   expose:
      - "2888"
      - "3888"   
zoo3:
   image: jerry/zookeeper:latest
   restart: always
   container_name: zk3
   net: zoo
   volumes:
      - /mnt/data/zoo3:/opt/data
      - /mnt/logs/zoo3:/opt/log
      - /mnt/docker-project/zookeeper/zoo:/opt/zookeeper/conf
   ports:
      - "2183:2181"
   expose:
      - "2888"
      - "3888" 
zoo4:
   image: jerry/zookeeper:latest
   restart: always
   container_name: zk4
   net: zoo
   volumes:
      - /mnt/data/zoo4:/opt/data
      - /mnt/logs/zoo4:/opt/log
      - /mnt/docker-project/zookeeper/zoo:/opt/zookeeper/conf
   ports:
      - "2184:2181"
   expose:
      - "2888"
      - "3888" 
zoo5:
   image: jerry/zookeeper:latest
   restart: always
   container_name: zk5
   net: zoo
   volumes:
      - /mnt/data/zoo5:/opt/data
      - /mnt/logs/zoo5:/opt/log
      - /mnt/docker-project/zookeeper/zoo:/opt/zookeeper/conf
   ports:
      - "2185:2181"
   expose:
      - "2888"
      - "3888" 
zoo6:
   image: jerry/zookeeper:latest
   restart: always
   container_name: zk6
   net: zoo
   volumes:
      - /mnt/data/zoo6:/opt/data
      - /mnt/logs/zoo6:/opt/log
      - /mnt/docker-project/zookeeper/zoo:/opt/zookeeper/conf
   ports:
      - "2186:2181"
   expose:
      - "2888"
      - "3888" 
  • net 设置之前的zoo 网络
  • container_name:当前容器名称,设置名称好做集群。
docker-compose up -d 

ps: 在zoo.cfg文件中定义的server机器上都创建dataDir和dataLogDir定义的目录,同时在dataDi目录下创建myid文件,该文件的内容根据server定义的不同而不同,如server.1 该文件的内容是1,server.2 该文件内容是 2,以此类推.

阅读更多

没有更多推荐了,返回首页