Zookeeper Introductory Learning (iii)--zookeeper client use

Source: Internet
Author: User
Tags zookeeper zookeeper client
One, zookeeper client 1, Zookeeper client

(1) Use SSH to connect the zookeeper server, then go to the Bin directory under the Zookeeper installation directory, then use the./zkcli.sh-timeout 5000-r-server Ip:port to establish the client connection. Where-R is a read-only mode for zookeeper, the server no longer processes client requests when the server that needs to be connected loses connectivity to more than half of the servers in the cluster, but sometimes it is still desirable that the server can provide read-only services, You need to add-R (-R is optional), IP is the IP address of the server to which you want to connect, port is the port number, and the default port number is 2181

[zk:192.168.153.129:2181 (CONNECTED) 0] help zookeeper-server host:port cmd args #查看节点状态 stat path [watch ] #设置节点的数据内容 set PATH data [version] #查看节点列表 ls path [watch] #删除节点配额-N child node number,-B data The length of the node Delquota [-n|-b] path #查看节点下的子节点列表 and displays the status of the current node LS2 path [watch] #设置节点的权限 set ACL path ACL #设置节点的配额 setquota-n|-b val path #查看历史命令 history #重复执行历史命令中的哪一条命令 cmd No represents the ID number in the history command redo Cmdno printwatches on|off #删除子节点为空的节点 Delete path [version] s
        Ync path #查看配额 listquota path #递归删除节点 RMR path #查看节点数据 get path [watch]
        Created #创建节点-S table order automatically increases whether the ID,-E table is a temporary node create [-S] [-e] path data ACL addauth scheme auth #退出客户端 Quit Getacl Path #关闭连接 close #连接到其他的服务器 connect host:port root@liumeng-1:/ opt/zookeeper/bin#./ZKCLi.sh-timeout 5000-server 192.168.153.129:2181
 

In zookeeper, each write to data node is a transaction, each transaction will have a transaction ID -client instruction Details # (1) LS and stat instruction ls path: View the node's child node list

State path: View node status

Watchedevent state:syncconnected type:none path:null
#查看节点下的子节点
[zk:192.168.153.129:2181 (CONNECTED) 0] LS/
[Zookeeper]
#查看节点的状态
[zk:192.168.153.129:2181 (CONNECTED) 1] Stat/
#创建该节点的事务ID
Czxid = 0x0
#创建该节点的时间
ctime = Thu 08:00:00 CST 1970
#最后一次被修改的事务ID
mzxid = 0x0
#最后一次被修改的ID
Mtime = Thu 08:00:00 CST 1970
#该节点的子节列表最后一次被修改的事务ID, adding a node to the current node or removing a node from the current node can cause a change in the list of child nodes, but the data content of the modified child nodes is not counted
Pzxid = 0x0
#子节点的版本号
cversion =-1
#数据版本号
dataversion = 0
#权限版本号
aclversion = 0
#专用于临时节点, create the transaction ID for the temporary node, and if the node is a persistent node, the value of the property is a fixed value of 0
ephemeralowner = 0x0
#当前节点所存放的数据的长度
datalength = 0
#当前节点所拥有的子节点的个数
numchildren = 1 
# (2) Get instruction: Gets the value of the node

Get path: Getting the value of a node

[Zk:192.168.153.129:2181 (CONNECTED) 5] get/zookeeper/node_1
#节点值        
345
#节点状态, the same as the output of the stat directive  
CZXID = 0x1900000006
CTime = Wed Apr 15:24:59 CST 2017
mzxid = 0x1900000006
mtime = Wed Apr 15:24:59 CST 2017
  pzxid = 0x1900000006
cversion = 0
dataversion = 0
aclversion = 0
ephemeralowner = 0x0
datalength = 3
numchildren = 0
[zk:192.168.153.129:2181 (CONNECTED) 6]
# (3) LS2 instruction

LS2 path: Gets the list of child nodes of the node and shows the state of the node

