In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-02-25 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >
Share
Shulou(Shulou.com)06/02 Report--
Zookeeper CLI1, view all commands
Start zookeeper and connect to the zookeeper server using zkCli.sh in the bin directory, enter any commands that zookeeper does not recognize, and zookeeper lists all available commands:
[zk: 127.0.0.1 kZooKeeper 2184 (CONNECTED) 105] kZooKeeper-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:port2 Command parsing
Create a node:
Create [- s] [- e] path data acl
-s ordered node
A znode can also be set to an sequential node. An ordered znode node is assigned a unique monotonously increasing integer. When an ordered node is created, a sequence number is appended to the path.
-e temporary node
Znode nodes can be persistent (persistent) nodes or temporary (ephemeral) nodes. Persistent znode can only be deleted by calling delete. A temporary znode, by contrast, is deleted when the client that created the node crashes or closes the connection to the ZooKeeper. Because the temporary znode is deleted when its creator's session expires, we do not allow temporary nodes to have child nodes at this time.
In summary, there are four types of znode: persistent, ephemeral, persistent_sequential, and ephemeral_sequential.
Data saved by the data node
Acl permission related content, will not be considered for the time being
Create a persistent node
[zk: 127.0.0.1 create 2184 (CONNECTED) 7] create / test testdataCreated / test [zk: 127.0.0.1 create 2184 (CONNECTED) 8] ls / [zookeeper, test]
Create a temporary node
[zk: 127.0.0.1 create 2184 (CONNECTED) 9] create-e / testephemeral testdata2Created / testephemeral [zk: 127.0.0.1 create 2184 (CONNECTED) 11] ls / [zookeeper, test, testephemeral]
Ctrl+c disconnects from the server before viewing
WatchedEvent state:SyncConnected type:None path:null [zk: 127.0.0.1 CONNECTED 2184 (CONNECTED) 0] ls / [zookeeper, test]
The temporary node has been removed.
Create ordered nodes
[zk: 127.0.0.1 create 2184 (CONNECTED) 4] create-s / testsquence testdata2Created / testsquence0000000008 [zk: 127.0.0.1 create 2184 (CONNECTED) 5] ls / [testsquence0000000008, zookeeper, test]
It automatically appends a serial number to the path we specified.
Node state
Stat path [watch]
Watch add monitors, we'll talk about it later
List the status of the node / test
[zk: 127.0.0.1 stat (CONNECTED) 10] stat / test cZxid = 0x21ctime = Wed May 08 05:43:54 CST 2019mZxid = 0x21mtime = Wed May 08 05:43:54 CST 2019pZxid = 0x21cversion = 0dataVersion = 0aclVersion = 0ephemeralOwner = 0x0dataLength = 8numChildren = 0
Attribute description
The status attribute describes the transaction zxid created by the cZxid node. Each time you modify the ZooKeeper state, you will receive a timestamp in the form of zxid, that is, the ZooKeeper transaction ID. Transaction ID is the total order of all modifications in ZooKeeper. Each modification has a unique zxid, and if zxid1 is less than zxid2, then zxid1 occurs before zxid2. If it is not a temporary node, it is the data length dataLengthznode child node number of 0dataLengthznode
Query data
Get path [watch]
Query the data of node / test
[zk: 127.0.0.1 get (CONNECTED) 19] get / testtestdatacZxid = 0x21ctime = Wed May 08 05:43:54 CST 2019mZxid = 0x21mtime = Wed May 08 05:43:54 CST 2019pZxid = 0x21cversion = 0dataVersion = 0aclVersion = 0ephemeralOwner = 0x0dataLength = 8numChildren = 0
Well, it's the value of data plus status information.
List nodes
Ls path [watch] ls2 path [watch]
List root node information
[zk: 127.0.0.1 ls 2184 (CONNECTED) 0] ls / [testsquence0000000008, zookeeper, test] [zk: 127.0.0.1 ls 2184 (CONNECTED) 1] ls2 / [testsquence0000000008, zookeeper, test] cZxid = 0x0ctime = Thu Jan 01 08:00:00 CST 1970mZxid = 0x0mtime = Thu Jan 01 08:00:00 CST 1970pZxid = 0x25cversion = 15dataVersion = 0aclVersion = 0ephemeralOwner = 0x0dataLength = 0numChildren = 3
Ls2 wants to add the status information of the current node on the basis of ls.
Set up data
Set path data [version]
Data to be set by data
Version data version number, which is set only when the specified version number is the same as the current data version number of the node
Set node / test data to newdata
Set / test newdatacZxid = 0x21ctime = Wed May 08 05:43:54 CST 2019mZxid = 0x28mtime = Wed May 08 06:40:59 CST 2019pZxid = 0x21cversion = 0dataVersion = 1aclVersion = 0ephemeralOwner = 0x0dataLength = 7numChildren = 0 [zk: 127.0.0.1 Vera 2184 (CONNECTED) 34] get / test newdatacZxid = 0x21ctime = Wed May 08 05:43:54 CST 2019mZxid = 0x28mtime = Wed May 08 06:40:59 CST 2019pZxid = 0x21cversion = 0dataVersion = 1aclVersion = 0ephemeralOwner = 0x0dataLength = 7numChildren = 0
Have you noticed that dataVersion has changed from 0 to 1? this is associated with the last parameter, version.
Specify an incorrect version update data
[zk: 127.0.0.1 set 2184 (CONNECTED) 59] set / test nnn 0version No is not valid: / test
Failure.
Let's try the right one.
[zk: 127.0.0.1 set (CONNECTED) 61] set / test nnn 1 cZxid = 0x21ctime = Wed May 08 05:43:54 CST 2019mZxid = 0x2amtime = Wed May 08 06:46:12 CST 2019pZxid = 0x21cversion = 0dataVersion = 2aclVersion = 0ephemeralOwner = 0x0dataLength = 3numChildren = 0
It worked, and then dataVersion changed from 1 to 2.
Delete nod
Delete path [version] rmr path
Version: the version number, which means the same as the set command, can only be deleted if the version is the same.
The difference between delete and rmr is that delete cannot be deleted when there are child nodes, while rmr can cascade delete child nodes.
Delete / test using delete
[zk: 127.0.0.1 delete 2184 (CONNECTED) 73] delete / test [zk: 127.0.0.1 delete 2184 (CONNECTED) 74] ls / [testsquence0000000008, zookeeper]
Use delete to delete a child node.
[zk: 127.0.0.1 create 2184 (CONNECTED) 77] create / test ttCreated / test [zk: 127.0.0.1 create 2184 (CONNECTED) 78] create / test/child ttCreated / test/child [zk: 127.0.0.1 test ttCreated 2184 (CONNECTED) 80] delete / testNode not empty: / test
Yes, you cannot delete a child node
Use rmr to delete / test with child nodes.
[zk: 127.0.0.1 rmr 2184 (CONNECTED) 85] rmr / test [zk: 127.0.0.1 rmr 2184 (CONNECTED) 86] ls / [testsquence0000000008, zookeeper]
Deleted successfully
Watch usage
Watch mechanism: a zk node can be monitored, including changes to the data stored in this directory, changes in the child node directory, and once changes can be notified to the monitoring client. This function is the most important feature of zookeeper for applications. The functions that can be realized through this feature include centralized configuration management, cluster management, distributed locking, and so on. A Watch event is an one-time trigger, and when the data with the Watch set changes, the server sends the change to the client with the Watch set.
Create a watch to the node / test through ls
[zk: 127.0.0.1 ls 2184 (CONNECTED) 92] ls / test mywatch [zk: 127.0.0.1 ls 2184 (CONNECTED) 94] delete / testWATCHER::WatchedEvent state:SyncConnected type:NodeDeleted path:/test
We received a notification when the node was deleted
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.