ZooKeeper command line client

ZooKeeper command line client

Start client

  • Start the local zookeeper client:. / zkCli.sh
[root@node-02 bin]# ./zkCli.sh
Connecting to localhost:2181  # 2181 is the client listening port
...
[zk: localhost:2181(CONNECTED) 0] 
  • Start remote zookeeper client:. / zkCli.sh – server ip:port
[root@node-01 bin]# ./zkCli.sh -server node-02:2181
Connecting to hdp-02:2181
...
[zk: node-02:2181(CONNECTED) 0] 

Client commands

get command

Obtain node information. Note that the paths of nodes are absolute paths, that is, it is necessary to start from / (root path).

[zk: localhost:2181(CONNECTED) 1] get /aa
hello world #Data stored by node
cZxid = 0x0 #zxid at node creation
ctime = Thu Jan 01 08:00:00 CST 1970 #Node creation time
mZxid = 0x5 #zxid when the node was last updated
mtime = Thu Apr 27 15:09:00 CST 2017 #The time when the node was last updated
pZxid = 0xc #Timestamp of the last creation / deletion of a child node
cversion = 1 #Child node data update times
dataVersion = 2 #Data update times of this node
aclVersion = 0 #Number of updates of node ACL (authorization information)
ephemeralOwner = 0x0 #This node is not a temporary node
dataLength = 11 #Node data length
numChildren = 1 #Number of child nodes of node
[zk: localhost:2181(CONNECTED) 1] get /aa watch # watch monitors node data (only once)
[zk: localhost:2181(CONNECTED) 1] set /aa dfdsf
#Modify node data to display listening results
WATCHER::
WatchedEvent state:SyncConnected type:NodeDataChanged path:/aa

ls command

Get the node information under the path (note that this path is an absolute path, similar to the ls command in linux)

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

ls2 command

ls2 is an extension of ls command, which outputs more information of this node than ls command

[zk: hdp-01(CONNECTED) 12] ls2 /
[aa, zookeeper]
cZxid = 0x0
ctime = Thu Jan 01 08:00:00 CST 1970
mZxid = 0x0
mtime = Thu Jan 01 08:00:00 CST 1970
pZxid = 0x20000001c
cversion = 6
dataVersion = 0
aclVersion = 0
ephemeralOwner = 0x0
dataLength = 0
numChildren = 2

create command

Create a node, where - s is a sequential node and - e is a temporary node

# Create persistent node (default)
[zk: localhost:2181(CONNECTED) 1] create /aa "aa"
# Create a temporary node (if the client is disconnected, the node will be deleted automatically)
[zk: localhost:2181(CONNECTED) 1] create -e /bb "bb"
# Create node with sequence number (automatically add sequence number to the node to avoid node duplication)
[zk: localhost:2181(CONNECTED) 1] create -s /cc "cc"
Created /cc0000000006
# Create a temporary node with sequence number
[zk: localhost:2181(CONNECTED) 1] create  -e -s /dd "dd"

set command

Set the data of the node

[zk: localhost:2181(CONNECTED) 1] set /zookeeper "hello world"

rmr command

Delete node command

The difference between this command and the delete command is that delete cannot delete a node with child nodes, but the rmr command can delete it. Note that the path is an absolute path

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

delete command

Delete node (the deleted node cannot have child nodes)

[zk: hdp-01(CONNECTED) 28] delete /aa

stat command

Viewing node status information is different from the get command in that node data cannot be viewed

[zk: localhost:2181(CONNECTED) 1] stat /
cZxid = 0x0
ctime = Thu Jan 01 08:00:00 CST 1970
mZxid = 0x1f
mtime = Thu Apr 27 16:05:14 CST 2017
pZxid = 0xc
cversion = 1
dataVersion = 3
aclVersion = 0
ephemeralOwner = 0x0
dataLength = 5
numChildren = 1

connect command

Connect the zookeeper server, and use it with the close command to connect or disconnect the zookeeper server

[zk: localhost:2181(CONNECTED) 0] connect 127.0.0.1:2181

quit command

Exit client connection

[zk: localhost:2181(CONNECTED) 1] quit

close command

Disconnect the client from the server

[zk: localhost:2181(CONNECTED) 1] close

printwatches command

Set and display monitoring status, on or off

[zk: localhost:2181(CONNECTED) 1] printwatches on

history command

List recent historical commands

[zk: hdp-01(CONNECTED) 14] history
4 - status /aa
5 - stat /aa
6 - close
7 - ls /
8 - connect hdp-01
9 - ls /
10 - ls2 /
11 - ls /
12 - ls2 /
13 - hostory
14 - history

redo command

Execute a command again, where 10 is the command ID, which needs to be used in conjunction with the history command

[zk: hdp-01(CONNECTED) 28] redo 10

sync command

Force synchronization

Since the request takes effect on more than half of the zookeeper server nodes, it means that the request takes effect. Then, the data on some zookeeper server nodes is old. The sync command forces all update operations to be synchronized

[zk: hdp-01(CONNECTED) 28] sync /zookeeper

setquota command

Set the number of child nodes and data length quota

# set up /zookeeper/aa The maximum number of child nodes is 4[zk: hdp-01(CONNECTED) 28] setquota –n 4 /zookeeper/aa# Set the maximum node length of / zookeeper/bb to 100[zk: hdp-01(CONNECTED) 28] setquota – b 100 /zookeeper/bb 

listquota command

Show quota

[zk: hdp-01(CONNECTED) 22] listquota /zookeeperabsolute path is/zookeeper/quota/zookeeper/zookeeper_limitsOutput quota for /zookeepercount=2,bytes=-1 #The number of nodes is limited to 2 and the length is unlimited. 

delquota command

Delete quota, - n is the number of child nodes, - b is the node data length.

[zk: localhost:2181(CONNECTED) 1] delquota –n 2

See listquota and setquota commands

help command

Displays all commands supported by the zookeeper client

[zk: localhost:2181(CONNECTED) 7] help[zk: localhost:2181(CONNECTED) 11] helpZooKeeper -server host:port cmd args        stat path [watch]        set path data [version]        ls path [watch]        delquota [-n|-b] path        ls2 path [watch]        setAcl path acl        setquota -n|-b val path        history         redo cmdno        printwatches on|off        delete path [version]        sync path        listquota path        rmr path        get path [watch]        create [-s] [-e] path data acl        addauth scheme auth        quit         getAcl path        close         connect host:port

Optional command: watch: indicates to listen to node data

Keywords: Hadoop

Added by lookee on Thu, 02 Dec 2021 23:55:17 +0200