ZooKeeper 学习笔记1

239 阅读2分钟

image.png

ZK类似文件系统,但是其不同之处在于:为客户端提供高吞吐、低延迟、高可用、严格有序访问znode的方式。ZK的优越性能允许其应用在大型分布式系统里。 ZK提供的命名空间很像标准的文件系统,使用“/” 作为路径分隔符,父类则在“/”的前缀。需要注意根目录不存在父类路径。ZK与标准文件系统的主要区别:每个znode都可以有与之关联的数据,并且znode受限制与数据量大小。

从ZK的设计出发,其旨在存储协调数据:状态信息、配置、位置信息等等。所以其存储的数据一般以比特或是千比特为单位,系统本身也提供1M容量的检测机制,避免被用于作为大型数据库使用。其数据是存储在内存中,这也进一步限制其存储数据的容量大小。

client客户端通过访问单个ZK server即可实现连接,client通过维护TCP连接实现(发生请求、接收响应、获取监视事件、发送心跳)。如果TCP连接中断,client可以连接至其他ZK server服务器。client首次连接server时,服务器会为client设置会话。当client连接新的ZK server服务器,服务端会建立新的会话设置。

读写的特性:读请求在ZK server 的本地即可完成处理。写请求需要进行信息同步后,zk server才会返回响应。因此,读请求的吞吐量随着服务器数量的增加而增加,写请求的吞吐量随着服务器数据的增加而减少

排序特性对ZK非常重要,所有的更新都是有序的。通过标记zxid(ZooKeeper transaction id)按顺序更新每一个记录。每个zxid唯一的。包括读写和监视也是顺序的。

ZK的集群版本建议的节点数量最少在5个以上。 在进行滚动升级时,即使出现单个节点的意外故障。也能保证ZK集群的正常运行。

一些有用的工具
-   [zkconf](http://bit.ly/mBEcF) - generate configuration for a ZooKeeper ensemble
-   [zk-smoketest](http://bit.ly/2Cs6Ee) - smoketest or latencytest a ZooKeeper ensemble (uses zkpython)
-   [zookeeper_dashboard](http://bit.ly/1kjQy0) - web dashboard for ZooKeeper ensemble (uses zkpython & django)
-   [zktop](http://bit.ly/1iMZdg) - monitor ZooKeeper in realtime
-   [zkexamples](http://bit.ly/43Emx3) - phunt's "random examples of useful bits of ZooKeeper ephemera"
-   [SPM for ZooKeeper](http://sematext.com/spm) - Performance Monitoring and Alerting for ZooKeeper

列举用到ZK的应用程序 
-   [Mesos](http://www.mesosproject.org/) Mesos is a cluster management platform that provides resource sharing and isolation across distributed applications, or frameworks. For example, Hadoop MapReduce, MPI, Hypertable, and Spark
-   [Apache Hadoop MapReduce](http://hadoop.apache.org/mapreduce) The next generation of Hadoop MapReduce (colled "Yarn") uses ZooKeeper. [Jira issue](https://issues.apache.org/jira/browse/MAPREDUCE-279), [Design paper](https://issues.apache.org/jira/secure/attachment/12486023/MapReduce_NextGen_Architecture.pdf)
-   [Apache HBase](http://hadoop.apache.org/hbase/) - HBase is the Hadoop database. Its an open-source, distributed, column-oriented store modeled after the Google paper, Bigtable: A Distributed Storage System for Structured Data by Chang et al.\
We use ZooKeeper for master election, server lease management, bootstrapping, and coordination between servers.
-   [Apache Kafka (incubating)](http://incubator.apache.org/kafka/) Kafka is a distributed publish/subscribe messaging system