Use of zookeeper command line zkcli.sh&zkserver.sh (iv)

Source: Internet
Author: User
Tags sessions zookeeper

On the blog, we successfully installed and launched the Zookeeper server, zookeeper also provides a lot of convenient features to facilitate us to view the status of the server, add, modify, delete data (the entrance is zkserver.sh and zkcli.sh). It also provides a series of four-word commands that allow us to interact with the server to confirm the server's current performance (which is also the basis for server monitoring alarms). zkserver.sh

After zookeeper start, let's take a look at the main features that ZKSERVER.SH provides: View server status

[Yinpeng@slave1 zookeeper-3.4.9]$./bin/zkserver.sh status
zookeeper JMX enabled by default
Using config:/home /yinpeng/yuliang/zookeeper-3.4.9/bin/.. /conf/zoo.cfg
Mode:standalone

We are using a stand-alone mode of zookeeper. Starting and stopping the server

[Yinpeng@slave1 zookeeper-3.4.9]$./bin/zkserver.sh help  
Zookeeper JMX-enabled by default
Using config:/home/ yinpeng/yuliang/zookeeper-3.4.9/bin/.. /conf/zoo.cfg
Usage:./bin/zkserver.sh {Start|start-foreground|stop|restart|status|upgrade|print-cmd}

Zkserver.sh also offers the ability to start, stop, and reboot. Zookeeper provides not only the server-side commands, but also the client commands. zkcli.sh

Use zkcli.sh to connect zookeeper, and to operate zookeeper on the client.

First, connect zookeeper

./bin/zkcli.sh-timeout 5000-server 192.168.0.23:2181

After the connection is successful, the system will output zookeeper related environment and configuration information, and output "Welcome to Zookeeper" on the screen. As shown in the following illustration:

After you enter Help or H, the screen prints out a list of available client commands, as shown in the following illustration:

From top to bottom, there are more than 10 orders altogether. Learn more things, as much practice, the following we order the practice once again: LS Query the current node list (/is the root node) path: Path

[Zk:192.168.0.23:2181 (CONNECTED) 7] LS/
[zookeeper]
Create creates a new Znode node (-S: Sequential node-e: Temporary data node (reboot disappears)) path: path data: Data ACL: permissions, do not specify default as World:anyone:cdwra, reference zookeeper ACL access Control List
[Zk:192.168.0.23:2181 (CONNECTED)] create/node_1 "test" 
created/node_1

Sequential nodes can be used as a primary key self-increasing policy get view node data path: Path

[Zk:192.168.0.23:2181 (CONNECTED)] get/node_1
test
czxid = 0x13 CTime
= Thu Feb CST 13:19:40
m Zxid = 0x13
mtime = Thu Feb 13:19:40 CST 2017
pzxid = 0x13 cversion =
0
dataversion = 0
aclversion = 0
Ephemeralowner = 0x0
datalength = 4
numchildren = 0

Test data content stored for the node
Note:
CZXID: Represents the transaction ID that the node created in that transaction.
CTime: Indicates when the node was created
MZXID: Represents the transaction ID when the node is updated
Mtime: Indicates the modified time of the node
PZXID: The transaction ID that represents the last modification of the list of child nodes for this node
Cversion: Sub-node version number
Dataversion: Data Version number
Aclversion: Permission version number
Ephemeralowner: Dedicated to a temporary node that represents the transaction ID that created the temporary node (if the current node is a persistent node, the value is fixed to 0)
Datalength: The length of the current node holds data
Numchildren: Number of child nodes of the current node Stat View data node status information path: path

[Zk:192.168.0.23:2181 (CONNECTED)] stat/node_1
czxid = 0x13 CTime
= Thu Feb-13:19:40 CST 2017
Mzxid = 0x13
mtime = Thu Feb 13:19:40 CST 2017
pzxid = 0x13 cversion
= 0
dataversion = 0
aclversion = 0
Ephemeralowner = 0x0
datalength = 4
numchildren = 0

LS2 is the super instruction of LS, which can not only list the nodes of the current node, but also output the state information of the node, no longer demonstrated.