[Zk:192.168.153.129:2181 (CONNECTED) 1] ls2/zookeeper
[node_1, quota]
Czxid = 0x0 CTime
= Thu 01 08:00 : CST 1970
Mzxid = 0x0
mtime = Thu, 08:00:00 CST 1970 Pzxid = 0x1900000006 cversion =
0
D ataversion = 0
aclversion = 0
ephemeralowner = 0x0
datalength = 0
Numchildren = 2
# (4) Create instruction

Create [-S] [-e] path data ACL: Create a node, s to indicate whether it is a sequential node,-e is a temporary node, path is a node path, data is a node, ACL is a node right

#创建普通节点 (Permanent node) [zk:192.168.153.129:2181 (CONNECTED) 0] create/node_1 123 created/node_1 [zk:192.168.153.129:2181 ( CONNECTED) 2] get/node_1 123 Czxid = 0x190000000b CTime = Wed Apr 15:36:40 CST 2017 Mzxid = 0x190000000b mtime = Wed A  PR 15:36:40 CST 2017 Pzxid = 0x190000000b cversion = 0 dataversion = 0 aclversion = 0 Ephemeralowner = 0x0 datalength = 3 Numchildren = 0 #创建临时节点, and then log back on after the client connection is terminated, the temporary node fails to delete [zk:192.168.153.129:2181 (CONNECTED) 1] create-e/node_1/node_1_1 23 4 Created/node_1/node_1_1 [zk:192.168.153.129:2181 (CONNECTED) 2] ls/node_1 [node_1_1] #退出客户端 [zk:192.168.153.129:2181 (CONNECTED) 3] quit quitting ... #重新连接客户端 root@liumeng-1:/opt/zookeeper/bin#./zkcli.sh-timeout 5000-server 192.168.153.129:2181 connecting to 192.168.153.129:2181 #重新查询, the node's child nodes are empty [zk:192.168.153.129:2181 (CONNECTED) 0] Ls/node _1 [] #创建顺序节点 [zk:192.168.153.129:2181 (CONNECTED) 1] create-s/node_1/node_1_1 234 #创建成功之后返回的节点名称 created/node_1/node_1 _10000000001 #同路径下继续创建相同名称的节点名, because it's a sequential node, sub. The node is automaticallyIncrement ID [zk:192.168.153.129:2181 (CONNECTED) 2] create-s/node_1/node_1_1 234 created/node_1/node_1_10000000002 [zk:192.1 68.153.129:2181 (CONNECTED) 3] create-s/node_1/node_1_1 234 created/node_1/node_1_10000000003 [ZK:
 192.168.153.129:2181 (CONNECTED) 4] ls/node_1 [node_1_10000000001, node_1_10000000003, node_1_10000000002]
# (5) Set instruction

Set path data [version]: Modify the node, version is the current node's data edition number, optional parameters, version must be consistent with the current node data version number to be able to modify the success, or failure

#修改节点内容 [zk:192.168.153.129:2181 (CONNECTED) 3] set/node_1/node_1_10000000001 789 Czxid = 0x1900000011 CTime = Wed APR 19 15:39:27 CST 2017 Mzxid = 0x1900000016 mtime = Wed Apr 15:47:37 CST 2017 Pzxid = 0x1900000011 cversion = 0 #数据版本号加了1 D Ataversion = 1 Aclversion = 0 Ephemeralowner = 0x0 datalength = 3 Numchildren = 0 #查询节点内容 [zk:192.168.153.129:2181 (CONNEC TED) 4] get/node_1/node_1_1000000000 789 Czxid = 0x1900000011 CTime = Wed Apr 15:39:27 CST 2017 Mzxid = 0x1900000016 m Time = Wed APR 15:47:37 CST 2017 Pzxid = 0x1900000011 cversion = 0 #数据版本号加了1 dataversion = 1 aclversion = 0 Ephemeralow NER = 0x0 Datalength = 3 Numchildren = 0 #指定数据版本号修改 #版本号一致, modification succeeded, data version number plus 1 [zk:192.168.153.129:2181 (CONNECTED) 5] Set/node_ 1/node_1_10000000001 987 2 Czxid = 0x1900000011 CTime = Wed Apr 15:39:27 CST 2017 Mzxid = 0x190000001c mtime = Wed Apr
15:51:52 CST 2017 Pzxid = 0x1900000011 cversion = 0 Dataversion = 3 aclversion = 0 Ephemeralowner = 0x0 datalength = 3 Numchildren = 0 #版本号不一致,Modification failed [zk:192.168.153.129:2181 (CONNECTED) 6] set/node_1/node_1_10000000001 987 2 version No is not valid:/node_1/node_1
 _10000000001
