1. Cluster roles and division of labor
-
Leader leaders
The leader node in the cluster.Copy the code
-
Flower follower
Followers participate in elections and data synchronization.Copy the code
-
The observer observers
Observer nodes have business data but do not participate in elections. Thus, data synchronization and election efficiency can be ensured.Copy the code
2. Common commands
-
Starting a Service Node
./zkServer.sh start .. /conf/zoo.cfgCopy the code
-
Viewing node Status (Primary/Secondary)
./zkServer.sh status Copy the code
-
Start the client connection
. / zkCli. Sh - server 127.0.0.1:2181Copy the code
-
List the nodes
ls / Copy the code
-
Create a node
create /test 'content' Copy the code
-
Create temporary nodes (children cannot be created under temporary nodes)
create -e /test-e 'content' Copy the code
-
Creating sequence nodes
Create -s/TEST_SEq_ 1 The result shows: Created/TEST_SEq_0000000001Copy the code
-
Obtaining node content
get /test Copy the code
-
Viewing Node Information
Stat /test: Ctime = Mon Apr 26 12:28:29 CST 2021 mZxid = 0x8b mtime = Mon Apr 26 12:28:29 CST 2021 # Time of node change pZxid = 0x8B # Transaction ID of node increase, Delete, change Cversion = 0 # Number of changes on this node datLVersion = 0 # Number of changes on this node data EphemeralOwner = 0x0 # The value is 0 or the sessionID of the temporary node dataLength = 1 # The length of the data on the node numChildren = 0 # The number of child nodesCopy the code
-
Remove nodes
Delete /test # Delete current node RMR /test # Cascade delete nodeCopy the code
-
Viewing Node Rights
GetAcl /test results show :' World,'anyone: Cdrwa ACL permission control, identified by Schmea: ID: Permission, mainly covers three aspects: - Permission Schema: authentication policy - Authorization object (ID) - Permission schema. world: only one user; Anyone represents everyone (default). IP: authenticate with an IP address. Auth: authenticate with an authenticated user. Use "Username: DELETE d can DELETE the child node. READ R can READ the node data. WRITE W can set the node data. You can set access control lists for nodesCopy the code
-
Add user
addauth digest zhangsan:123456 Copy the code
3. The other
-
The maximum size of each node is 1 MB by default
-
A child node does not inherit the permissions of its parent node. A client may not have access to a node, but can access its children.
-
Zookeeper native client listeners can only listen to new ZooKeeper () once.
-
The operations that can register listeners are getData(),
-
Use the ZkClient client
4. Set up a cluster
Prepare three VMS. Node1 IP 192.168.108.13 Node2 IP 192.168.108.11 Node3 IP 192.168.108.8 2. Download ZooKeeper 3 from the Apache website. CFG file and name it zoo_sample. CFG 4. Modify the dataDir path. 5. Create the myID file 6 in the dataDir path. CFG file. Server. 1=192.168.108.13:2888:3888 server.2=192.168.108.11:2888:3888 server.3=192.168.108.8:2888:3888 Ps: Enter the server IP address. Unable to read Additional data from server sessionID 0x0, likely Server has closed socket, closing socket connection and attempting reconnectCopy the code