zookeeper(2)-operation command

zookeeper(2)-operation command

ls

ls path to view a list of directories under a certain path, ls/to view a zookeeper directory under the root directory. A directory is a node./The root node zookeeper is a child node

[zk: localhost:2181(CONNECTED) 1] ls/
[zookeeper]

stat

View node status information.

[zk: localhost:2181(CONNECTED) 9] stat/
cZxid = 0x0
ctime = Thu Jan 01 08:00:00 CST 1970
mZxid = 0x0
mtime = Thu Jan 01 08:00:00 CST 1970
pZxid = 0x0
cversion = -1
dataVersion = 0
aclVersion = 0
ephemeralOwner = 0x0
dataLength = 0
numChildren = 1

cZxid Zookeeper Id assigned to the node cTime node creation time mZxid modified id mtime modification time pZxid child node id cversion child node version dataVersion current node data version number aclVersion permission Version dataLength data length numChildren number of child nodes

ls2

ls2 shows some status information of the data is a combination of ls and stat commands

[zk: localhost:2181(CONNECTED) 7] ls2/
[zookeeper]
cZxid = 0x0
ctime = Thu Jan 01 08:00:00 CST 1970
mZxid = 0x0
mtime = Thu Jan 01 08:00:00 CST 1970
pZxid = 0x0
cversion = -1
dataVersion = 0
aclVersion = 0
ephemeralOwner = 0x0
dataLength = 0
numChildren = 1

create

create/test testdata
Created/test

Create a temporary node

[zk: localhost:2181(CONNECTED) 12] create -e/test/tmp tmpdata
Created/test/tmp

Create sequence node

[zk: localhost:2181(CONNECTED) 4] create -s/test/sec sequencer
Created/test/sec0000000001

get

get path to get node data information

get/test
testdata
cZxid = 0x2
ctime = Wed May 08 17:28:06 CST 2019
mZxid = 0x2
mtime = Wed May 08 17:28:06 CST 2019
pZxid = 0x2
cversion = 0
dataVersion = 0
aclVersion = 0
ephemeralOwner = 0x0
dataLength = 8
numChildren = 0

set

Modify node value

[zk: localhost:2181(CONNECTED) 5] set/test newdata
cZxid = 0x2
ctime = Wed May 08 17:28:06 CST 2019
mZxid = 0x7
mtime = Wed May 08 17:59:07 CST 2019
pZxid = 0x6
cversion = 3
dataVersion = 1
aclVersion = 0
ephemeralOwner = 0x0
dataLength = 7
numChildren = 1

If the node does not exist or the modification fails

[zk: localhost:2181(CONNECTED) 7] set/test1 newdata1
Node does not exist:/test1

Optimistic lock modification set pata data dataversion

[zk: localhost:2181(CONNECTED) 8] set/test new-data 1
cZxid = 0x2
ctime = Wed May 08 17:28:06 CST 2019
mZxid = 0x9
mtime = Wed May 08 18:02:29 CST 2019
pZxid = 0x6
cversion = 3
dataVersion = 2
aclVersion = 0
ephemeralOwner = 0x0
dataLength = 8
numChildren = 1
[zk: localhost:2181(CONNECTED) 9] set/test new-data 1
version No is not valid:/test

delete

Delete node

[zk: localhost:2181(CONNECTED) 23] delete/test0000000001
[zk: localhost:2181(CONNECTED) 24] delete/test0000000001
Node does not exist:/test0000000001

4.letter Words

Zk can interact with the server to install the nc command command format echo [commond] | nc [ip] [port] stat to view the status information of zk and whether it is mode

baxiangs-Mac-mini:~ baxiang$ echo stat | nc localhost 2181
Zookeeper version: 3.4.12-e5259e437540f349646870ea94dc2658c4e44b3b, built on 03/27/2018 03:55 GMT
Clients:
/0:0:0:0:0:0:0:1:50696[0](queued=0, recved=1, sent=0)
/127.0.0.1:50565[1](queued=0, recved=140, sent=140)

Latency min/avg/max: 0/0/7
Received: 865
Sent: 864
Connections: 2
Outstanding: 0
Zxid: 0x1d99
Mode: standalone
Node count: 19

ruok Check whether the current zkserver is started, and return to imok

echo ruok | nc localhost 2181
imok

dump lists unprocessed sessions and temporary nodes

$ echo dump | nc localhost 2181
SessionTracker dump:
Session Sets (3):
0 expire at Thu Jan 01 10:36:30 CST 1970:
0 expire at Thu Jan 01 10:36:40 CST 1970:
1 expire at Thu Jan 01 10:36:50 CST 1970:
    0x100000872ba0003
ephemeral nodes dump:
Sessions with Ephemerals (0):

conf view server configuration

echo conf | nc localhost 2181
clientPort=2181
dataDir=/usr/local/var/run/zookeeper/data/version-2
dataLogDir=/usr/local/var/run/zookeeper/data/version-2
tickTime=2000
maxClientCnxns=60
minSessionTimeout=4000
maxSessionTimeout=40000
serverId=0

cons displays client information connected to the server

echo cons | nc localhost 2181
/0:0:0:0:0:0:0:1:50728[0](queued=0, recved=1, sent=0)
/127.0.0.1:50565[1](queued=0,recved=184,sent=184,sid=0x100000872ba0003,lop=PING,est=1557332837106,to=30000,lcxid=0x9,lzxid=0x1d99,lresp=9618134, llat=0,minlat=0,avglat=0,maxlat=2)

envi view environment variable configuration mntr monitor zk monitoring information

echo mntr | nc localhost 2181
zk_version 3.4.12-e5259e437540f349646870ea94dc2658c4e44b3b, built on 03/27/2018 03:55 GMT
zk_avg_latency 0
zk_max_latency 7
zk_min_latency 0
zk_packets_received 942
zk_packets_sent 941
zk_num_alive_connections 2
zk_outstanding_requests 0
zk_server_state standalone
zk_znode_count 19
zk_watch_count 0
zk_ephemerals_count 0
zk_approximate_data_size 258
zk_open_file_descriptor_count 32
zk_max_file_descriptor_count 10240

wchs display watch information

$ echo wchs | nc localhost 2181
1 connections watching 1 paths
Total watches:1

wchc/wchp session and watch and path and watch information

Reference: https://cloud.tencent.com/developer/article/1438228 zookeeper(2)-Operation Command-Cloud + Community-Tencent Cloud