Set sets the value of the data node, path: path, data: Date, can be with version number, without version number,

[Zk:192.168.0.23:2181 (CONNECTED)] set/node_1 "11114"  
czxid = 0x13 CTime
= Thu Feb CST 13:19:40
2017  XID = 0x18
mtime = Thu Feb 13:32:59 CST 2017
pzxid = 0x17 cversion =
4
dataversion = 1
aclversion = 0
ephemeralowner = 0x0
datalength = 5
numchildren = 3
[zk:192.168.0.23:2181 (CONNECTED)] Get/node_ 1 
11114
czxid = 0x13
CTime = Thu Feb-CST 13:19:40
2017 = mzxid 0x18
= mtime Thu 16 Feb 9 CST 2017
pzxid = 0x17
cversion = 4
dataversion = 1
aclversion = 0
ephemeralowner = 0x0
dat Alength = 5
Numchildren = 3

I set up three nodes under Node_1, Node_1_1,node_1_2 and Node_1_3 set: Add the version number (optimistic lock)

[Zk:192.168.0.23:2181 (CONNECTED)] get/node_1/node_1_3
333
czxid = 0x30 CTime
= Fri Feb-10:11:45 CST 20
Mzxid = 0x33
mtime = Fri Feb 10:29:37 CST 2017
pzxid = 0x30 cversion
= 0
dataversion = 2
ACL Version = 0
ephemeralowner = 0x0
datalength = 3
numchildren = 0
[zk:192.168.0.23:2181 (CONNECTED) 28] Set/node_1/node_1_3 332 2
czxid = 0x30
CTime = Fri Feb-10:11:45 CST 2017
mzxid = 0x34 Mtime = Fri
Feb 10:31:51 CST 2017
pzxid = 0x30 cversion
= 0
dataversion = 3
aclversion = 0
Ephemeralowner = 0x0
datalength = 3
numchildren = 0
[zk:192.168.0.23:2181 (CONNECTED)] Set/node_1/node_1_3 332 >version No is valid:/node_1/node_1_3

Through get, we know the data value and version number of node_1_3, then modify the data value and version number of node_1_3, the version number will be modified successfully, the version number is inconsistent, the exception that throws the version number is invalid. Delete Deletes the node_1_3 node, it does not have a child node, or it will be an error, you can also carry a version

[Zk:192.168.0.23:2181 (CONNECTED) 4] delete/node_1/node_1_3
[zk:192.168.0.23:2181 (CONNECTED) 5] ls2/node_1
[Node_1_1, Node_1_2]
Czxid = 0x13
CTime = Thu Feb 13:19:40 CST 2017
mzxid = 0x18 mtime
= Thu Feb 13:32:59 CST 2017
Pzxid = 0x26
cversion = 6
dataversion = 1
aclversion = 0
ephemeralowner = 0x0 datalength
= 5
Numchil dren = 2

At this point, we see that the Node_1_3 node has been deleted. RMR The parent node that has child nodes, such as deleting node_1

[Zk:192.168.0.23:2181 (CONNECTED) 6] rmr/node_1
[zk:192.168.0.23:2181 (CONNECTED) 7] LS/
[zookeeper]

After using LS authentication, the parent node and the child node are indeed deleted. Quota (quota): Increase the number of node restrictions, must be in a certain range Setquota: Set the number of child nodes (-N: The limit of the number of child nodes,-B: Data data node data length limit)

[Zk:192.168.0.23:2181 (CONNECTED)] Create/node_1 1
created/node_1
[zk:192.168.0.23:2181 (CONNECTED) 40] Setquota-n 2/node_1
comment:the parts are option-n val 2 path/node_1
[zk:192.168.0.23:2181 (CONNECTED)] Cr Eate/node_1/node_1_1
created/node_1/node_1_1
[zk:192.168.0.23:2181 (CONNECTED)] Create/node_1/node_1 _2
created/node_1/node_1_2
[zk:192.168.0.23:2181 (CONNECTED)] create/node_1/node_1_3 Created
/ Node_1/node_1_3

