欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

ZooKeeper单机伪集群搭建

程序员文章站 2022-06-21 17:46:27
...

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

开始搭建

cp多个zoo.cfg文件,分别命令为zoo1.cfg、zoo2.cfg、zoo3.cfg
ZooKeeper单机伪集群搭建
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
ZooKeeper单机伪集群搭建
在zk安装目录下,创建log-cluster文件夹,同上
ZooKeeper单机伪集群搭建

创建myid

在/usr/local/apache-zookeeper-3.6.1/data-cluster文件夹下有三个data文件,每个data文件夹里都创建myid文件,就叫myid没后缀,然后对应着文件夹的层次写1,2,3;
ZooKeeper单机伪集群搭建

这里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 

ZooKeeper单机伪集群搭建
Mode: follower,从节点模式
ZooKeeper单机伪集群搭建
Mode: leader,主节点模式

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

ZooKeeper单机伪集群搭建

技术交流群:797156985
jerbrains系列正确打开(你懂得),加群:1093476453,加群请说明原因,可能会被拒!
个人公众号,求求点关注谢谢!
ZooKeeper单机伪集群搭建