basic data model
It is a tree structure, similar to the data model of the tree.js component
zookeeper in front-end development. It can also be understood as the file directory of linux/unix: /usr/local
Each node is called a znode, which can have child nodes. There can also be data.
Each node is divided into temporary nodes and permanent nodes. The temporary node disappears after the client is disconnected.
Each zookeeper node has its own version number, and the node information can be displayed through the command line.
Whenever the node data changes, Then the version number of the node will be accumulated (optimistic lock).
When deleting/modifying outdated nodes, the version number will not match and an error will be reported. The data stored in
each zookeeper node should not be too large, just a few K. The
node can set the permission acl, which can be set through the permission. Restrict user access
Basic Data Model Basic Operations
Client connection
Use ./zkCli.sh to connect, as shown in the figure
You can use the help command to view the supported commands
ls
Check the specified directory to see which paths are in the directory. The
newly installed zookeeper has only the /zookeeper/quota directory, and the directory is empty.
You can use the following command to query
ls /
ls /zookeeper
ls /zookeeper/quota as shown in the
figure
close client connection
ctrl + c exits the client link
The role of zookeeper
role one
The master node is elected. After the master node hangs up, the slave node will take over the work and ensure that this node is unique. This is the so-called head mode, which ensures that our cluster is highly available.
role two
Unified configuration file management, that is, only one server needs to be deployed, and the same configuration file can be updated to all other servers synchronously. This operation is particularly used in cloud computing (for example, the unified configuration of redis is modified)
role three
Publish and subscribe, similar to the message queue MQ (amq, rmq), the dubbo publisher stores the data on the znode, and the subscriber will read the data
Function four
Provides distributed locks, where different processes compete for resources in a distributed environment, similar to locks in multithreading
Function five
Cluster management, ensuring strong data consistency in the cluster