(分布式协调)通过分布式协调组件多节点顺序一致性,简单来说zookeeper=文件系统+监听通知机制
Google Chubby(不开源产品)
解决分布式一致性
sh zkServer.sh start
集群的角色:leader、follower、observer
整个集群中的调度节点
数据的同步
高可用特性
参与投票(leader选举的投票,数据达成一致的投票)
过半提交(集群节点过多会影响整个集群性能的数据同步)
处理客户端请求(提升集群性能)
不需要参与投票
参与数据的同步
2N+1台组成(过半提交决策)大于过半
observer
修改配置文件zoo.cfg,原配置文件,添加集群节点配置
$dataDir/myid 添加一个Myid文件
?
/home/program/zookeeper-3.4.14/data
?
如果需要增加observer节点
同时在zoo.cfg中增加;peerType=observer
Server.1=192.168.11.129:2888:3181
Server.2=192.168.11.135:2888:3181
Server.3=192.168.11.136:2888:3181:observer
?
# The number of milliseconds of each tick
# 这个时间是作为 Zookeeper 服务器之间或客户端与服务器之间维持心跳的时间间隔,也就是每个 tickTime 时间就会发送一个心跳。
2 tickTime=2000
3 # The number of ticks that the initial
4 # synchronization phase can take
5 initLimit=10
6 # The number of ticks that can pass between
7 # sending a request and getting an acknowledgement
# 这个配置项标识 Leader 与 Follower 之间发送消息,请求和应答时间长度,最长不能超过多少个 tickTime 的时间长度,总的时间长度就是 5*2000=10秒
8 syncLimit=5
9 # the directory where the snapshot is stored.
10 # do not use /tmp for storage, /tmp here is just
11 # example sakes.
# 顾名思义就是 Zookeeper 保存数据的目录,默认情况下,Zookeeper 将写数据的日志文件也保存在这个目录里。
12 dataDir=/home/program/zookeeper-3.4.14/data
13 # the port at which the clients will connect
# 这个端口就是客户端连接 Zookeeper 服务器的端口,Zookeeper 会监听这个端口,接受客户端的访问请求。
14 clientPort=2181
15 # the maximum number of client connections.
16 # increase this if you need to handle more clients
17 #maxClientCnxns=60
18 #
19 # Be sure to read the maintenance section of the
20 # administrator guide before turning on autopurge.
21 #
22 # http://zookeeper.apache.org/doc/current/zookeeperAdmin.html#sc_maintenance
23 #
24 # The number of snapshots to retain in dataDir
25 #autopurge.snapRetainCount=3
26 # Purge task interval in hours
27 # Set to "0" to disable auto purge feature
28 #autopurge.purgeInterval=1
29 server.1=192.168.1.102:2888:3181:observer
30 server.2=192.168.1.115:2888:3181
31 server.3=192.168.1.106:2888:3181