1. 程式人生 > >zookeeper偽分佈安裝和使用

zookeeper偽分佈安裝和使用

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程序

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]

PS:這是年前最後一篇文章,在此給大家拜個早年了,祝大家前程似錦,錦上添花,花中有喜,喜在眉梢;也祝家人身體健康,萬事如意,長命百歲。