The above command, we recreated the Node_1 node and set it to a limit of 2 nodes, but we succeeded in creating the child node, node_1_3, and did not throw an exception to us, it was simply a warning to the output of the zookeeper.out in the directory.

More than the number will only be reported warning:

[yinpeng@slave1 zookeeper-3.4.9]$ tail zookeeper.out 
..... Omitting
2017-02-17 10:45:32,472 [myID:]-WARN  [syncthread:0:datatree@301]-Quota exceeded:/node_1 count=3 limit= 2
Listquota, view data node quotas
[Zk:192.168.0.23:2181 (CONNECTED)] listquota/node_1
Absolute path is/zookeeper/quota/node_1/zookeeper_limits
Output Quota for/node_1 count=2,bytes=-1
Output Stat for/node_1 count=4,bytes=7

Two lines of information are exported, the first line is the quota information, the number of child nodes set is 2, the data length is 1, there is no limit, the second row is state information, at this point the number of child nodes is 4, the data length is 7 (its own data length plus the data length of the child node) Delquota, delete data node quota

[Zk:192.168.0.23:2181 (CONNECTED) Wuyi] delquota-n/node_1
[zk:192.168.0.23:2181 (CONNECTED)] listquota/node_1< C4/>absolute path is/zookeeper/quota/node_1/zookeeper_limits
Output quota for/node_1 count=-1,bytes=-1
Output Stat for/node_1 count=4,bytes=7

After removing the configuration of the node, we verify that there are no restrictions on the number of child nodes of the Node_1 node at this time, and the length of the data is unlimited.

Let's take a quick look at the other commands:

History print out the 10 most recently executed commands
Redo Cmdno Execute previously executed commands based on the command number (available history query number)
Close closes the current connection, can connect again with connect, does not exit the client
Quit close the connection and exit the connection client
Connect Connect Server

command of permission, we learn through an article, I feel quite good, no longer do:
Use zookeeper ACL features for Znode control commonly used four-word commands

Command function Description
Conf Output related service configuration details
Cons Lists the full connection/session details for all clients connected to the server. Includes "Accept/send" packet number, session, ID, Operation delay, final operation execution, etc. information
Dump Lists the unhandled sessions and temporary nodes.
Envi Output detailed information about the service environment
Reqs List of unprocessed requests
Ruok Test whether the service is in the correct state. If it does, then the service returns "Imok", otherwise no response is made
Stat Output list of clients on performance and connectivity
Wchs List details of server watch
Wchc Lists the details of the server watch by session, and its output is a list of watch-related sessions
Wchp Lists the details of the server watch by path. It outputs a path associated with the session

Here are a few examples: conf

[Yinpeng@slave1 zookeeper-3.4.9]$ echo conf | NC 192.168.0.23 2181
clientport=2181
datadir=/home/yinpeng/yuliang/data/version-2
datalogdir=/home/ Yinpeng/yuliang/data/version-2
ticktime=2000
maxclientcnxns=60
minsessiontimeout=4000
maxsessiontimeout=40000
serverid=0
Cons
[Yinpeng@slave1 zookeeper-3.4.9]$ echo Cons | NC 192.168.0.23 2181
 /192.168.0.23:38968[0] (queued=0,recved=1,sent=0)
Ruok

Test whether the service is in the correct state. If so, then the service returns "Imok", otherwise no corresponding.

[Yinpeng@slave1 zookeeper-3.4.9]$ echo Ruok | NC 192.168.0.23 2181
Imok

Reply Imok indicates that the stat has been started

[Yinpeng@slave1 zookeeper-3.4.9]$ echo Stat | NC 192.168.0.23 2181
zookeeper version:3.4.9-1757313, built on 08/23/2016 06:50 GMT
Clients:
 / 192.168.0.23:38972[0] (queued=0,recved=1,sent=0)

latency min/avg/max:0/0/32
received:5425
sent:5424
connections:1
outstanding:0
zxid:0x4a
mode:standalone
Node count:11

Other orders, we don't look, you can try, this blog post ends here. Summary

Zookeeper's command is very simple, with the usual use of SQL, not too much, not much said, the next blog we use Java Client to operate.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.