CentOS下使用Docker实现Zookeeper集群部署

环境

    1.三台虚拟机(192.168.5.29,192.168.5.20,192.168.5.21)

    2.安装docker、docker-compose、拉取镜像zookeeper

#安装docker
yum -y install docker
#启用docker
systemtcl start docker
#与systemtcl start docker 作用相同
service docker start

#拉取zookeeper镜像
docker pull zookeeper

#安装pip环境
yum -y install epel-release
yum -y install python-pip
#安装docker-compose
pip install docker-compose

#集群下关闭防火墙,或者开放端口2888,3888
systemctl stop firewalld

单机部署

#创建zookeeper文件夹 
mkdir zookeeper

#进入zookeeper目录
cd zookeeper


#创建Dockerfile文件
touch Dockerfile

#编写Dockerfile文件
vi Dockerfile

######### Dockerfile ##########
FROM zookeeper:latest
EXPOSE 2181
EXPOSE 2888
EXPOSE 3888
EXPOSE 8080
###############################


#创建conf文件夹
mkdir conf
#创建zoo.cfg文件
touch conf/zoo.cfg
#编写zoo.cfg文件
vi conf/zoo.cfg

######### zoo.cfg #############
dataDir=/data
dataLogDir=/datalog
clientPort=2181
4lw.commands.whitelist=*
tickTime=2000
initLimit=5
syncLimit=2
autopurge.snapRetainCount=3
autopurge.purgeInterval=0
maxClientCnxns=60
standaloneEnabled=true
admin.enableServer=true
################################

#创建docker-compose.yml
touch docker-compose.yml
#编写docker-compose.yml
vi docker-compose.yml

######### docker-compose.yml ########
version: '3.6'
services:
  zookeeper:
    image: zookeeper:latest
    restart: always
    container_name: zookeeper
    ports:
      - "2181:2181"
      - "2888:2888"
      - "3888:3888"
      - "28080:8080"
    volumes: 
      - "./data:/data"
      - "./datalog:/datalog"
      - "./logs:/logs"

######################################

#当前目录情况

####->zookeeper
  ####->conf
    ####--> zoo.cfg
  ####->Dockerfile
  ####->docker-compose.yml

#进入 zookeeper目录
#执行以下语句
docker-compose build
docker-compose up -d --force-recreate
docker-compose restart

#检查docker运行情况
docker ps

#查看日志
docker logs --tail="500" zookeeper

#进入容器
docker exec -it zookeeper /bin/bash

#检查容器状态
docker exec -it zookeeper1 /bin/bash ./bin/zkServer.sh status

集群部署

#server1,server2,server3 各自创建
#创建zookeeper目录
mkdir zookeeper

#进入zookeeper目录
cd zookeeper


#创建Dockerfile文件
touch Dockerfile

#编写Dockerfile文件
vi Dockerfile

######### Dockerfile ##########
FROM zookeeper:latest
EXPOSE 2181
EXPOSE 2888
EXPOSE 3888
EXPOSE 8080
###############################


#创建conf文件夹
mkdir conf
#创建zoo.cfg文件
touch conf/zoo.cfg
#编写zoo.cfg文件
vi conf/zoo.cfg

######### Dockerfile ##########
dataDir=/data
dataLogDir=/datalog
clientPort=2181
4lw.commands.whitelist=*
tickTime=2000
initLimit=5
syncLimit=2
autopurge.snapRetainCount=3
autopurge.purgeInterval=0
maxClientCnxns=60
admin.enableServer=true
#机器1
server.1=192.168.5.29:2888:3888
#机器2
server.2=192.168.5.20:2888:3888
#机器3
server.3=192.168.5.21:2888:3888

###############################


#创建docker-compose.yml
touch docker-compose.yml
#编写docker-compose.yml
vi docker-compose.yml

######### docker-compose.yml ########
version: '3.6'
services:
  zookeeper:
    image: zookeeper:3.4.12
    restart: always
    container_name: zookeeper
    privileged: true
    network_mode: "host"
    ports:
      - "2181:2181"
      - "2888:2888"
      - "3888:3888"
      - "28080:8080"
    environment:
      #### !!! 特别注意 !!! ####
      #### 这里是机器编号 对应下面ZOO_SERVERS,记得修改 ####
      ZOO_MY_ID: 1 
      #########################
      #### 主机ip可以改为0.0.0.0 ####
      ZOO_SERVERS: server.1=192.168.5.29:2888:3888 server.2=192.168.5.20:2888:3888 server.3=192.168.5.21:2888:3888
    volumes: 
      - "./conf/zoo.cfg:/conf/zoo.cfg"
      - "./data:/data"
      - "./datalog:/datalog"
      - "./logs:/logs"

#####################################

#当前各个主机目录情况

####->zookeeper
  ####->conf
    ####--> zoo.cfg
  ####->Dockerfile
  ####->docker-compose.yml

#进入 zookeeper目录
#各个主机分别执行以下语句
docker-compose build
docker-compose up -d --force-recreate
docker-compose restart

#检查docker运行情况
docker ps

#查看日志
docker logs --tail="500" zookeeper

#进入容器
docker exec -it zookeeper /bin/bash

#检查容器状态
docker exec -it zookeeper1 /bin/bash ./bin/zkServer.sh status

 

你可能感兴趣的:(Spring,boot)