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
发布了13 篇原创文章 · 获赞 11 · 访问量 1万+

猜你喜欢

转载自blog.csdn.net/weixin_40908734/article/details/102810994
今日推荐