Some things can not be changed by hard work. No matter how beautiful the design of RMB of 50 yuan is, it is not as attractive as that of 100 yuan.

https://p1-jj.byteimg.com/tos-cn-i-t2oaga2asx/gold-user-assets/2018/6/3/163c50e2d1a6adb4~tplv-t2oaga2asx-image.image

preface

Since the company is moving to a new office at the end of the year, I recently sent out my resume and found that interviewers are now asking about Dubbo, ZooKeeper, and high concurrency. Because the company does not use Dubbo, it only knows that Dubbo is a distributed framework for remote service invocation, and ZooKeeper coordinates services for distributed applications. Therefore, this week, I looked up the information and sorted out the zooKeeper learning notes.

Install the zookeeper

Installation reference links blog.csdn.net/qiunian1440…

Basic Command Operations

Start the ZK service

  • ./zkServer.sh start
[root@localhost bin]#./ zkserver. sh ZooKeeper JMX enabled by default Using config: /usr/home/zookeeper-3.4.11/bin/.. /conf/zoo.cfg Usage: ./zkServer.sh {start|start-foreground|stop|restart|status|upgrade|print-cmd}#You are prompted to start Zk with./ zkcli. sh start
./zkCli.sh start 
Copy the code

Check the ZK running status

  • ./zkServer.sh statusBecause I’ve already configured itzkCluster, so the state displayed here isleader
[root@localhost bin]# ./zkServer.sh status ZooKeeper JMX enabled by default Using config: The/usr/home/zookeeper - 3.4.11 / bin /.. /conf/zoo.cfg Mode: leaderCopy the code

Client links to ZK

[root@localhost bin]# ./zkCli.sh 
......
WatchedEvent state:SyncConnected type:None path:null
[zk: localhost:2181(CONNECTED) 0]
Copy the code

Help Displays the client help command

  • help
[zk: localhost:2181(CONNECTED) 0] help ZooKeeper -server host:port cmd args stat path [watch] set path data [version] ls path  [watch] delquota [-n|-b] path ls2 path [watch] setAcl path acl setquota -n|-b val path history redo cmdno printwatches on|off delete path [version] sync path listquota path rmr path get path [watch] create [-s] [-e] path data acl addauth scheme auth quit getAcl path close connect host:port [zk: localhost:2181(CONNECTED) 1]Copy the code

Ls check

  • lsView commands (niocoderIs the node created by my test cluster, the default is onlyzookeeperOne node)
[zk: localhost:2181(CONNECTED) 1] ls /
[niocoder, zookeeper]
[zk: localhost:2181(CONNECTED) 2] ls /zookeeper 
[quota]
[zk: localhost:2181(CONNECTED) 4] ls /zookeeper/quota
[]
Copy the code

Get Obtains node data and update information

  • getContent is empty
  • CZxid: indicates the ID of the node to be created
  • Ctime: creation time of a node
  • MZxid: changes the id of a controller
  • Mtime: changes the time of a controller
  • PZxid: indicates the ID of a child node
  • Cversion: indicates the version of a child node
  • Datspanning: Version of data for the current node
  • AclVersion: indicates the version of the permission
  • EphemeralOwner: Determines whether the node is temporary
  • DataLength: Indicates the length of data
  • NumChildren: indicates the number of child nodes
