基本的术语:
1、Architecture(架构)
2、Hierarchical namespace(层次命名空间)
3、Session(会话)
4、Watches(监视)
5、zookeeper CLI 命令行界面,要执行ZooKeeper CLI操作,首先打开ZooKeeper服务器(“bin/zkServer.sh start”),然后打开ZooKeeper客户端(“bin/zkCli.sh”)。一旦客户端启动,你可以执行以下操作:
1、创建znode
2、获取数据
3、监视znode的变化
4、设置数据
5、创建znode的子节点
6、列出znode的子节点
7、检查状态
8、移除/删除znode
基本理论
https://www.cnblogs.com/sunddenly/category/620563.html
架构:
https://www.cnblogs.com/ChrisMurphy/p/6683397.html
zookeeper搭建:https://www.cnblogs.com/wuxl360/p/5817489.html
搭建要求:
(1) zk服务器集群规模不小于3个节点
(2) 要求各服务器之间系统时间要保持一致。
创建myid
在dataDir(/data/zookeeper/data)目录创建myid文件(dataDir是用来存储内存中数据库快照的位置,应该谨慎的选择日志存放的位置,使用专用的日志存储设备能够大大提高系统的性能,如果将日志存储在比较繁忙的存储设备上,那么将会很大程度上影像系统性能)
Server0机器的内容为:0
Server1机器的内容为:1
Server2机器的内容为:2
编写配置文件
在conf目录下删除zoo_sample.cfg文件,创建一个配置文件zoo.cfg,如下所示,代码清单 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.
dataDir=/usr/local/zk/data
# the port at which the clients will connect
clientPort=2183
#the location of the log file
dataLogDir=/usr/local/zk/log
server.0=10.1.2.133:2888:3888
server.1=10.1.2.134:2888:3888
server.2=10.1.2.135:2888:3888
启动
分别在3台机器上启动ZooKeeper的Server:zkServer.sh start;
kafka在zookeeper中元数据的管理
https://blog.csdn.net/m0_38003171/article/details/80503290
服务器具有四种状态,分别是LOOKING、FOLLOWING、LEADING、OBSERVING。
LOOKING:寻找Leader状态。当服务器处于该状态时,它会认为当前集群中没有Leader,因此需要进入Leader选举状态。
FOLLOWING:跟随者状态。表明当前服务器角色是Follower。
LEADING:领导者状态。表明当前服务器角色是Leader。
OBSERVING:观察者状态。表明当前服务器角色是Observer。
Leader 选举