zookeeper集群搭建
一、zookeeper的集群组成
zookeeper一般是由 2n+1台服务器组成;
原因:由于zookeeper里面有一个投票选举机制,要半数通过才能正常使用某些功能,所以集群机器只能为基数个
二、zookeeper集群中分为3种角色(leader、foller、observer)
leader
leader是zookeeper集群的核心。
1.事务请求的唯一调度者和处理者,保证集群事务处理的顺序性
2.集群内部各个服务器的调度者
follower
1.处理客户端非事务请求,以及转发事务请求给leader服务器
2.参与事务请求提议(proposal)的投票(客户端的一个事务请求,需要半数服务器投票通过以后才能通知leader commit; leader会发起一个提案,要求follower投票)
3.参与leader选举的投票
observer
观察zookeeper集群中最新状态的变化并将这些状态同步到observer服务器上
增加observer不影响集群中事务处理能力,同时还能提升集群的非事务处理能力
三、zookeeper集群搭建
linux系统zookeeper路径:/learn/zookeeper/zookeeper-3.4.10
linux系统zookeeper日志路径:dataDir=/learn/zookeeperLog
1、修改zookeeper-3.4.10/conf/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=/learn/zookeeperLog
# 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.194.128:2188:3181
server.2=192.168.194.129:2188:3181
server.3=192.168.194.130:2188:3181
server.4=192.168.194.131:2188:3181:observer
1.1、zoo.cfg配置中增加4台服务器配置
1.2、dataDir=/learn/zookeeperLog目录下去建立一个myid文件,里面按照对应机器写入1、2、3、4
如:192.168.194.128机器myid文件中写入1
192.168.194.129机器myid文件中写入2
2、切换到/learn/zookeeper/zookeeper-3.4.10/bin目录下,使用./zkServer.sh start命令启动所有服务器
3、使用tail -f zookeeper.out查看启动日志
4、使用./zkServer.sh status查看服务器是leader还是follower
启动成功不报错集群就算搭建完成
操作过程中错误信息:
解决方案:需要关闭防火墙,命令systemctl stop firewalld,关闭后重新启动zookeeper服务