Three, Zookeeper's command line operation

       This article mainly describes the command line operation of Zookeeper, pay attention to the column "Broken Cocoon and Become a Butterfly- Zookeeper " to view Zookeeper related articles~


table of Contents

1. Basic syntax of command line operation

Two, operation example


 

1. Basic syntax of command line operation

       First, use zkCli.sh to enter the command line interface of Zookeeper.

       Below is the basic syntax of command line operations.

Basic command syntax

Function description

help

Show all operation commands

ls path [watch]

Use the ls command to view the content contained in the current znode

ls2 path [watch]

View current node data and can see data such as the number of updates

create

Ordinary creation

-s contains sequence

-e Temporary (restart or timeout disappears)

get path [watch]

Get the value of the node

set

Set the specific value of the node

stat

View node status

delete

Delete node

rmr

Recursively delete nodes

Two, operation example

1. Display all operation commands

help

2. View the content contained in ZNode

ls /

3. View the detailed data of the current node

ls2 /

       The Stat structure is explained as follows:
       (1) cZxid: the transaction zxid that creates the node. Every time the ZooKeeper state is modified, a timestamp in the form of zxid will be received, which is the ZooKeeper transaction ID. The transaction ID is the total sequence of all modifications in ZooKeeper. Each modification has a unique zxid, if zxid1 is less than zxid2, then zxid1 occurs before zxid2.
       (2) ctime: The number of milliseconds the znode was created (since 1970).
       (3) mZxid: The last updated transaction zxid of znode.
       (4) mtime: the number of milliseconds last modified by znode (since 1970).
       (5) pZxid: The last updated child node zxid of znode.
       (6) Cversion: znode child node change number, znode child node modification times.
       (7) dataVersion: znode data change number.
       (8) aclVersion: the change number of the znode access control list.
       (9) ephemeralOwner: If it is a temporary node, this is the session id of the znode owner. If it is not a temporary node, it is 0.
       (10) dataLength: the data length of znode.
       (11) numChildren: the number of znode child nodes.

4. Create a normal node

create /node_name "node_content"

5. Get the value of the node

get /node_name

6. Create short-lived nodes. As the name suggests, this node is short-lived, meaning that it is visible on the current client. If you exit the current client, it will be deleted automatically.

create -e /node_name "node_content"

       Exit the client and re-enter to find that the original node has disappeared:

7. Create a node with a serial number

create -s /node_name "node_content"

       Note: If there is no serial number node, the serial number starts from 0 and increases sequentially. If there are already 2 nodes under the original node, the reordering starts from 2, and so on.

8. Modify the data value of the root node

set /node_name "修改的值"

9. The value of the monitoring node

get /node_name watch

       Monitor xzw on slave01. When the value in xzw changes, you see the following:

10. Monitor changes in child nodes

ls /node_name watch

       Monitor xzw on slave01. When the child node in xzw changes, you see the following:

11. Delete node

delete /node_name

rmr /node_name

       When using delete to delete, if there are child nodes under a node, it cannot be deleted:

       Using rmr to delete is equivalent to deleting nodes recursively:

12. View node status

stat /node_name

13, exit

quit

 

       This is the end of this article. If you have any problems during this process, please leave a message and let me see what problems you have encountered~

Guess you like

Origin blog.csdn.net/gdkyxy2013/article/details/108462926