zookeeper 也是apache的顶级项目,所以他的项目官网:http://zookeeper.apache.org/
zookeeper是什么
以下是官网的解释
Apache ZooKeeper is an effort to develop and maintain an open-source server which enables highly reliable distributed coordination.
ZooKeeper is a centralized service for maintaining configuration information, naming, providing distributed synchronization, and providing group services. All of these kinds of services are used in some form or another by distributed applications. Each time they are implemented there is a lot of work that goes into fixing the bugs and race conditions that are inevitable. Because of the difficulty of implementing these kinds of services, applications initially usually skimp on them ,which make them brittle in the presence of change and difficult to manage. Even when done correctly, different implementations of these services lead to management complexity when the applications are deployed.
以下是百度百科的说明
ZooKeeper是一个分布式的,开放源码的分布式应用程序协调服务。是Google的Chubby一个开源的实现,是Hadoop和Hbase的重要组件。它是一个为分布式应用提供一致性服务的软件,提供的功能包括:配置维护、域名服务、分布式同步、组服务等。它是集群的管理者,监视着集群中各个节点的状态根据节点提交的反馈进行下一步合理操作。最终,将简单易用的接口和性能高效、功能稳定的系统提供给用户
刚接触zookeeper,那么先总安装开始说起吧
下载
https://www.apache.org/dyn/closer.cgi/zookeeper/
从这里选择一个镜像下载
我选的这个
是Zookeeper-3.4.12
安装
将刚才下载zookeeper-3.4.12.tar.gz 解压
tar -zxvf zookeeper-3.4.12.tar.gz
移动
mv zookeeper-3.4.12 /usr/local/zookeeper
这个时候,可以打开/usr/local/zookeeper/docs/index.html
或者进入这里http://zookeeper.apache.org/doc/current/index.html,
在页面上点击“Getting Started”,就进入http://zookeeper.apache.org/doc/current/zookeeperStarted.html
这个页面和刚才docs里的文件内容一致
新建data目录
mkdir -p /var/lib/zookeeper/data
这个路径会写入到zoo.cfg文件中
准备配置文件
cd /usr/local/zookeeper/conf
mv zoo_sample.cfg zoo.cfg
vi zoo.cfg
编辑zoo.cfg,GettingStarted中也有相关内容,主要修改以下内容
tickTime=2000
dataDir=/var/lib/zookeeper/data
clientPort=2181
还有一个dataLogDir参数,如果不设置,日志默认使用dataDir的目录
启动zookeeper
cd /usr/local/zookeeper
bin/zkServer.sh start
连接到zookeeper
bin/zkCli.sh -server 127.0.0.1:2181
如果连接成功:
Connecting to localhost:2181
log4j:WARN No appenders could be found for logger (org.apache.zookeeper.ZooKeeper).
log4j:WARN Please initialize the log4j system properly.
Welcome to ZooKeeper!
JLine support is enabled
[zkshell: 0]
输入一个命令,试试
[zkshell: 0] help
ZooKeeper host:port cmd args
get path [watch]
ls path [watch]
set path data [version]
delquota [-n|-b] path
quit
printwatches on|off
createpath data acl
stat path [watch]
listquota path
history
setAcl path acl
getAcl path
sync path
redo cmdno
addauth scheme auth
delete path [version]
setquota -n|-b val path
后面的验证,按照官网文档,增加一个znode,set一个数据,再get一个数据
停止zookeeper
刚才进入到zookeeper 的shell中,输入命令:quit 就退出。
bing/zkServer.sh stop