Common commands of Zookeeper

Basic command syntax:

help   : Display all operation commands

  Client base command:

Client basic instruction

  1. View child nodes under a specific node

ls path

2. Create a node. And bind data to the node (persistent node by default)

create path data

3. Create persistent node (default is persistent node)

create path data

4. Create persistent order node

create -s path data

5. Create a temporary node (Note: a temporary node cannot contain any child nodes)

 create -e path data

6. Create a temporary order node (Note: a temporary node cannot contain any child nodes)

create -e -s path data

7. View node status

stat path

8. Modify node data

set path data

9. View the status of the child and the current node under the node

ls2 path

10. View operation history

history

11. Get the data information bound on the node

get path

12. Delete node (Note: the deleted node cannot contain child nodes)

delete path

13. Recursively delete nodes (Note: all nodes under the current node will be deleted)

rmr  path

14. Exit the current session (session failure)

quit

 

 

Data manipulation exercise

Create 2 ordinary nodes respectively

1. Use the LS command to view the contents of the current znode   : ls path [watch]

47.243.87.144:2181 $  ls /
[zookeeper]

2. View the current node data and see the update times and other data, ls2 path [watch]  

47.243.87.144:2181        $        ls2 /
[zookeeper]cZxid = 0x0
ctime = Thu Jan 01 08:00:00 CST 1970
mZxid = 0x0
mtime = Thu Jan 01 08:00:00 CST 1970
pZxid = 0x0
cversion = -1
dataVersion = 0
aclVersion = 0
ephemeralOwner = 0x0
dataLength = 0
numChildren = 1

3,create :

create [-s] [-e] path data data_info    Data can not be filled in, as shown below

Normal creation
  - s contains sequences
  - e temporary (restart or timeout disappears)

47.243.87.144:2181        $        create /data                                            # Create persistent node
Created /data
 
47.243.87.144:2181        $        create -s /data/data_info                  # Create persistent order node
Created /data/data_info0000000000
 
47.243.87.144:2181        $        create -e /data/temp_znode        # Create temporary node
Created /data/temp_znode
 
47.243.87.144:2181        $        create -e -s /data/temp_znode_        # Create temporary sequence node
Created /data/temp_znode_0000000002
 
47.243.87.144:2181        $        ls /data                                                    # Presentation node
[temp_znode, temp_znode_0000000002, data_info0000000000]

4. Get the value of the node:    get path [watch]

47.243.87.144:2181        $        get /zookeeper
 
cZxid = 0x0                                                # To create a node Id
ctime = Thu Jan 01 08:00:00 CST 1970                       # Node creation time
mZxid = 0x0                                                # Modify the of a node id
mtime = Thu Jan 01 08:00:00 CST 1970                              # Time when the node was modified  
pZxid = 0x0                                                # Of the newly inserted child node id
cversion = -2                                              # Version of child node
dataVersion = 0                                            # Data version of current node
aclVersion = 0                                             # Permission version
ephemeralOwner = 0x0                                          # Is it a temporary node
dataLength = 0                                             # Data length
numChildren = 2                                            # Number of child nodes

5. set path data [version] modify node

47.243.87.144:2181        $        create /data info_1
Created /data
47.243.87.144:2181        $        get /data
info_1
cZxid = 0x34
ctime = Wed Jun 02 18:01:25 CST 2021
mZxid = 0x34
mtime = Wed Jun 02 18:01:25 CST 2021
pZxid = 0x34
cversion = 0
dataVersion = 0
aclVersion = 0
ephemeralOwner = 0x0
dataLength = 6
numChildren = 0

Change to new value:

47.243.87.144:2181        $        set /data data_info_2_new                      # Change to new value
cZxid = 0x34
ctime = Wed Jun 02 18:01:25 CST 2021
mZxid = 0x35
mtime = Wed Jun 02 18:02:58 CST 2021
pZxid = 0x34
cversion = 0
dataVersion = 1
aclVersion = 0
ephemeralOwner = 0x0
dataLength = 15
numChildren = 0

set updates the dataVersion optimistic lock according to the version number (modify the value when the version number is equal to the given version number value)

