define

ZooKeeper is a software project of the Apache Software Foundation that provides open source distributed configuration services, synchronization services, and naming registries for large-scale distributed computing.

Zookeeper data structure

Zookkeeper provides namespaces that are very similar to standard file systems, stored as key-values. The name key is a series of path elements separated by slash /. Each node in the ZooKeeper namespace is identified by a path.

As shown in the preceding figure, the root path is / /app1/ app1/name /app1/desc /app2/name

Use Docker to build the ZooKeeper container

Docker pull zookeeper: 3.4 docker run - d - name zookeeper -p 2181:2181 - v/etc/localtime: / etc/localtime zookeeper: 3.4 Enter the container Docker exec-it 9ce28A0FE383 shCopy the code

restart

root@9ce28a0fe383:/zookeeper-3.4.14/bin# sh zkserver. sh restart /conf/zoo. CFG zookeeper JMX enabled by default Using config: /conf/zoo.cfg ZooKeeper JMX enabled by default Using config: /conf/zoo.cfg Stopping zookeeper ... no zookeeper to stop (could not find file /data/zookeeper_server.pid) ZooKeeper JMX enabled by default Using config: /conf/zoo.cfg Starting zookeeper ... STARTEDCopy the code

Check the status

root@9ce28a0fe383:/zookeeper-3.4.14/bin# sh zkserver. sh status zookeeper JMX enabled by default Using config: /conf/zoo.cfg Mode: standaloneCopy the code

The connection

root@9ce28a0fe383:/zookeeper-3.4.14/bin# sh zkcli. sh-server 127.0.0.1:2181 Connecting to 127.0.0.1:2181 2021-04-18 04:07:56,680 [myID :] -info [main:Environment@100] -client Environment: the zookeeper. Version = c25d480e66aadd371de8bd2fd8da255ac140bcf 3.4.14-4, Built on 03/06/2019 16:18 GMT 2021-04-18 04:07:56.688 [myID :] -info [main:Environment@100] -client Environment: host-name = 9CE28A0FE383 2021-04-18 04:07:56.689 [myID :] -info [main:Environment@100] -client Environment :java.version=1.8.0_282 2021-04-18 04:07:56,700 [myID :] -info [main:Environment@100] -client Environment: Java. vendor=Oracle Corporation 2021-04-18 04:07:56.701 [myID :] -info [main:Environment@100] -client Environment :java.home= /usr/local/openJDK-8 2021-04-18 04:07:56.701 [myID :] -info [main:Environment@100] -client Environment: Java. Class. Path = / zookeeper - 3.4.14 / bin /.. / zookeeper server/target/classes: / zookeeper - 3.4.14 / bin /.. / build/classes: / zookeeper - 3.4.14 / bin /.. / zookeeper server/target/lib / *. The jar: / zookeeper - 3.4.14 / bin /.. / build/lib / *. The jar: / zookeeper - 3.4.14 / bin /.. . / lib/slf4j - log4j12-1.7.25 jar: / zookeeper - 3.4.14 / bin /.. . / lib/slf4j - API - 1.7.25 jar: / zookeeper - 3.4.14 / bin /.. / lib/netty - 3.10.6. Final. Jar: / zookeeper - 3.4.14 / bin /.. / lib/log4j - 1.2.17. Jar: / zookeeper - 3.4.14 / bin /.. / lib/jline - 0.9.94. Jar: / zookeeper - 3.4.14 / bin /.. . / lib/on - annotations - 0.5.0 jar: / zookeeper - 3.4.14 / bin /.. / zookeeper - 3.4.14. Jar: / zookeeper - 3.4.14 / bin /.. /zookeeper-server/src/main/resources/lib/*.jar:/conf: 2021-04-18 04:07:56,702 [myID :] -info [main:Environment@100] -client Environment: Java. Library. The path = / usr/Java/packages/lib/amd64: / usr/lib64: / lib64: / lib: / usr/lib 04:07:56 2021-04-18, 702 [myid:] - INFO [main: Environment @ 100] - Client Environment: Java. IO. Tmpdir = / TMP 04:07:56 2021-04-18, 703 [myid:] - INFO [main: Environment @ 100] - Client environment:java.com piler = < NA > 2021-04-18 04:07:56, 703 [myid:] - INFO [main:Environment@100] -client environment:os.name=Linux 2021-04-18 04:07:56.704 [myID :] -info [main:Environment@100] Arch = AMD64 2021-04-18 04:07:56,704 [myID :] -info [main:Environment@100] -client Environment: OS.version = 4.19.121-LinuxKit 2021-04-18 04:07:56:705 [myID :] -info [main:Environment@100] -client Environment :user.name=root 2021-04-18 04:07:56,705 [myID :] -info [main:Environment@100] -client Environment :user.home=/root 2021-04-18 04:07:56.706 [myID :] -info [main:Environment@100] -client Environment :user.dir=/zookeeper-3.4.14/bin 2021-04-18 04:07:56,710 [myID :] -info [main:ZooKeeper@442] - Initiating the virtual state client connection, ConnectString = 127.0.0.1:2181 30000 watcher sessionTimeout = = org. Apache. The zookeeper. ZooKeeperMain $5 ce65a89 MyWatcher @ the Welcome to ZooKeeper! 2021-04-18 04:07:56,762 [myID :] -info [main-sendThread (localhost:2181):ClientCnxn$SendThread@1025] -opening socket Connection to server localhost / 127.0.0.1:2181 Will not attempt to authenticate using SASL (unknown error) JLine support Is enabled 2021-04-18 04:07:56,872 [myID :] -info [main-sendThread (localhost:2181):ClientCnxn$SendThread@879] -socket The connection established to localhost / 127.0.0.1:2181, initiating the session [zk: 127.0.1:2181 (CONNECTING) 0] 21-04-18 04:07:56,947 [myID :] -info [main-SendThread(localhost:2181):ClientCnxn$SendThread@1299] - Session establishment complete on server Localhost / 127.0.0.1:2181, sessionid = 0 x10002845bf60000, negotiated a timeout = 30000Copy the code

Common command

[zk: 127.0.0.1:2181(CONNECTED) 1] ls /zookeeper [zk: 127.0.0.1:2181(CONNECTED) 2] ls /zookeeper [quota] [zk: 127.0.0.1:2181(CONNECTED) 2] ls /zookeeper [quota] [zk: 127.0.0.1:2181(CONNECTED) 2] 127.0.0.1:2181(CONNECTED) 3] ls/Zookeeper /quota []Copy the code

Related command parameters

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:portCopy the code