[zk: CZxid = 0x0 ctime = Thu Jan 01 00:00:00 UTC 1970 mZxid = 0x0 mtime = Thu Jan 01 00:00:00 UTC 1970 pZxid = 0x0 cversion = -1 dataVersion = 0 aclVersion = 0 ephemeralOwner = 0x0 dataLength = 0 numChildren = 1 [zk: localhost:2181(CONNECTED) 8]Copy the code

Stat Gets the updated information about the node

  • stat
[zk: localhost:2181(CONNECTED) 8] stat /zookeeper
cZxid = 0x0
ctime = Thu Jan 01 00:00:00 UTC 1970
mZxid = 0x0
mtime = Thu Jan 01 00:00:00 UTC 1970
pZxid = 0x0
cversion = -1
dataVersion = 0
aclVersion = 0
ephemeralOwner = 0x0
dataLength = 0
numChildren = 1
Copy the code

Ls2 Indicates the integration of the ls and stat commands

  • ls2
[zk: localhost:2181(CONNECTED) 10] ls2 /zookeeper
[quota]
cZxid = 0x0
ctime = Thu Jan 01 00:00:00 UTC 1970
mZxid = 0x0
mtime = Thu Jan 01 00:00:00 UTC 1970
pZxid = 0x0
cversion = -1
dataVersion = 0
aclVersion = 0
ephemeralOwner = 0x0
dataLength = 0
numChildren = 1
[zk: localhost:2181(CONNECTED) 11] 
Copy the code

Create Creates a node.

  • create [-s] [-e] path data aclNotice the changes in each version
#Create a MerryYou node whose content is MerryYou
[zk: localhost:2181(CONNECTED) 1] create /merryyou merryyou
Created /merryyou
#Get the merryYou node content
[zk: localhost:2181(CONNECTED) 3] get /merryyou
merryyou
cZxid = 0x200000004
ctime = Sat Jun 02 14:20:06 UTC 2018
mZxid = 0x200000004
mtime = Sat Jun 02 14:20:06 UTC 2018
pZxid = 0x200000004
cversion = 0
dataVersion = 0
aclVersion = 0
ephemeralOwner = 0x0
dataLength = 8
numChildren = 0
Copy the code

Create-e creates a temporary node

  • create -e
#Creating temporary Nodes
[zk: localhost:2181(CONNECTED) 4] create -e  /merryyou/temp merryyou
Created /merryyou/temp
[zk: localhost:2181(CONNECTED) 5] get /merryyou
merryyou
cZxid = 0x200000004
ctime = Sat Jun 02 14:20:06 UTC 2018
mZxid = 0x200000004
mtime = Sat Jun 02 14:20:06 UTC 2018
pZxid = 0x200000005
cversion = 1
dataVersion = 0
aclVersion = 0
ephemeralOwner = 0x0
dataLength = 8
numChildren = 1
[zk: localhost:2181(CONNECTED) 6] get /merryyou/temp
merryyou
cZxid = 0x200000005
ctime = Sat Jun 02 14:22:24 UTC 2018
mZxid = 0x200000005
mtime = Sat Jun 02 14:22:24 UTC 2018
pZxid = 0x200000005
cversion = 0
dataVersion = 0
aclVersion = 0
ephemeralOwner = 0x2000000d4500000
dataLength = 8
numChildren = 0
[zk: localhost:2181(CONNECTED) 7] 
#After the connection is disconnected and reconnected, the temporary node disappears automatically
WATCHER::

WatchedEvent state:SyncConnected type:None path:null
#The query temporary node still exists because of the default heartbeat mechanism
[zk: localhost:2181(CONNECTED) 0] ls /merryyou
[temp]
#The temporary node disappears
[zk: localhost:2181(CONNECTED) 1] ls /merryyou
[]
[zk: localhost:2181(CONNECTED) 2] 
Copy the code

Create-s Automatically accumulates the nodes in the creation sequence

  • create -s
#Create order nodes, which are automatically accumulated
[zk: localhost:2181(CONNECTED) 2] create -s /merryyou/sec seq
Created /merryyou/sec0000000001
[zk: localhost:2181(CONNECTED) 3] create -s /merryyou/sec seq
Created /merryyou/sec0000000002 
Copy the code

Set path data [version] Modifies a node

[zk: localhost:2181(CONNECTED) 6] get /merryyou
merryyou
cZxid = 0x200000004
ctime = Sat Jun 02 14:20:06 UTC 2018
mZxid = 0x200000004
mtime = Sat Jun 02 14:20:06 UTC 2018
pZxid = 0x200000009
cversion = 4
dataVersion = 0
aclVersion = 0
ephemeralOwner = 0x0
dataLength = 8
numChildren = 2
#Example Change the node content to new-merryyou[zk: localhost:2181(CONNECTED) 7] set /merryyou new-merryyou cZxid = 0x200000004 ctime = Sat Jun 02 14:20:06 UTC 2018 mZxid =  0x20000000a mtime = Sat Jun 02 14:29:23 UTC 2018 pZxid = 0x200000009 cversion = 4 dataVersion = 1 aclVersion = 0 ephemeralOwner = 0x0 dataLength = 12 numChildren = 2#When you query the node again, the node content is modified[zk: localhost:2181(CONNECTED) 8] get /merryyou new-merryyou cZxid = 0x200000004 ctime = Sat Jun 02 14:20:06 UTC 2018 mZxid =  0x20000000a mtime = Sat Jun 02 14:29:23 UTC 2018 pZxid = 0x200000009 cversion = 4 dataVersion = 1 aclVersion = 0 ephemeralOwner = 0x0 dataLength = 12 numChildren = 2#setUpdate the DatSpanning Optimistic lock based on the version number[zk: localhost:2181(CONNECTED) 9] set /merryyou test-merryyou 1 cZxid = 0x200000004 ctime = Sat Jun 02 14:20:06 UTC 2018 mZxid = 0x20000000b mtime = Sat Jun 02 14:31:30 UTC 2018 pZxid = 0x200000009 cversion = 4 dataVersion = 2 aclVersion = 0  ephemeralOwner = 0x0 dataLength = 13 numChildren = 2#Because the version number of the data has been changed to 2, use version number 1 again to modify the node commit error
[zk: localhost:2181(CONNECTED) 10] set /merryyou test-merryyou 1
version No is not valid : /merryyou
Copy the code

Delete path [version] Deletes a node

[zk: localhost:2181(CONNECTED) 13] delete /merryyou/sec000000000

sec0000000001   sec0000000002
[zk: localhost:2181(CONNECTED) 13] delete /merryyou/sec0000000001
[zk: localhost:2181(CONNECTED) 14] ls /merryyou
[sec0000000002]
[zk: localhost:2181(CONNECTED) 15] 
#Version number operation andsetA similar version
Copy the code

Watcher notification mechanism

Watcher events are triggered when each node changes, similar to mysql triggers. The Watcher in ZK is disposable and destroyed immediately after it is triggered. You can refer to blog.csdn.net/hohoo1990/a…

  • stat path [watch]Setting the Watch Event
  • get path [watch]Setting the Watch Event
  • The Watch event is triggered when a child node is created or deleted, but not when a child node is modified
Stat path [watch] Sets the watch event
#Add the Watch event
[zk: localhost:2181(CONNECTED) 18] stat /longfei watch
Node does not exist: /longfei
#The Watcher event is raised when the Longfei node is created
[zk: localhost:2181(CONNECTED) 19] create /longfei test

WATCHER::

WatchedEvent state:SyncConnected type:NodeCreated path:/longfei
Created /longfei
Copy the code
Get path [watch] Sets the watch event
#Use the get command to add the Watch event
[zk: localhost:2181(CONNECTED) 20] get /longfei watch
test
cZxid = 0x20000000e
ctime = Sat Jun 02 14:43:15 UTC 2018
mZxid = 0x20000000e
mtime = Sat Jun 02 14:43:15 UTC 2018
pZxid = 0x20000000e
cversion = 0
dataVersion = 0
aclVersion = 0
ephemeralOwner = 0x0
dataLength = 4
numChildren = 0
#Modify the node to trigger the Watcher event
[zk: localhost:2181(CONNECTED) 21] set /longfei new_test

WATCHER::

WatchedEvent state:SyncConnected type:NodeDataChanged path:/longfei
cZxid = 0x20000000e
ctime = Sat Jun 02 14:43:15 UTC 2018
mZxid = 0x20000000f
mtime = Sat Jun 02 14:45:06 UTC 2018
pZxid = 0x20000000e
cversion = 0
dataVersion = 1
aclVersion = 0
ephemeralOwner = 0x0
dataLength = 8
numChildren = 0
[zk: localhost:2181(CONNECTED) 22] 
#Delete the triggering watcher event[zk: localhost:2181(CONNECTED) 23] get /longfei watch new_test cZxid = 0x20000000e ctime = Sat Jun 02 14:43:15 UTC 2018 mZxid  = 0x20000000f mtime = Sat Jun 02 14:45:06 UTC 2018 pZxid = 0x20000000e cversion = 0 dataVersion = 1 aclVersion = 0 ephemeralOwner = 0x0 dataLength = 8 numChildren = 0 [zk: localhost:2181(CONNECTED) 24] delete /longfei WATCHER:: WatchedEvent state:SyncConnected type:NodeDeleted path:/longfei [zk: localhost:2181(CONNECTED) 25]Copy the code

ACL Permission Control

A ZK node has five operation permissions: CREATE, READ, WRITE, DELETE, and ADMIN (Add, DELETE, modify, search, and manage permissions). These five permissions are abbreviated as crwda(the initials of each word). Note: Among these five permissions, delete refers to the permission to delete child nodes, and the other four permissions refer to the operation permission of its own nodes

There are four methods of identity authentication:

  • world: The default mode, which means that the whole world can access
  • auth: indicates an authenticated user. On the CLI, run addauth digest user: PWD to add an authorized user in the current context.
  • digest: That is, user name: password authentication, which is the most commonly used in business systems
  • ip: Uses the Ip address for authentication

Use [Scheme: ID: Permissions] to represent ACL permissions

GetAcl: obtains the ACL permission information of a node
#Obtaining node permission Information The default value is World :cdrwa. Anyone can access it
[zk: localhost:2181(CONNECTED) 34] getAcl /merryyou
'world,'anyone
: cdrwa
[zk: localhost:2181(CONNECTED) 35] 
Copy the code
SetAcl Sets the permission
[zk: localhost:2181(CONNECTED) 35] create /merryyou/test test
Created /merryyou/test
[zk: localhost:2181(CONNECTED) 36] getAcl /merryyou/test
'world,'anyone
: cdrwa
#Setting node permissions CRWA cannot be deleted
[zk: localhost:2181(CONNECTED) 37] setAcl /merryyou/test world:anyone:crwa
cZxid = 0x200000018
ctime = Sat Jun 02 16:18:18 UTC 2018
mZxid = 0x200000018
mtime = Sat Jun 02 16:18:18 UTC 2018
pZxid = 0x200000018
cversion = 0
dataVersion = 0
aclVersion = 1
ephemeralOwner = 0x0
dataLength = 4
numChildren = 0
#Query the acl permission. Crwa Does not have the permission to delete the ACL
[zk: localhost:2181(CONNECTED) 38] getAcl /merryyou/test
'world,'anyone
: crwa
[zk: localhost:2181(CONNECTED) 39] 
[zk: localhost:2181(CONNECTED) 39] create /merryyou/test/abc abc
Created /merryyou/test/abc
#Insufficient commit permission when deleting a child node. Procedure
[zk: localhost:2181(CONNECTED) 40] delete /merryyou/test/abc
Authentication is not valid : /merryyou/test/abc
#Example Set the permission information of a node to RDA[zk: localhost:2181(CONNECTED) 41] setAcl /merryyou/test world:anyone:rda cZxid = 0x200000018 ctime = Sat Jun 02 16:18:18 UTC  2018 mZxid = 0x200000018 mtime = Sat Jun 02 16:18:18 UTC 2018 pZxid = 0x20000001a cversion = 1 dataVersion = 0 aclVersion = 2 ephemeralOwner = 0x0 dataLength = 4 numChildren = 1 [zk: localhost:2181(CONNECTED) 42] getAcl /merryyou/test 'world,'anyone : dra#Can be deleted successfully
[zk: localhost:2181(CONNECTED) 43] delete /merryyou/test/abc             
[zk: localhost:2181(CONNECTED) 46] ls /merryyou/test
[]
[zk: localhost:2181(CONNECTED) 47] 
#Example Set the node information to a admin
[zk: localhost:2181(CONNECTED) 47] setAcl /merryyou/test world:anyone:a  
cZxid = 0x200000018
ctime = Sat Jun 02 16:18:18 UTC 2018
mZxid = 0x200000018
mtime = Sat Jun 02 16:18:18 UTC 2018
pZxid = 0x20000001d
cversion = 2
dataVersion = 0
aclVersion = 3
ephemeralOwner = 0x0
dataLength = 4
numChildren = 0
#Access Settings prompt insufficient permissions
[zk: localhost:2181(CONNECTED) 49] get /merryyou/test
Authentication is not valid : /merryyou/test
[zk: localhost:2181(CONNECTED) 50] set /merryyou/test 123
Authentication is not valid : /merryyou/test
[zk: localhost:2181(CONNECTED) 51] 
Copy the code
Acl Auth Specifies the password in plaintext
[zk: localhost:2181(CONNECTED) 53] create /niocoder/merryyou merryyou
Created /niocoder/merryyou
#Example Query the permission information of the default controller
[zk: localhost:2181(CONNECTED) 54] getAcl /niocoder/merryyou
'world,'anyone
: cdrwa
[zk: localhost:2181(CONNECTED) 55] 
#Use auth to set node permission information
[zk: localhost:2181(CONNECTED) 2] setAcl /niocoder/merryyou auth:test:test:cdrwa  
Acl is not valid : /niocoder/merryyou
#registeredtest:testThe account password
[zk: localhost:2181(CONNECTED) 3] addauth digest test:test
[zk: localhost:2181(CONNECTED) 4] setAcl /niocoder/merryyou auth:test:test:cdrwa
cZxid = 0x200000020
ctime = Sat Jun 02 16:32:08 UTC 2018
mZxid = 0x200000020
mtime = Sat Jun 02 16:32:08 UTC 2018
pZxid = 0x200000020
cversion = 0
dataVersion = 0
aclVersion = 1
ephemeralOwner = 0x0
dataLength = 8
numChildren = 0
#The password for querying node permission information is in ciphertext
[zk: localhost:2181(CONNECTED) 5] getAcl /niocoder/merryyou
'digest,'test:V28q/NynI4JI3Rk54h0r8O5kMug=
: cdrwa
[zk: localhost:2181(CONNECTED) 6] 
Copy the code
Acl Digest Specifies the ciphertext password
[zk: localhost:2181(CONNECTED) 13] create /names test
Created /names
[zk: localhost:2181(CONNECTED) 14] getAcl /names
'world,'anyone
: cdrwa
#Use digest to set the permission information of a node totestcipher
[zk: localhost:2181(CONNECTED) 15] setAcl /names digest:test:V28q/NynI4JI3Rk54h0r8O5kMug=:cdra
cZxid = 0x400000006
ctime = Sun Jun 03 01:01:17 UTC 2018
mZxid = 0x400000006
mtime = Sun Jun 03 01:01:17 UTC 2018
pZxid = 0x400000006
cversion = 0
dataVersion = 0
aclVersion = 1
ephemeralOwner = 0x0
dataLength = 4
numChildren = 0
#Example Query the permission information of a node
[zk: localhost:2181(CONNECTED) 16] getAcl /names
'digest,'test:V28q/NynI4JI3Rk54h0r8O5kMug=
: cdra
#Insufficient permission is displayed when obtaining node information
[zk: localhost:2181(CONNECTED) 5] get /names
Authentication is not valid : /names
#Sign up for an account
[zk: localhost:2181(CONNECTED) 4] addauth digest test:test
#Available as normal
[zk: localhost:2181(CONNECTED) 17] get /names          
test
cZxid = 0x400000006
ctime = Sun Jun 03 01:01:17 UTC 2018
mZxid = 0x400000006
mtime = Sun Jun 03 01:01:17 UTC 2018
pZxid = 0x400000006
cversion = 0
dataVersion = 0
aclVersion = 1
ephemeralOwner = 0x0
dataLength = 4
numChildren = 0
#Node W cannot be modified because the write permission is not set
[zk: localhost:2181(CONNECTED) 18] set /names 111
Authentication is not valid : /names
[zk: localhost:2181(CONNECTED) 19] delete /names
[zk: localhost:2181(CONNECTED) 20] 
Copy the code
Acl IP control client
[zk: localhost:2181(CONNECTED) 22] create /niocoder/ip aa
Created /niocoder/ip
[zk: localhost:2181(CONNECTED) 23] get /niocoder/ip
aa
cZxid = 0x40000000a
ctime = Sun Jun 03 01:06:47 UTC 2018
mZxid = 0x40000000a
mtime = Sun Jun 03 01:06:47 UTC 2018
pZxid = 0x40000000a
cversion = 0
dataVersion = 0
aclVersion = 0
ephemeralOwner = 0x0
dataLength = 2
numChildren = 0
#Example Add the permission information of IP control[zk: Localhost :2181(CONNECTED) 24] setAcl /niocoder/ IP IP :192.168.0.68:cdrwa cZxid = 0x40000000a ctime = Sun Jun 03 01:06:47 UTC 2018 mZxid = 0x40000000a mtime = Sun Jun 03 01:06:47 UTC 2018 pZxid = 0x40000000a cversion = 0 dataVersion = 0 aclVersion = 1 ephemeralOwner = 0x0 dataLength = 2 numChildren = 0 [zk: Localhost :2181(CONNECTED) 25] getAcl /niocoder/ IP 'IP,'192.168.0.68: cdrwa [zk: localhost:2181(CONNECTED) 26]Copy the code
Acl super Super administrator

To use the super permission, modify zkserver. sh, add the super administrator, and restart zkserver. sh

"-Dzookeeper.DigestAuthenticationProvider.superDigest=test:V28q/NynI4JI3Rk54h0r8O5kMug="
 nohup "$JAVA" "-Dzookeeper.log.dir=${ZOO_LOG_DIR}" "-Dzookeeper.root.logger=${ZOO_LOG4J_PROP}" "-Dzookeeper.DigestAuthenticationprovider.superDigest=test:V28q/NynI4JI3Rk54h0r8O5kMug=" \
    -cp "$CLASSPATH" $JVMFLAGS $ZOOMAIN "$ZOOCFG" > "$_ZOO_DAEMON_OUT" 2>&1 < /dev/null &

#Restart the zkCli
#Access is not allowed because the IP permission was set earlier
[zk: localhost:2181(CONNECTED) 2] ls /niocoder/ip
Authentication is not valid : /niocoder/ip
#The login account is the administrator account
[zk: localhost:2181(CONNECTED) 3] addauth digest test:test
#Normal access, node content is empty
[zk: localhost:2181(CONNECTED) 4] ls /niocoder/ip
[]
[zk: localhost:2181(CONNECTED) 5] get /niocoder/ip
aa
cZxid = 0x40000000a
ctime = Sun Jun 03 01:06:47 UTC 2018
mZxid = 0x40000000a
mtime = Sun Jun 03 01:06:47 UTC 2018
pZxid = 0x40000000a
cversion = 0
dataVersion = 0
aclVersion = 1
ephemeralOwner = 0x0
dataLength = 2
numChildren = 0
[zk: localhost:2181(CONNECTED) 6] 
Copy the code

Four Letter Words

  • Installation is required to use the four-word commandncCommand,yum install nc)