# (6) Delete instruction and RMR instructionDelete path [version]: Delete a node, can only delete nodes without child nodes, otherwise the error, version and set of versions of the same effect

RMR path: Recursively deletes a node and deletes all child nodes under the node

#delete删除没有子节点的节点
[zk:192.168.153.129:2181 (CONNECTED) 0] delete/node_1/node_1_10000000001
[ZK: 192.168.153.129:2181 (CONNECTED) 2] ls/node_1
[node_1_10000000003, node_1_10000000002]
#delete删除有子节点的节点
[zk:192.168.153.129:2181 (CONNECTED) 3] delete/node_1
Node not empty:/node_1
#rmr删除有子节点的节点
[zk:192.168.153.129:2181 (CONNECTED) 4] rmr/node_1
[ZK: 192.168.153.129:2181 (CONNECTED) 5] LS/
[zookeeper]
# (7) Setquota instruction

Setquota-n|-b var path: Quotas are set for nodes,-n indicates the number of child nodes,----------limit the length of child node data, Var is the value, path

#设置配额, the number of child nodes is 2
[zk:192.168.153.129:2181 (CONNECTED) 3] setquota-n 2/node_1 comment:the parts are option-n
val 2 path/node_1
#创建子节点
[zk:192.168.153.129:2181 (CONNECTED) 5] create-s/node_1/node_1_1 123
Created/node_ 1/node_1_10000000001
[zk:192.168.153.129:2181 (CONNECTED) 6] create-s/node_1/node_1_1 123
created/node_1/ node_1_10000000002
[zk:192.168.153.129:2181 (CONNECTED) 7] create-s/node_1/node_1_1 123
created/node_1/ node_1_10000000003
[zk:192.168.153.129:2181 (CONNECTED) 8] ls/node_1
[node_1_10000000001, node_1_ 10000000003, node_1_10000000002]

It is found here that the number of nodes exceeds the quota setting and no exception is thrown because in zookeeper, if the number of child nodes exceeds the quota limit, the exception is not thrown, and only an alert message is logged in the log, in the bin directory under the Zookeeper installation directory

    #Quota Exceeded:path count limit path to a node that exceeds the quota, the current state includes the number of child nodes for the node itself, limit child node quota values
    2017-04-19 16:04:15,460 [myID : 3]-WARN  [commitprocessor:3:datatree@301]-Quota exceeded:/node_1 count=3 limit=2
    2017-04-19 16:04:18,128 [ Myid:3]-WARN  [commitprocessor:3:datatree@301]-Quota exceeded:/node_1 count=4 limit=2
# (8) Listquota instruction

Listquota path: View quotas for nodes

[zk:192.168.153.129:2181 (CONNECTED) 0] listquota/node_1
Absolute path is/zookeeper/quota/node_1/zookeeper_ Limits
#当前节点的配额, the quota for the number of child nodes is 2, the data length is not limited (1 means no limit)
Output quota for/node_1 count=2,bytes=-1
#当前节点的状态, Count represents the number of child nodes that the current node includes itself, bytes represents the data length of all child nodes, including node data, and
Output stat for/node_1 count=4,bytes=12    
# (9) Listquota instruction

Delquota [-n|-b] path: Deleting quotas for nodes

 [zk:192.168.153.129:2181 (CONNECTED) 0] 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=5,bytes=15 [zk:192.168.153.129:2181 (CONNEC TED) 1] delquota-n/node_1 [zk:192.168.153.129:2181 (CONNECTED) 2] listquota/node_1 absolute path is/zookeeper/quota/no De_1/zookeeper_limits Output Quota for/node_1 count=-1,bytes=-1 output stat for/node_1 count=5,bytes=15 

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.