1、下载路径为:http://mirrors.cnnic.cn/apache/zookeeper/stable/
2、安装:
第一步 解压zookeeper压缩包:
进入 zookeeper安装目录
第二步 创建一个data目录:
第三步 修改 conf/zoo.cfg文件:
先将zoo_sample.cfg copy 为 zoo.cfg
然后 编辑zoo.cfg文件:
修改后:
第三步 将ZOOKEEPER_HOME加入到.bash_profile环境变量中并使用source使环境变量生效
第三步 启动zookeeper的server:
我们启动zookeeper后,通过jps,可以查看到QuorunPeerMain进程
如果我们想配置集群zookeeper,请查看这个文档:http://zookeeper.apache.org/doc/trunk/zookeeperStarted.html#sc_RunningReplicatedZooKeeper
3、使用:
客户端连接zookeeper server:
help命令:
ls命令:
[zk: 127.0.0.1:2181(CONNECTED) 2] ls /
[zookeeper]
create命令:
[zk: 127.0.0.1:2181(CONNECTED) 5] create /zk_test my_data
Created /zk_test
[zk: 127.0.0.1:2181(CONNECTED) 8] ls /
[zookeeper, zk_test]
get命令:
[zk: 127.0.0.1:2181(CONNECTED) 0] get /zk_test
my_data
cZxid = 0x2
ctime = Fri Feb 06 01:45:04 PST 2015
mZxid = 0x2
mtime = Fri Feb 06 01:45:04 PST 2015
pZxid = 0x2
cversion = 0
dataVersion = 0
aclVersion = 0
ephemeralOwner = 0x0
dataLength = 7
numChildren = 0
[zk: 127.0.0.1:2181(CONNECTED) 1]
修改下zk_test节点数据:
[zk: 127.0.0.1:2181(CONNECTED) 15] set /zk_test summer
cZxid = 0x2
ctime = Fri Feb 06 01:45:04 PST 2015
mZxid = 0x5
mtime = Fri Feb 06 01:49:19 PST 2015
pZxid = 0x2
cversion = 0
dataVersion = 1
aclVersion = 0
ephemeralOwner = 0x0
dataLength = 6
numChildren = 0
[zk: 127.0.0.1:2181(CONNECTED) 16]
再查下:
[zk: 127.0.0.1:2181(CONNECTED) 29] get /zk_test
summer
cZxid = 0x2
ctime = Fri Feb 06 01:45:04 PST 2015
mZxid = 0x5
mtime = Fri Feb 06 01:49:19 PST 2015
pZxid = 0x2
cversion = 0
dataVersion = 1
aclVersion = 0
ephemeralOwner = 0x0
dataLength = 6
numChildren = 0
[zk: 127.0.0.1:2181(CONNECTED) 30]
delete命令:
[zk: 127.0.0.1:2181(CONNECTED) 44] delete /zk_test
再使用get查下该节点:
[zk: 127.0.0.1:2181(CONNECTED) 45] get /zk_test
Node does not exist: /zk_test
[zk: 127.0.0.1:2181(CONNECTED) 46]
更多关于使用操作,请看这篇文档:http://zookeeper.apache.org/doc/trunk/zookeeperProgrammers.html
参考文档1:http://zookeeper.apache.org/doc/trunk/zookeeperStarted.html
参考文档2:http://zookeeper.apache.org/doc/trunk/zookeeperAdmin.html
PS:这是年前最后一篇文章,在此给大家拜个早年了,祝大家前程似锦,锦上添花,花中有喜,喜在眉梢;也祝家人身体健康,万事如意,长命百岁。