Stat Displays status information
[root @ localhost bin] # echo stat | nc 192.168.0.68 2181 Zookeeper version: 3.4.11 to 37 e277162d567b55a07d1755f0b31c32e93c01a0, built on 11/01/2017 18:06 GMT Clients: /192.168.0.68:49346[0](queued=0,recved=1,sent=0) Latency min/ AVg/Max: 0/0/4 Received: 62 sent: 61 Connections: 1 Outstanding: 0 Zxid: 0x50000000a Mode: follower Node count: 10 [root@localhost bin]#Copy the code
Ruok Checks whether ZooKeeper is started
[root @ localhost bin] # echo ruok | nc 192.168.0.68 2181 imok [root @ localhost bin] #Copy the code
Dump lists nodes that are not processed, temporary nodes
Imok [root @ localhost bin] # echo dump | nc 192.168.0.68 2181 SessionTracker dump: org.apache.zookeeper.server.quorum.LearnerSessionTracker@29805957 ephemeral nodes dump: Sessions with Ephemerals (0): [root@localhost bin]#Copy the code
Conf Displays the server configuration
[root @ localhost bin] # echo the conf | nc 192.168.0.68 clientPort = 2181 dataDir = 2181 / usr/home/zookeeper - 3.4.11 / data/version - 2 DataLogDir = / usr/home/zookeeper - 3.4.11 tickTime/data/version - 2 = 2000 maxClientCnxns = 60 minSessionTimeout = 4000 maxSessionTimeout=40000 serverId=2 initLimit=10 syncLimit=5 electionAlg=3 electionPort=3888 quorumPort=2888 peerType=0 [root@localhost bin]#Copy the code
Cons Displays information about connections to the server
[root @ localhost bin] # echo cons | 2181 / nc 192.168.0.68 192.168.0.68:49354 [0] (queued = 0, recved = 1, sent = 0) [root @ localhost bin]#Copy the code
Envi Displays information about environment variables
[root @ localhost bin] # echo envi | nc 192.168.0.68 2181 Environment: Zookeeper. Version = e277162d567b55a07d1755f0b31c32e93c01a0 3.4.11 to 37, Name =localhost java.version=1.8.0_111 java.vendor=Oracle Corporation built on 11/01/2017 18:06 GMT how.name =localhost java.version=1.8.0_111 java.vendor=Oracle Corporation Java. Home = / usr/local/jdk1.8.0 _111 / jre Java class. The path = / usr/home/zookeeper - 3.4.11 / bin /.. / build/classes: / usr/home/zookeeper - 3.4.11 / bin /.. / build/lib / *. The jar: / usr/home/zookeeper - 3.4.11 / bin /.. / lib/slf4j - log4j12-1.6.1. Jar: / usr/home/zookeeper - 3.4.11 / bin /.. / lib/slf4j - API - 1.6.1. Jar: / usr/home/zookeeper - 3.4.11 / bin /.. / lib/netty - 3.10.5. Final. Jar: / usr/home/zookeeper - 3.4.11 / bin /.. / lib/log4j - 1.2.16. Jar: / usr/home/zookeeper - 3.4.11 / bin /.. / lib/jline - 0.9.94. Jar: / usr/home/zookeeper - 3.4.11 / bin /.. . / lib/on - annotations - 0.5.0 jar: / usr/home/zookeeper - 3.4.11 / bin /.. / zookeeper - 3.4.11. Jar: / usr/home/zookeeper - 3.4.11 / bin /.. / SRC/Java/lib / *. The jar: / usr/home/zookeeper - 3.4.11 / bin /.. /conf: java.library.path=/usr/java/packages/lib/amd64:/usr/lib64:/lib64:/lib:/usr/lib java.io.tmpdir=/tmp java.compiler=<NA> Arch =amd64 os.version=3.10.0-514.10.2.el7.x86_64 user.name=root user.home=/root User. Dir = / usr/home/zookeeper - 3.4.11 / bin/root @ localhost bin] #Copy the code
MNTR Views zK’s health information
[root @ localhost bin] # echo MNTR | nc 192.168.0.68 2181 zk_version e277162d567b55a07d1755f0b31c32e93c01a0 3.4.11 to 37, built on 11/01/2017 18:06 GMT zk_avg_latency 0 zk_max_latency 4 zk_min_latency 0 zk_packets_received 68 zk_packets_sent 67 zk_num_alive_connections 1 zk_outstanding_requests 0 zk_server_state follower zk_znode_count 10 zk_watch_count 0 zk_ephemerals_count 0 zk_approximate_data_size 124 zk_open_file_descriptor_count 32 zk_max_file_descriptor_count 4096 [root@localhost bin]#Copy the code
WCHS displays information about the watch
[root @ localhost bin] # echo WCHS | nc 192.168.0.68 2181 connections watching 0 paths Total watches: 0 [root @ localhost bin]#Copy the code
WCHC and WCHP Displays the watch information of the session
  • Need to configurezoo.cfgAdd to file4lw.commands.whitelist=*
[root @ localhost bin] # echo WCHC | nc 192.168.0.68 2181 WCHC is not executed because it is not in the whitelist. [root @ localhost bin] # echo WCHP | nc 192.168.0.68 2181 WCHP is not executed because it is not in the whitelist.Copy the code

conclusion

After you are familiar with basic ZooKeeper commands, you can use apis provided by ZooKeeper or encapsulated by a third-party.

Recommend the article

  1. Java creates the blockchain family
  2. Spring Security source code analysis series
  3. Spring Data Jpa series
  4. All about Trees in Data Structures (Java Edition)
  5. SpringBoot+Docker+Git+Jenkins realize easy continuous integration and continuous deployment

https://p1-jj.byteimg.com/tos-cn-i-t2oaga2asx/gold-user-assets/2018/5/27/163a194a87e01e0c~tplv-t2oaga2asx-image.image

🙂🙂🙂 focus on wechat small program Java architect journey Bored on the commute? Still reading novels, news? Don’t know how to improve your skills? Here’s the Java architecture article you need. 1.5W + Java engineers are reading it. What are you waiting for?


Copy the code