ZooKeeper官方网站: http://zookeeper.apache.org/
" ZooKeeper: A Distributed Coordination Service for Distributed Applications
ZooKeeper is a distributed, open-source coordination service for distributed applications. It exposes a simple set of primitives that distributed applications can build upon to implement higher level services for synchronization, configuration maintenance, and groups and naming. It is designed to be easy to program to, and uses a data model styled after the familiar directory tree structure of file systems. It runs in Java and has bindings for both Java and C. "
ZooKeeper 是一个分布式的,开源的协作服务,可应用于分布式应用程序。它发布了一组简单的原子操作,分布式应用程序在此基础之上可以实现更高层次的服务,如同步、配置维护、群组和命名管理 等。它设计为易于编程,并且使用了一个类似于文件系统的目录结构风格的数据模型。它(ZooKeeper service)运行于Java环境中并且(ZooKeeper client)可绑定于Java和C.
ZooKeeper 是一个用于对分布式系统进行协作管理的服务程序,它本身也是分布式的,所以不要弄混了。对于我们自己的分布式系统来说,ZooKeeper就是一个用来管理的应用程序(或者说服务)。ZooKeeper提供了一个简单易用的框架,由Service和Client两大部分组成。
ZooKeeper的Service由若干运行的Server组成(1个或多个),这些Server完全相同(除了可以部署在不同的机器上),每个Server都维护着相同的数据结构(类似于文件目录结构),这个树形结构中的节点叫znode,Server之间会自动同步数据。
ZooKeeper的Client端可以连接到Service,每个Client对象可以连接到一个指定(或自动分配)的Server,用户通过client可以在Server中创建并维护数据。因为不同的Server维护的是同一份数据的复制,所以,不同的client使用者之间,通过ZooKeeper Service,就可以达到共享数据(信息)的目的。ZooKeeper还提供了Watch的功能,当一个client改变了znode中的数据,所有的client都可以得到通知。ZooKeeper提供了Java和C语言的客户端。
对于ZooKeeper的使用者来说,只需要运行Service,并且知道client的操作方法就可以了。在我们自己的分布式系统中,每个节点通过创建ZooKeeper client,就可以利用ZooKeeper service来同步,共享数据,或者实现更复杂的功能了。
ZooKeeper的C语言客户端使用起来不是很方便,我们可以用C++将C client library进行封装,应用到我们的C++分布式应用程序当中。