之前上上篇说了一下 zookeeper 的搭建及简单使用(见:https://blog.csdn.net/a15835774652/article/details/80620038)今天也搭建了下 zookeeper伪集群 记录下

为什么叫伪集群

    个人理解 正常的集群应该是2n+1台服务器进行交互  伪集群 是在一个 台机器上 启动不同端口的实例达到集群的目的 所以称为伪集群了吧

 步骤和搭建单个zookeeper差不多 之前只有 现在有2n+1个 这里选用3个

我的服务器上开发目录下文件

1.新建文件夹 zookeeper-clusters

zookeeper伪集群搭建

2将之前解压好的 zookeeper-3.4.12 复制到 zookeeper-clusters下

zookeeper伪集群搭建

3个文件夹 zookeeper-server1  zookeeper-server2  zookeeper-server3 

仅仅复制文件 而不赋值文件夹  格式 cp -Rf 原路径/ 目的路径/

在develope 目录下分别执行 命令  cp -Rf ./zookeeper-3.4.12  /usr/local/develope/zookeeper-clusters/zookeeper-server1

cp -Rf ./zookeeper-3.4.12  /usr/local/develope/zookeeper-clusters/zookeeper-server2

cp -Rf ./zookeeper-3.4.12  /usr/local/develope/zookeeper-clusters/zookeeper-server3

集群配置1.分别修改这3个目录下  zoo.cfg配置文件

 这里 贴出 这3个文件 的配置 (分别设置3个不同端口  来启动)

zookeeper-server1配置 

(注意修改复制后的 data目录 log目录  )

# 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=/usr/local/develope/zookeeper-clusters/zookeeper-server1/data
#log dir 
dataLogDir=/usr/local/develope/zookeeper-clusters/zookeeper-server1/logs
# 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:2888:3888
server.2=localhost:2889:3889

server.3=localhost:2890:3890

zookeeper-server2配置 

(注意修改复制后的 data目录 log目录  )

# 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=/usr/local/develope/zookeeper-clusters/zookeeper-server2/data
#log dir 
dataLogDir=/usr/local/develope/zookeeper-clusters/zookeeper-server2/logs
# 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:2888:3888
server.2=localhost:2889:3889

server.3=localhost:2890:3890

zookeeper-server3配置 

(注意修改复制后的 data目录 log目录  )
# 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=/usr/local/develope/zookeeper-clusters/zookeeper-server3/data
#log dir 
dataLogDir=/usr/local/develope/zookeeper-clusters/zookeeper-server3/logs
# 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:2888:3888
server.2=localhost:2889:3889

server.3=localhost:2890:3890

集群配置2.在zookeeper-server1,zookeeper-server2,zookeeper-server3创建data ,logs 目录 并在data目录下添加 myid文件

echo "1" > /usr/local/develope/zookeeper-clusters/zookeeper-server1/data/myid

echo "2" > /usr/local/develope/zookeeper-clusters/zookeeper-server2/data/myid

echo "3" > /usr/local/develope/zookeeper-clusters/zookeeper-server3/data/myid


集群配置3.逐个启动zookeeper-server

   都启动成功后 在3个集群任何一个 bin目录下 启动 客户端 测试连接

zookeeper伪集群搭建

如图连接ok 

在看下每个 zookeeper服务的状态

zookeeper伪集群搭建

如图 有一个leader 2个follerer 搭建成功 

基本使用见上上篇文章 zookeeper搭建及基本使用

相关文章:

  • 2021-06-12
  • 2021-07-05
  • 2021-09-11
  • 2021-12-17
  • 2021-08-25
  • 2021-04-02
  • 2021-08-08
猜你喜欢
  • 2021-11-17
  • 2021-11-08
  • 2022-01-06
  • 2021-12-30
  • 2021-07-06
相关资源
相似解决方案