Zookeeper基础知识学习

[size=x-large][b]简介[/b][/size]

[color=red][b]ZooKeeper是Hadoop的正式子项目,它是一个针对大型分布式系统的可靠协调系统[/b][/color],提供的功能包括:[color=blue][b]配置维护[/b][/color]、[color=red][b]命名服务[/b][/color]、[color=darkred]分布式同步[/color]、[color=orange]组服务[/color]等。[b]ZooKeeper的目标就是封装好复杂易出错的关键服务,将简单易用的接口和性能高效、功能稳定的系统提供给用户。[/b]
Zookeeper是Google的Chubby一个开源的实现,[color=red][b]是高有效和可靠的协同工作系统[/b][/color],Zookeeper能够用来leader选举,配置信息维护等,[color=red][b]在一个分布式的环境中,需要一个Master实例或存储一些配置信息,确保文件写入的一致性等。[/b][/color]
[color=red][b]ZooKeeper是一个分布式的,开放源码的分布式应用程序协调服务[/b][/color],包含一个简单的原语集,是Hadoop和Hbase的重要组件。 提供Java和C的接口。

Zookeeper 作为一个分布式的服务框架,[b]主要用来解决分布式集群中应用系统的一致性问题[/b],它能提供基于类似于文件系统的目录节点树方式的数据存储,[size=medium][color=red][b]但是 Zookeeper 并不是用来专门存储数据的,它的作用主要是用来维护和监控你存储的数据的状态变化。[/b][/color][/size]通过监控这些数据状态的变化,从而可以达到基于数据的集群管理。

[size=x-large][b]原理[/b][/size]

[color=red][b]ZooKeeper是以Fast Paxos算法为基础的[/b][/color],paxos算法存在活锁的问题,即当有多个proposer交错提交时,有可能互相排斥导致没有一个proposer能提交成功,而Fast Paxos作了一些优化,[b]通过选举产生一个leader,只有leader才能提交propose[/b],具体算法可见Fast Paxos。因此,[b]要想弄懂ZooKeeper首先得对Fast Paxos有所了解。[/b]
[size=large][b]ZooKeeper的基本运转流程:[/b][/size]
[color=red][b]1、选举Leader。[/b][/color]
2、同步数据。
3、选举Leader过程中算法有很多,但要达到的选举标准是一致的。
[color=red][b]4、Leader要具有最高的zxid。[/b][/color]
5、集群中大多数的机器得到响应并follow选出的Leader。

ZooKeeper代码版本中,提供了分布式独享锁、选举、队列的接口,代码在zookeeper-3.4.3\src\recipes。其中分布锁和队列有Java和C两个版本,选举只有Java版本

[size=x-large][b]统一命名空间[/b][/size]
在zookeeper中实现了一个类似file system系统的数据结构,比如/zookeeper/status。 每个节点都对应于一个znode节点。
znode节点的数据结构模型:

[img]http://dl2.iteye.com/upload/attachment/0123/9428/1140b236-dbf6-32ef-96c3-4a250e2c1e2e.jpg[/img]

[color=red][b]znode的数据结构内容:[/b][/color]

[b]czxid[/b]
The zxid of the change that caused this znode to be created.
[b]mzxid[/b]
The zxid of the change that last modified this znode.
[b]ctime[/b]
The time in milliseconds from epoch when this znode was created.
[b]mtime[/b]
The time in milliseconds from epoch when this znode was last modified.
[b]version[/b]
The number of changes to the data of this znode.
[b]cversion[/b]
The number of changes to the children of this znode.
[b]aversion[/b]
The number of changes to the ACL of this znode.
[b]ephemeralOwner[/b]
The session id of the owner of this znode if the znode is an ephemeral node. If it is not an ephemeral node, it will be zero.
[b]dataLength[/b]
The length of the data field of this znode.
[b]numChildren[/b]
The number of children of this znode.

说明: zxid (ZooKeeper Transaction Id,每次请求对应一个唯一的zxid,如果zxid a < zxid b ,则可以保证a一定发生在b之前)。

[size=x-large][b]配置推送(Watcher)[/b][/size]
[color=red][b]zookeeper为解决数据的一致性,使用了Watcher的异步回调接口,将服务端znode的变化以事件的形式通知给客户端,主要是一种反向推送的机制,让客户端可以做出及时响应。[/b][/color]比如及时更新后端的可用集群服务列表。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值