Zookeeper system model introduction

Table of contents

1. Data model

Two, the type of node

(1) Persistent nodes

(2) Persistent sequential nodes

(3) Temporary nodes

(4) Temporary sequential nodes 

3. Client command line

(1) Create a node

(2) Read node information

(3) delete

Fourth, check the node status

5. Monitoring mechanism

(1) Monitor node changes

(2) Monitor node value changes

6. ACL permission control

(1) Permission mode

(2) Authority object

(3) Authority

(4) Permission related commands


1. Data model

 The data stored in Zookeeper is composed of znodes. Znodes can also be called nodes.
They store data in the form of key-value pairs. The overall data structure is similar to a tree. It can
be compared with the Linux file system mode. The path starts with / .
Note that it is said that it stores data in the form of key-value pairs, and the key is the node
path of the znode, such as /first

Two, the type of node

The zookeeper node has a life cycle, which depends on the type of node. Node types are divided into persistent nodes, temporary nodes, and timing nodes. Specifically, the following four types of nodes can be generated

(1) Persistent nodes

 After the data node is created, it exists on the zookeeper server until there is an operation to actively clear the node

(2) Persistent sequential nodes

Consistent with persistent nodes, but with an additional feature, each parent node will maintain a sequence for its first-level child nodes, and record the order in which each child node was created

(3) Temporary nodes

 It is temporary and will not be stored on the zookeeper server all the time. That is to say, if the session fails, the node will be automatically cleared. Note that the session is invalid rather than the connection is disconnected. At the same time, it should also be noted that no child nodes can be created under the temporary node

(4) Temporary sequential nodes 

 The basic characteristics are consistent with the temporary nodes, and the sequential characteristics are also added on the basis of the temporary nodes

3. Client command line

(1) Create a node

create -s path(key)+data(value)
create -e path(key)+data(value)

-s: sequential node (default is persistent node without option)
-e: temporary node

Example: create -s /java opop

(2) Read node information

ls+path can know the node under the path
get+path can know the data content and attribute information of the specified node
set+path+data (value) to modify the value corresponding to the so-called key
Example: ls /
get /java
set /java asas

(3) delete

delete+path
Example: delete /java
Note that if the node contains child nodes, an error will be reported

Fourth, check the node status

Use the stat command to view the node status

状态属性               说明
czxid            表示该数据节点被创建时的事务ID
mzxid            表示该节点最后一次被更新时的事务ID
pzxid            表示该节点的子节点列表最后一次被修改时的事务ID
ctime            表示该节点的创建时间
mtime            表示该节点最后一次被更新的时间
version          数据节点的版本号
cversion         子节点的版本号
aversion         节点的ACL版本号
ephemeralOwner    创建该临时节点的回话SessionID,若该节点是持久节点,那么该属性就是0
dataLength        数据内容的长度
numChildren        当前节点的子节点个数

5. Monitoring mechanism

(1) Monitor node changes

If the ls -w path command uses watch, then what is monitored is the change of the node, not the change of the value.

Note: One host uses the monitoring mechanism, and the other host creates nodes

 

(2) Monitor node value changes

The get -w path watch monitoring mechanism can only be used once. If you want to use it next time, you must listen again. For example, the ls path watch command can only monitor the change of the node path once. If you want to monitor again, you need to execute ls again path watch command

 

6. ACL permission control

ACL permission control
permission mode + permission object + permission

Set permissions for each znode node, child nodes will not inherit the permissions of the parent node,
the client does not have the right to access a node, but can access its child nodes

(1) Permission mode

world There is only one user: anyone, representing everyone (default)
ip use ip address authentication
auth use added authenticated user authentication
digest use username: password authentication

(2) Authority object

IP is usually an IP address or IP segment, for example: "192.168.66.121"
Digest custom, usually "username: BASE64 (SHA-1 (username: password))"
World has only one ID: anyone
Super Consistent with Digest mode

(3) Authority

Permission ACL Abbreviation Description
CREATE c Can create child nodes
DELETE d Can delete child nodes (only lower level nodes)
READ r Can read node data and display child node list
WRITE w Can set node data
ADMIN a Can set node access control list permissions


(4) Permission related commands

getAcl read ACL permission
setAcl set permission
addauth add authentication user

 

Guess you like

Origin blog.csdn.net/gaoqiandr/article/details/130395429