linux下zookeeper集群部署

1.zookeeper介绍

对于zookeeper集群,一般配置为2n+1个,其中n > 0。Zookeeper 集群保证当一个节点宕机时,其他节点会继续提供服务。如果是一个 Follower 宕机,还有 2 台服务器提供访问,因为 Zookeeper 上的数据是有多个副本的,数据并不会丢失; 如果是一个 Leader 宕机,Zookeeper 会选举出新的 Leader。 ZK 集群的机制是只要超过半数的节点正常,集群就能正常提供服务。只有在ZK节点挂得太多,只剩一半或不到一半节点能工作,集群才失效。

2.zookeeper安装

1.在安装zookeeper时首先要安装jdk

对于jdk的安装可参考https://blog.csdn.net/u010689849/article/details/100146830?spm=1001.2014.3001.5501

2.下载zookeeper并进行解压

tar -zxvf zookeeper-3.4.6.tar.gz

结果如下:

进入目录:cd zookeeper-3.4.6

结构如下:

bin里面会有相应的指令:

其中zkServer.sh为服务端指令,zkCli.sh为客户端指令

3.配置和启动

进入zookeeper中config目录

其中zoo_sample.cfg为配置模板

复制配置模板:cp zoo_sample.cfg zoo.cfg

编辑zoo.cfg文件:

tickTime为心跳值,用来检测服务中leader和follower,客户端和服务端的通信,默认为2000毫秒检测一次

initLimit为初始化值,默认为10次,当有一个follower连接一个leader主节点时,可以忍耐一个10 * 2000mm的延迟

syncLimit为同步的超时时间,默认为5,即同步时间超过5次 * tickTime时,则为超时。

dataDir为持久化路径,即将相关数据放在配置文件

clientPort为客户端连接端口号,默认为2181

maxClientCnxns为客户端最大连接数,这个参数为选配

配置节点

server.1=ip01:2888:3888
server.2=ip02:2888:3888
server.3=ip03:2888:3888

其中3888为第一次启动当无leader时,会通过3888建立连接进行投票选举出leader。leader选出来后会启动2888,然后进行通信。

配置如下:

# 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/zookeeper/zookeeper-3.4.6
# 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=192.168.94.134:2888:3888
server.2=192.168.94.140:2888:3888
server.3=192.168.94.141:2888:3888
#server.4=192.168.94.139:2888:3888

然后进入dataDir所指定的目录vim myid,写上当前zookeeper的id号(集群为三台,则分别为1,2,3)

进入bin目录执行zkServer.sh

其中start为后台启动,即守护式线程启动,而start-foreground为前台启动,执行zkServer.sh start-foreground日志会直接打印。

执行zkServer.sh start-foreground结果如下:

当启动了服务器2和服务器3时:

分别在服务器1,2,3执行zkServer.sh status

可以看到

其中一个为leader,而剩下的为follower

 

  • 2
    点赞
  • 8
    收藏
    觉得还不错? 一键收藏
  • 10
    评论
评论 10
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值