47.243.87.144:2181        $        set /data data_info_3_new 1             # The modification is successful. Before modification, the version number is 1
cZxid = 0x34
ctime = Wed Jun 02 18:01:25 CST 2021
mZxid = 0x36
mtime = Wed Jun 02 18:06:48 CST 2021
pZxid = 0x34
cversion = 0
dataVersion = 2
aclVersion = 0
ephemeralOwner = 0x0
dataLength = 15
numChildren = 0
 
47.243.87.144:2181        $        set /data data_info_4_new 1000         # Modification failed. Before modification, the version number is 2, which is not equal to the specified 1000  
version No is not valid : /data
 
47.243.87.144:2181        $        get /data
data_info_3_new
cZxid = 0x34
ctime = Wed Jun 02 18:01:25 CST 2021
mZxid = 0x36
mtime = Wed Jun 02 18:06:48 CST 2021
pZxid = 0x34
cversion = 0
dataVersion = 2
aclVersion = 0
ephemeralOwner = 0x0
dataLength = 15
numChildren = 0

6,stat     Stat view status information

47.243.87.144:2181        $        stat /zookeeper
cZxid = 0x0
ctime = Thu Jan 01 08:00:00 CST 1970
mZxid = 0x0
mtime = Thu Jan 01 08:00:00 CST 1970
pZxid = 0x0
cversion = -2
dataVersion = 0
aclVersion = 0
ephemeralOwner = 0x0
dataLength = 0
numChildren = 2
47.243.87.144:2181        $        stat /data
cZxid = 0xb9
ctime = Thu Jun 03 20:57:09 CST 2021
mZxid = 0xb9
mtime = Thu Jun 03 20:57:09 CST 2021
pZxid = 0xb9
cversion = 0
dataVersion = 0
aclVersion = 1
ephemeralOwner = 0x0
dataLength = 9
numChildren = 0

 

7. delete path [version] deletes a node. Adding version is an optimistic lock. When the node is not empty, the delete command cannot delete it. Use the rmr command

47.243.87.144:2181        $        ls /data
[data_01]
47.243.87.144:2181 $ delete /data 0 Node not empty: /data
47.243.87.144:2181 $ delete /data 0 Node not empty: /data

8. ACL permission control

ZK nodes have five operation permissions: CREATE, READ, WRITE, DELETE and ADMIN, that is, add, DELETE, modify, query and management permissions. These five permissions are abbreviated as crwda (i.e. the abbreviation of the first character of each word).

Note: among the five permissions, delete refers to the permission to delete child nodes, and the other four permissions refer to the operation permission to their own nodes

There are four ways of identity authentication:

-World: the default mode, which is equivalent to being accessible all over the world

-auth: represents the authenticated user (in cli, you can add the authorized user in the current context through addauth digest user:pwd)

-digest: user name: password authentication, which is also the most commonly used method in business systems

-Ip: use Ip address authentication

Use [scheme:id:permissions] to represent acl permissions

getAcl: get acl permission information of a node

47.243.87.144:2181        $        create /data data_info
Created /data
47.243.87.144:2181        $        getAcl /data
'world,'anyone
: cdrwa

setAcl set permissions

47.243.87.144:2181        $        setAcl /data world:anyone:crwa
cZxid = 0x43
ctime = Wed Jun 02 18:36:02 CST 2021
mZxid = 0x43
mtime = Wed Jun 02 18:36:02 CST 2021
pZxid = 0x43
cversion = 0
dataVersion = 0
aclVersion = 1
ephemeralOwner = 0x0
dataLength = 9
numChildren = 0
 
47.243.87.144:2181        $        getAcl /data
'world,'anyone
: crwa
# Query just set setAcl permissions information crwa No permission to delete 47.243.87.144:2181 $ create /data/test1 test1_info Created /data/test1 47.243.87.144:2181 $ delete /data/test1 # No permission, deletion failed Authentication is not valid : /data/test1 # Set charge again /data Delete permissions 47.243.87.144:2181 $ setAcl /data world:anyone:crda # View permission. You already have permission to delete 47.243.87.144:2181 $ getAcl /data 'world,'anyone : cdra 47.243.87.144:2181 $ delete /data/test1 # Successfully deleted # Modify node permissions to admin after 47.243.87.144:2181 $ setAcl /data world:anyone:a cZxid = 0x54 ctime = Thu Jun 03 19:49:32 CST 2021 mZxid = 0x54 mtime = Thu Jun 03 19:49:32 CST 2021 pZxid = 0x54 cversion = 0 dataVersion = 0 aclVersion = 1 ephemeralOwner = 0x0 dataLength = 9 numChildren = 0 # Permissions are just administrative permissions 47.243.87.144:2181 $ getAcl /data 'world,'anyone : a # You do not have permission to read or view 47.243.87.144:2181 $ get /data Authentication is not valid : /data

