進入命令行
運行 zkCli.sh –server <ip>進入命令行工具。
[root@zk1 bin]# zkCli.sh -server ? <不加ip地址,連接本地zookeeper>
Error: no argument found for option -server
Connecting to localhost:2181
[zk: localhost:2181(CONNECTED) 0]?
[root@zk1 bin]# zkCli.sh -server zk2 ?< 加ip地址,連接相應的zookeeper>
Connecting to zk2
[zk: zk2(CONNECTED) 0]?
HELP
輸入help查看幫助
[zk: localhost:2181(CONNECTED) 0] help
ZooKeeper -server host:port cmd args
? ? ? ? stat path [watch]
? ? ? ? set path data [version]
? ? ? ? ls path [watch]
? ? ? ? delquota [-n|-b] path
? ? ? ? ls2 path [watch] ?---詳情版ls
? ? ? ? setAcl path acl
? ? ? ? setquota -n|-b val path
? ? ? ? history?
? ? ? ? redo cmdno
? ? ? ? printwatches on|off
? ? ? ? delete path [version]
? ? ? ? sync path
? ? ? ? listquota path
? ? ? ? get path [watch]
? ? ? ? create [-s] [-e] path data acl
? ? ? ? addauth scheme auth
? ? ? ? quit?
? ? ? ? getAcl path
? ? ? ? close?
? ? ? ? connect host:port
操作
zookeeper的節點符合常規的文件系統規范。
ls?
[zk: localhost:2181(CONNECTED) 3] ls /
[zookeeper]
create?
[zk: localhost:2181(CONNECTED) 6] create /testapp1 1111
Created /testapp1
默認節點類型是:PERSISTENT
[zk: localhost:2181(CONNECTED) 7] ls /
[testapp1, zookeeper]
[zk: localhost:2181(CONNECTED) 8] create -s /testapp1 1111
Created /testapp10000000009
[zk: localhost:2181(CONNECTED) 9] ls /
[testapp1, zookeeper, testapp10000000009]
[zk: localhost:2181(CONNECTED) 10]?
進入zk2,zk3 使用ls 命令可以看到zk1的內容已經同步了。
create?EPHEMERAL類型
[zk: localhost:2181(CONNECTED) 4] create -e /app1eeee eeee
Created /app1eeee
[zk: localhost:2181(CONNECTED) 5] ls /
[testapp1, zookeeper, app1eeee, testapp10000000009]
quit退出
在其他節點 ls / 發現app1eeee沒了,退出后就刪了
[zk: localhost:2181(CONNECTED) 2] create -e /app1eeeee/app2eee eeee
Ephemerals cannot have children: /app1eeeee/app2eee
get
[zk: localhost:2181(CONNECTED) 1] get /testapp1
1111 ?<存進去的內容>
cZxid = 0x300000007
ctime = Sun Nov 13 20:57:06 CST 2016
mZxid = 0x300000007
mtime = Sun Nov 13 20:57:06 CST 2016
pZxid = 0x300000007
cversion = 0
dataVersion = 0
aclVersion = 0
ephemeralOwner = 0x0
dataLength = 4
numChildren = 0
set
[zk: localhost:2181(CONNECTED) 2] set /testapp1 2222
cZxid = 0x300000007
ctime = Sun Nov 13 20:57:06 CST 2016
mZxid = 0x30000000a
mtime = Sun Nov 13 21:05:26 CST 2016
pZxid = 0x300000007
cversion = 0
dataVersion = 1
aclVersion = 0
ephemeralOwner = 0x0
dataLength = 4
numChildren = 0
-------------
更多的Java,Angular,Android,大數據,J2EE,Python,數據庫,Linux,Java架構師,:
http://www.cnblogs.com/zengmiaogen/p/7083694.html