Docker分布式部署zookeeper集群

docker分布式部署zookeeper

部署环境

HOST1: centos7 :192.168.51.121
HOST2: centos7 :192.168.51.155
HOST3: centos7 :192.168.51.122
三台机器全部关闭防火墙:

//临时关闭
systemctl stop firewalld
//禁止开机启动
systemctl disable firewalld
Removed symlink /etc/systemd/system/multi-user.target.wants/firewalld.service.
Removed symlink /etc/systemd/system/dbus-org.fedoraproject.FirewallD1.service.

第一种方式

部署

1.安装docker

https://blog.csdn.net/qq_32488647/article/details/81773947

2.部署(每台机器都执行相同的操作)

启动docker

sudo systemctl start docker

拉取镜像

#不指定版本默认拉取latest
sudo docker pull zookeeper

创建容器

#HOST1
sudo docker run -d --name=zookeeper1 --net=host zookeeper
#HOST2
sudo docker run -d --name=zookeeper2 --net=host zookeeper
#HOST3
sudo docker run -d --name=zookeeper3 --net=host zookeeper

修改配置文件

#HOST1:
$sudo docker exec -it zookeeper1 /bin/bash
$vi /conf/zoo.cfg
##改成下面
clientPort=2181
dataDir=/data
dataLogDir=/datalog
tickTime=2000
initLimit=5
syncLimit=2
server.1=192.168.51.121:2888:3888
server.2=192.168.51.155:2888:3888
server.3=192.168.51.122:2888:3888
#修改myid为1
$vi /data/myid

HOST2和HOST3zoo.cfg配置文件都一样,myid分别为2,3

3.验证

#进入服务器命令行
docker exec -it qd-zookeeper2 /bin/bash
#查看zkServer运行状态,Mode为follower或leader
bin/zkServer.sh status

如果出现Mode为standalone则防火墙未关或配置文件有问题zookeeper





第二种方式

第一步拉取镜像:
sudo docker pull jplock/zookeeper
第二步本地创建配置文件夹

#创建文件夹
sudo mkdir /opt/zookeeper
#创建临时容器将配置文件拷贝到宿主机
sudo docker run -tid --name=test jplock/zookeeper
sudo docker cp test:/opt/zookeeper/conf /opt/zookeeper
#删除临时容器
sudo docker rm -f test

第三步修改配置文件
sudo vim /opt/conf/zoo.cfg
修改成如下:

# The number of milliseconds of each tick
tickTime=2000
# The number of ticks that the initial 
# synchronization phase can take
initLimit=10
# The number of ticks that can pass between 
# sending a request and getting an acknowledgement
syncLimit=5
# the directory where the snapshot is stored.
# do not use /tmp for storage, /tmp here is just 
# example sakes.
dataDir=/opt/zookeeper/data
# the port at which the clients will connect
clientPort=2181
# the maximum number of client connections.
# increase this if you need to handle more clients
#maxClientCnxns=60
#
# Be sure to read the maintenance section of the 
# administrator guide before turning on autopurge.
#
# http://zookeeper.apache.org/doc/current/zookeeperAdmin.html#sc_maintenance
#
# The number of snapshots to retain in dataDir
#autopurge.snapRetainCount=3
# Purge task interval in hours
# Set to "0" to disable auto purge feature
#autopurge.purgeInterval=1
#下面是宿主机host
server.1=192.168.51.121:2888:3888
server.2=192.168.51.155:2888:3888
server.3=192.168.51.122:2888:3888

第四步创建容器(每台机器创建时只需要name不一样就可以)

# -v代表将容器的文件夹挂载到宿主机上
sudo docker run -tid --restart=always -p 2181:2181 -p 2888:2888 -p 3888:3888 --net=host -v /opt/zookeeper/data:/opt/zookeeper/data -v /opt/zookeeper/logs:/opt/zookeeper/logs -v /opt/zookeeper/conf:/opt/zookeeper/conf --name=zookeeper1 jplock/zookeeper

上面步骤执行完之后还需要修改myid才能集群
第五步修改myid
sudo vim /opt/data/myid
只需要输入1(对应的第二台宿主机输入2,第三台输入3)
重启容器
sudo docker restart zookeeper1

验证:
echo stat|nc 192.168.51.121

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值