acl Auth password plaintext setting

# Create default permission node data
47.243.87.144:2181        $        create /data data_info
Created /data
47.243.87.144:2181        $        getAcl /data
'world,'anyone
: cdrwa
 
# Registered account password, plaintext password: Account: password
47.243.87.144:2181        $        addauth digest testuser:pwdtest
 
# use auth Set node permission information
47.243.87.144:2181        $        setAcl /data auth:testuser:pwdtest:cdrwa
cZxid = 0x88
ctime = Thu Jun 03 20:21:27 CST 2021
mZxid = 0x88
mtime = Thu Jun 03 20:21:27 CST 2021
pZxid = 0x88
cversion = 0
dataVersion = 0
aclVersion = 1
ephemeralOwner = 0x0
dataLength = 9
numChildren = 0
 
# View node permission information
47.243.87.144:2181        $        getAcl /data
'digest,'testuser:fCxrHIVaINLWCCMKG8gNSPXMbCg=
: cdrwa

acl digest password ciphertext setting

# Create default permission node data
47.243.87.144:2181        $        create /data data_info
Created /data
 
# View permissions
47.243.87.144:2181        $        getAcl /data
'world,'anyone
: cdrwa
 
# use digest Set the permission information password of the node to testpwd ciphertext
47.243.87.144:2181        $        setAcl /data digest:testuser:fCxrHIVaINLWCCMKG8gNSPXMbCg=:cdra
cZxid = 0x9b
ctime = Thu Jun 03 20:37:47 CST 2021
mZxid = 0x9b
mtime = Thu Jun 03 20:37:47 CST 2021
pZxid = 0x9b
cversion = 0
dataVersion = 0
aclVersion = 1
ephemeralOwner = 0x0
dataLength = 9
numChildren = 0
 
#Insufficient permission to get node information prompt
47.243.87.144:2181        $        get /data
Authentication is not valid : /data
 
# Registered users can then access it normally
47.243.87.144:2181        $        addauth digest testuser:pwdtest

acl ip control client, this test native IP: 183.225.3.0

47.243.87.144:2181        $        create /data data_info
Created /data
47.243.87.144:2181        $        setAcl /data ip:183.225.3.0:cdrwa
cZxid = 0xb9
ctime = Thu Jun 03 20:57:09 CST 2021
mZxid = 0xb9
mtime = Thu Jun 03 20:57:09 CST 2021
pZxid = 0xb9
cversion = 0
dataVersion = 0
aclVersion = 1
ephemeralOwner = 0x0
dataLength = 9
numChildren = 0
 
# This machine can be accessed normally
47.243.87.144:2181        $        get /data
data_info
cZxid = 0xb9
ctime = Thu Jun 03 20:57:09 CST 2021
mZxid = 0xb9
mtime = Thu Jun 03 20:57:09 CST 2021
pZxid = 0xb9
cversion = 0
dataVersion = 0
aclVersion = 1
ephemeralOwner = 0x0
dataLength = 9
numChildren = 0

 

#This computer is inaccessible, IP not allow
47.243.87.144:2181        $        create /data1 data1_info
Created /data1
47.243.87.144:2181        $        setAcl /data1 ip:183.25.3.1:cdrwa
cZxid = 0xbb
ctime = Thu Jun 03 20:58:57 CST 2021
mZxid = 0xbb
mtime = Thu Jun 03 20:58:57 CST 2021
pZxid = 0xbb
cversion = 0
dataVersion = 0
aclVersion = 1
ephemeralOwner = 0x0
dataLength = 10
numChildren = 0
 
47.243.87.144:2181        $        get /data1
Authentication is not valid : /data1

acl super super administrator

To use the super permission, you need to modify zkServer.sh, add a super administrator, and restart zkServer.sh

Keywords: Zookeeper

Added by lihman on Sat, 30 Oct 2021 18:49:38 +0300