docker在两台服务器上部署zookeeper集群(亲测可用)

假设有A和B两台服务器,在A部署一个zk容器,B部署两个zk容器,一共3个(zk建议最好是奇数)

步骤:

1、在A的服务器中创建zookeeper1的文件夹

mkdir -p ~/docker/zookeeper1
  mkdir ~/docker/zookeeper1/data
  cd ~/docker/zookeeper1
  echo 1 > data/myid

2、在创建zoo.cfg 文件

vim 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=/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
server.1=0.0.0.0:2888:3888
server.2=这里写B的IP地址:2888:3888
server.3=这里写B的IP地址:2889:3889

3、在B的服务器中创建zookeeper2的文件夹

mkdir -p ~/docker/zookeeper2
  mkdir ~/docker/zookeeper2/data
cd ~/docker/zookeeper2
echo 2 > data/myid

4、在创建zoo.cfg 文件

vim 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=/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
server.1=这里写A的地址:2888:3888
server.2=0.0.0.0:2888:3888
server.3=0.0.0.0:2889:3889

5、在B的服务器中创建zookeeper3的文件夹

mkdir -p ~/docker/zookeeper3
  mkdir ~/docker/zookeeper3/data
  cd ~/docker/zookeeper3
  echo 3 > data/myid

6、在创建zoo.cfg 文件

vim 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=/data
# the port at which the clients will connect
clientPort=2182
# 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
server.1=这里写A的地址:2888:3888
server.2=0.0.0.0:2888:3888
server.3=0.0.0.0:2889:3889

7.启动A服务器容器

 cd ~/docker/zookeeper1
 sudo docker run -d --restart=always --name zookeeper1 -p2181:2181 -p2888:2888 -p3888:3888  -v $PWD/zoo.cfg:/conf/zoo.cfg -v $PWD/data:/data zookeeper

8.启动B服务器容器

 cd ~/docker/zookeeper2
 
 sudo docker run -d --restart=always --name zookeeper2 -p2181:2181 -p2888:2888 -p3888:3888  -v $PWD/zoo.cfg:/conf/zoo.cfg -v $PWD/data:/data zookeeper
 
  cd ~/docker/zookeeper2
  
 sudo docker run -d --restart=always --name zookeeper2 -p2182:2182 -p2889:2889 -p3889:3889  -v $PWD/zoo.cfg:/conf/zoo.cfg -v $PWD/data:/data zookeeper
  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值