ZooKeeper单机伪集群搭建

导读:本篇文章讲解 ZooKeeper单机伪集群搭建,希望对大家有帮助,欢迎收藏,转发!站点地址:www.bmabk.com

安装配置请看前文:
Linux系统安装ZooKeeper

开始搭建

cp多个zoo.cfg文件,分别命令为zoo1.cfg、zoo2.cfg、zoo3.cfg
在这里插入图片描述
zoo.cfg

#f 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
dataDir=/usr/local/apache-zookeeper-3.6.1/data-cluster/data1
dataLogDir=/usr/local/apache-zookeeper-3.6.1/log-cluster/log1
# 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=localhost:2287:3387
server.2=localhost:2288:3388
server.3=localhost:2289:3389

zoo2.cfg


#f 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
dataDir=/usr/local/apache-zookeeper-3.6.1/data-cluster/data2
dataLogDir=/usr/local/apache-zookeeper-3.6.1/log-cluster/log2
# 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=localhost:2287:3387
server.2=localhost:2288:3388
server.3=localhost:2289:3389

zoo3.cfg

#f 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
dataDir=/usr/local/apache-zookeeper-3.6.1/data-cluster/data3
dataLogDir=/usr/local/apache-zookeeper-3.6.1/log-cluster/log3
# the port at which the clients will connect
#
clientPort=2183
# 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=localhost:2287:3387
server.2=localhost:2288:3388
server.3=localhost:2289:3389

接着创建对应的data和log文件
在zk安装目录下,创建data-cluster文件夹,里面放data1,data2,data3
在这里插入图片描述
在zk安装目录下,创建log-cluster文件夹,同上
在这里插入图片描述

创建myid

在/usr/local/apache-zookeeper-3.6.1/data-cluster文件夹下有三个data文件,每个data文件夹里都创建myid文件,就叫myid没后缀,然后对应着文件夹的层次写1,2,3;
在这里插入图片描述

这里data2我之前多写了个2,写成了22,启动失败了,按理说只要3个myid不一致就可以了,不知道为什么会失败,然后改成2之后,又成功启动了!

到了这里理论上是可以的,注意杀8080端口的进程

开启启动:

./zkServer.sh start/usr/local/apache-zookeeper-3.6.1/conf/zoo1.cfg 
./zkServer.sh start/usr/local/apache-zookeeper-3.6.1/conf/zoo2.cfg 
./zkServer.sh start/usr/local/apache-zookeeper-3.6.1/conf/zoo3.cfg 

查看状态:

./zkServer.sh status /usr/local/apache-zookeeper-3.6.1/conf/zoo1.cfg 
./zkServer.sh status /usr/local/apache-zookeeper-3.6.1/conf/zoo2.cfg 
./zkServer.sh status /usr/local/apache-zookeeper-3.6.1/conf/zoo3.cfg 

在这里插入图片描述
Mode: follower,从节点模式
在这里插入图片描述
Mode: leader,主节点模式

可能随着后续的拓展,会有补充,欢迎收看,谢谢!

在这里插入图片描述

技术交流群:797156985
jerbrains系列正确打开(你懂得),加群:1093476453,加群请说明原因,可能会被拒!
个人公众号,求求点关注谢谢!
在这里插入图片描述

版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 举报,一经查实,本站将立刻删除。

文章由极客之音整理,本文链接:https://www.bmabk.com/index.php/post/16429.html

(0)
小半的头像小半

相关推荐

极客之音——专业性很强的中文编程技术网站,欢迎收藏到浏览器,订阅我们!