zookeeper客户端命令行操作

           zookeeper客户端命令行操作

                               作者:尹正杰

版权声明:原创作品,谢绝转载!否则将追究法律责任。

 

 

 

一.zookeeper的命令行基础操作

1>.连接到zookeeper服务器

[root@hadoop101.yinzhengjie.org.cn ~]# zkCli.sh 
/yinzhengjie/softwares/jdk1.8.0_201/bin/java
Connecting to localhost:2181
2020-05-12 06:58:25,541 [myid:] - INFO  [main:Environment@98] - Client environment:zookeeper.version=3.6.1--104dcb3e3fb464b30c5186d229e00af9f332524b, built on 04/21/2020 15:01 GMT
2020-05-12 06:58:25,543 [myid:] - INFO  [main:Environment@98] - Client environment:host.name=hadoop101.yinzhengjie.org.cn
2020-05-12 06:58:25,544 [myid:] - INFO  [main:Environment@98] - Client environment:java.version=1.8.0_201
2020-05-12 06:58:25,545 [myid:] - INFO  [main:Environment@98] - Client environment:java.vendor=Oracle Corporation
2020-05-12 06:58:25,545 [myid:] - INFO  [main:Environment@98] - Client environment:java.home=/yinzhengjie/softwares/jdk1.8.0_201/jre
2020-05-12 06:58:25,545 [myid:] - INFO  [main:Environment@98] - Client environment:java.class.path=/yinzhengjie/softwares/zookeeper/bin/../zookeeper-server/target/classes:/yinzhengjie/softwares/zookeeper/bin/../build/classes:/yinzhengjie/softwares/zookeeper/bin/../zooke
eper-server/target/lib/*.jar:/yinzhengjie/softwares/zookeeper/bin/../build/lib/*.jar:/yinzhengjie/softwares/zookeeper/bin/../lib/zookeeper-prometheus-metrics-3.6.1.jar:/yinzhengjie/softwares/zookeeper/bin/../lib/zookeeper-jute-3.6.1.jar:/yinzhengjie/softwares/zookeeper/bin/../lib/zookeeper-3.6.1.jar:/yinzhengjie/softwares/zookeeper/bin/../lib/snappy-java-1.1.7.jar:/yinzhengjie/softwares/zookeeper/bin/../lib/slf4j-log4j12-1.7.25.jar:/yinzhengjie/softwares/zookeeper/bin/../lib/slf4j-api-1.7.25.jar:/yinzhengjie/softwares/zookeeper/bin/../lib/simpleclient_servlet-0.6.0.jar:/yinzhengjie/softwares/zookeeper/bin/../lib/simpleclient_hotspot-0.6.0.jar:/yinzhengjie/softwares/zookeeper/bin/../lib/simpleclient_common-0.6.0.jar:/yinzhengjie/softwares/zookeeper/bin/../lib/simpleclient-0.6.0.jar:/yinzhengjie/softwares/zookeeper/bin/../lib/netty-transport-native-unix-common-4.1.48.Final.jar:/yinzhengjie/softwares/zookeeper/bin/../lib/netty-transport-native-epoll-4.1.48.Final.jar:/yinzhengjie/softwares/zookeeper/bin/../lib/netty-transport-4.1.48.Final.jar:/yinzhengjie/softwares/zookeeper/bin/../lib/netty-resolver-4.1.48.Final.jar:/yinzhengjie/softwares/zookeeper/bin/../lib/netty-handler-4.1.48.Final.jar:/yinzhengjie/softwares/zookeeper/bin/../lib/netty-common-4.1.48.Final.jar:/yinzhengjie/softwares/zookeeper/bin/../lib/netty-codec-4.1.48.Final.jar:/yinzhengjie/softwares/zookeeper/bin/../lib/netty-buffer-4.1.48.Final.jar:/yinzhengjie/softwares/zookeeper/bin/../lib/metrics-core-3.2.5.jar:/yinzhengjie/softwares/zookeeper/bin/../lib/log4j-1.2.17.jar:/yinzhengjie/softwares/zookeeper/bin/../lib/json-simple-1.1.1.jar:/yinzhengjie/softwares/zookeeper/bin/../lib/jline-2.11.jar:/yinzhengjie/softwares/zookeeper/bin/../lib/jetty-util-9.4.24.v20191120.jar:/yinzhengjie/softwares/zookeeper/bin/../lib/jetty-servlet-9.4.24.v20191120.jar:/yinzhengjie/softwares/zookeeper/bin/../lib/jetty-server-9.4.24.v20191120.jar:/yinzhengjie/softwares/zookeeper/bin/../lib/jetty-security-9.4.24.v20191120.jar:/yinzhengjie/softwares/zookeeper/bin/../lib/jetty-io-9.4.24.v20191120.jar:/yinzhengjie/softwares/zookeeper/bin/../lib/jetty-http-9.4.24.v20191120.jar:/yinzhengjie/softwares/zookeeper/bin/../lib/javax.servlet-api-3.1.0.jar:/yinzhengjie/softwares/zookeeper/bin/../lib/jackson-databind-2.10.3.jar:/yinzhengjie/softwares/zookeeper/bin/../lib/jackson-core-2.10.3.jar:/yinzhengjie/softwares/zookeeper/bin/../lib/jackson-annotations-2.10.3.jar:/yinzhengjie/softwares/zookeeper/bin/../lib/commons-lang-2.6.jar:/yinzhengjie/softwares/zookeeper/bin/../lib/commons-cli-1.2.jar:/yinzhengjie/softwares/zookeeper/bin/../lib/audience-annotations-0.5.0.jar:/yinzhengjie/softwares/zookeeper/bin/../zookeeper-*.jar:/yinzhengjie/softwares/zookeeper/bin/../zookeeper-server/src/main/resources/lib/*.jar:/yinzhengjie/softwares/zookeeper/bin/../conf:2020-05-12 06:58:25,545 [myid:] - INFO  [main:Environment@98] - Client environment:java.library.path=/usr/java/packages/lib/amd64:/usr/lib64:/lib64:/lib:/usr/lib
2020-05-12 06:58:25,577 [myid:] - INFO  [main:Environment@98] - Client environment:java.io.tmpdir=/tmp
2020-05-12 06:58:25,578 [myid:] - INFO  [main:Environment@98] - Client environment:java.compiler=<NA>
2020-05-12 06:58:25,578 [myid:] - INFO  [main:Environment@98] - Client environment:os.name=Linux
2020-05-12 06:58:25,578 [myid:] - INFO  [main:Environment@98] - Client environment:os.arch=amd64
2020-05-12 06:58:25,578 [myid:] - INFO  [main:Environment@98] - Client environment:os.version=3.10.0-957.el7.x86_64
2020-05-12 06:58:25,578 [myid:] - INFO  [main:Environment@98] - Client environment:user.name=root
2020-05-12 06:58:25,578 [myid:] - INFO  [main:Environment@98] - Client environment:user.home=/root
2020-05-12 06:58:25,578 [myid:] - INFO  [main:Environment@98] - Client environment:user.dir=/root
2020-05-12 06:58:25,578 [myid:] - INFO  [main:Environment@98] - Client environment:os.memory.free=237MB
2020-05-12 06:58:25,579 [myid:] - INFO  [main:Environment@98] - Client environment:os.memory.max=245MB
2020-05-12 06:58:25,579 [myid:] - INFO  [main:Environment@98] - Client environment:os.memory.total=245MB
2020-05-12 06:58:25,583 [myid:] - INFO  [main:ZooKeeper@1005] - Initiating client connection, connectString=localhost:2181 sessionTimeout=30000 watcher=org.apache.zookeeper.ZooKeeperMain$MyWatcher@379619aa
2020-05-12 06:58:25,587 [myid:] - INFO  [main:X509Util@77] - Setting -D jdk.tls.rejectClientInitiatedRenegotiation=true to disable client-initiated TLS renegotiation
2020-05-12 06:58:25,592 [myid:] - INFO  [main:ClientCnxnSocket@239] - jute.maxbuffer value is 1048575 Bytes
2020-05-12 06:58:25,598 [myid:] - INFO  [main:ClientCnxn@1703] - zookeeper.request.timeout value is 0. feature enabled=false
Welcome to ZooKeeper!
2020-05-12 06:58:25,634 [myid:localhost:2181] - INFO  [main-SendThread(localhost:2181):ClientCnxn$SendThread@1154] - Opening socket connection to server localhost/127.0.0.1:2181.
2020-05-12 06:58:25,635 [myid:localhost:2181] - INFO  [main-SendThread(localhost:2181):ClientCnxn$SendThread@1156] - SASL config status: Will not attempt to authenticate using SASL (unknown error)
JLine support is enabled
2020-05-12 06:58:25,734 [myid:localhost:2181] - INFO  [main-SendThread(localhost:2181):ClientCnxn$SendThread@986] - Socket connection established, initiating session, client: /127.0.0.1:35091, server: localhost/127.0.0.1:2181
2020-05-12 06:58:25,771 [myid:localhost:2181] - INFO  [main-SendThread(localhost:2181):ClientCnxn$SendThread@1420] - Session establishment complete on server localhost/127.0.0.1:2181, session id = 0x650000590d540001, negotiated timeout = 30000

WATCHER::

WatchedEvent state:SyncConnected type:None path:null
[zk: localhost:2181(CONNECTED) 0] 
[zk: localhost:2181(CONNECTED) 0] ls /
[zookeeper]
[zk: localhost:2181(CONNECTED) 1] 
[root@hadoop101.yinzhengjie.org.cn ~]# zkCli.sh                          #默认连接到本地的zookeeper服务器
[root@hadoop101.yinzhengjie.org.cn ~]# zkCli.sh -server hadoop102.yinzhengjie.org.cn
/yinzhengjie/softwares/jdk1.8.0_201/bin/java
Connecting to hadoop102.yinzhengjie.org.cn
2020-05-12 06:59:14,895 [myid:] - INFO  [main:Environment@98] - Client environment:zookeeper.version=3.6.1--104dcb3e3fb464b30c5186d229e00af9f332524b, built on 04/21/2020 15:01 GMT
2020-05-12 06:59:14,898 [myid:] - INFO  [main:Environment@98] - Client environment:host.name=hadoop101.yinzhengjie.org.cn
2020-05-12 06:59:14,898 [myid:] - INFO  [main:Environment@98] - Client environment:java.version=1.8.0_201
2020-05-12 06:59:14,899 [myid:] - INFO  [main:Environment@98] - Client environment:java.vendor=Oracle Corporation
2020-05-12 06:59:14,899 [myid:] - INFO  [main:Environment@98] - Client environment:java.home=/yinzhengjie/softwares/jdk1.8.0_201/jre
2020-05-12 06:59:14,899 [myid:] - INFO  [main:Environment@98] - Client environment:java.class.path=/yinzhengjie/softwares/zookeeper/bin/../zookeeper-server/target/classes:/yinzhengjie/softwares/zookeeper/bin/../build/classes:/yinzhengjie/softwares/zookeeper/bin/../zooke
eper-server/target/lib/*.jar:/yinzhengjie/softwares/zookeeper/bin/../build/lib/*.jar:/yinzhengjie/softwares/zookeeper/bin/../lib/zookeeper-prometheus-metrics-3.6.1.jar:/yinzhengjie/softwares/zookeeper/bin/../lib/zookeeper-jute-3.6.1.jar:/yinzhengjie/softwares/zookeeper/bin/../lib/zookeeper-3.6.1.jar:/yinzhengjie/softwares/zookeeper/bin/../lib/snappy-java-1.1.7.jar:/yinzhengjie/softwares/zookeeper/bin/../lib/slf4j-log4j12-1.7.25.jar:/yinzhengjie/softwares/zookeeper/bin/../lib/slf4j-api-1.7.25.jar:/yinzhengjie/softwares/zookeeper/bin/../lib/simpleclient_servlet-0.6.0.jar:/yinzhengjie/softwares/zookeeper/bin/../lib/simpleclient_hotspot-0.6.0.jar:/yinzhengjie/softwares/zookeeper/bin/../lib/simpleclient_common-0.6.0.jar:/yinzhengjie/softwares/zookeeper/bin/../lib/simpleclient-0.6.0.jar:/yinzhengjie/softwares/zookeeper/bin/../lib/netty-transport-native-unix-common-4.1.48.Final.jar:/yinzhengjie/softwares/zookeeper/bin/../lib/netty-transport-native-epoll-4.1.48.Final.jar:/yinzhengjie/softwares/zookeeper/bin/../lib/netty-transport-4.1.48.Final.jar:/yinzhengjie/softwares/zookeeper/bin/../lib/netty-resolver-4.1.48.Final.jar:/yinzhengjie/softwares/zookeeper/bin/../lib/netty-handler-4.1.48.Final.jar:/yinzhengjie/softwares/zookeeper/bin/../lib/netty-common-4.1.48.Final.jar:/yinzhengjie/softwares/zookeeper/bin/../lib/netty-codec-4.1.48.Final.jar:/yinzhengjie/softwares/zookeeper/bin/../lib/netty-buffer-4.1.48.Final.jar:/yinzhengjie/softwares/zookeeper/bin/../lib/metrics-core-3.2.5.jar:/yinzhengjie/softwares/zookeeper/bin/../lib/log4j-1.2.17.jar:/yinzhengjie/softwares/zookeeper/bin/../lib/json-simple-1.1.1.jar:/yinzhengjie/softwares/zookeeper/bin/../lib/jline-2.11.jar:/yinzhengjie/softwares/zookeeper/bin/../lib/jetty-util-9.4.24.v20191120.jar:/yinzhengjie/softwares/zookeeper/bin/../lib/jetty-servlet-9.4.24.v20191120.jar:/yinzhengjie/softwares/zookeeper/bin/../lib/jetty-server-9.4.24.v20191120.jar:/yinzhengjie/softwares/zookeeper/bin/../lib/jetty-security-9.4.24.v20191120.jar:/yinzhengjie/softwares/zookeeper/bin/../lib/jetty-io-9.4.24.v20191120.jar:/yinzhengjie/softwares/zookeeper/bin/../lib/jetty-http-9.4.24.v20191120.jar:/yinzhengjie/softwares/zookeeper/bin/../lib/javax.servlet-api-3.1.0.jar:/yinzhengjie/softwares/zookeeper/bin/../lib/jackson-databind-2.10.3.jar:/yinzhengjie/softwares/zookeeper/bin/../lib/jackson-core-2.10.3.jar:/yinzhengjie/softwares/zookeeper/bin/../lib/jackson-annotations-2.10.3.jar:/yinzhengjie/softwares/zookeeper/bin/../lib/commons-lang-2.6.jar:/yinzhengjie/softwares/zookeeper/bin/../lib/commons-cli-1.2.jar:/yinzhengjie/softwares/zookeeper/bin/../lib/audience-annotations-0.5.0.jar:/yinzhengjie/softwares/zookeeper/bin/../zookeeper-*.jar:/yinzhengjie/softwares/zookeeper/bin/../zookeeper-server/src/main/resources/lib/*.jar:/yinzhengjie/softwares/zookeeper/bin/../conf:2020-05-12 06:59:14,899 [myid:] - INFO  [main:Environment@98] - Client environment:java.library.path=/usr/java/packages/lib/amd64:/usr/lib64:/lib64:/lib:/usr/lib
2020-05-12 06:59:14,900 [myid:] - INFO  [main:Environment@98] - Client environment:java.io.tmpdir=/tmp
2020-05-12 06:59:14,900 [myid:] - INFO  [main:Environment@98] - Client environment:java.compiler=<NA>
2020-05-12 06:59:14,900 [myid:] - INFO  [main:Environment@98] - Client environment:os.name=Linux
2020-05-12 06:59:14,900 [myid:] - INFO  [main:Environment@98] - Client environment:os.arch=amd64
2020-05-12 06:59:14,900 [myid:] - INFO  [main:Environment@98] - Client environment:os.version=3.10.0-957.el7.x86_64
2020-05-12 06:59:14,900 [myid:] - INFO  [main:Environment@98] - Client environment:user.name=root
2020-05-12 06:59:14,900 [myid:] - INFO  [main:Environment@98] - Client environment:user.home=/root
2020-05-12 06:59:14,900 [myid:] - INFO  [main:Environment@98] - Client environment:user.dir=/root
2020-05-12 06:59:14,900 [myid:] - INFO  [main:Environment@98] - Client environment:os.memory.free=237MB
2020-05-12 06:59:14,902 [myid:] - INFO  [main:Environment@98] - Client environment:os.memory.max=245MB
2020-05-12 06:59:14,902 [myid:] - INFO  [main:Environment@98] - Client environment:os.memory.total=245MB
2020-05-12 06:59:14,906 [myid:] - INFO  [main:ZooKeeper@1005] - Initiating client connection, connectString=hadoop102.yinzhengjie.org.cn sessionTimeout=30000 watcher=org.apache.zookeeper.ZooKeeperMain$MyWatcher@379619aa
2020-05-12 06:59:14,908 [myid:] - INFO  [main:X509Util@77] - Setting -D jdk.tls.rejectClientInitiatedRenegotiation=true to disable client-initiated TLS renegotiation
2020-05-12 06:59:14,915 [myid:] - INFO  [main:ClientCnxnSocket@239] - jute.maxbuffer value is 1048575 Bytes
2020-05-12 06:59:14,922 [myid:] - INFO  [main:ClientCnxn@1703] - zookeeper.request.timeout value is 0. feature enabled=false
2020-05-12 06:59:14,926 [myid:hadoop102.yinzhengjie.org.cn:2181] - INFO  [main-SendThread(hadoop102.yinzhengjie.org.cn:2181):ClientCnxn$SendThread@1154] - Opening socket connection to server hadoop102.yinzhengjie.org.cn/172.200.4.102:2181.
2020-05-12 06:59:14,926 [myid:hadoop102.yinzhengjie.org.cn:2181] - INFO  [main-SendThread(hadoop102.yinzhengjie.org.cn:2181):ClientCnxn$SendThread@1156] - SASL config status: Will not attempt to authenticate using SASL (unknown error)
Welcome to ZooKeeper!
JLine support is enabled
2020-05-12 06:59:14,999 [myid:hadoop102.yinzhengjie.org.cn:2181] - INFO  [main-SendThread(hadoop102.yinzhengjie.org.cn:2181):ClientCnxn$SendThread@986] - Socket connection established, initiating session, client: /172.200.4.101:43171, server: hadoop102.yinzhengjie.org.c
n/172.200.4.102:21812020-05-12 06:59:15,010 [myid:hadoop102.yinzhengjie.org.cn:2181] - INFO  [main-SendThread(hadoop102.yinzhengjie.org.cn:2181):ClientCnxn$SendThread@1420] - Session establishment complete on server hadoop102.yinzhengjie.org.cn/172.200.4.102:2181, session id = 0x660000590c
490001, negotiated timeout = 30000
WATCHER::

WatchedEvent state:SyncConnected type:None path:null
[zk: hadoop102.yinzhengjie.org.cn(CONNECTED) 0] 
[zk: hadoop102.yinzhengjie.org.cn(CONNECTED) 0] ls /
[zookeeper]
[zk: hadoop102.yinzhengjie.org.cn(CONNECTED) 1] 
[root@hadoop101.yinzhengjie.org.cn ~]# zkCli.sh -server hadoop102.yinzhengjie.org.cn    #使用"-server"选项指定连接到zookeeper集群的某一台服务器上
[root@hadoop101.yinzhengjie.org.cn ~]# zkCli.sh -server hadoop102.yinzhengjie.org.cn:2181,hadoop103.yinzhengjie.org.cn:2181
/yinzhengjie/softwares/jdk1.8.0_201/bin/java
Connecting to hadoop102.yinzhengjie.org.cn:2181,hadoop103.yinzhengjie.org.cn:2181
2020-05-12 07:00:27,391 [myid:] - INFO  [main:Environment@98] - Client environment:zookeeper.version=3.6.1--104dcb3e3fb464b30c5186d229e00af9f332524b, built on 04/21/2020 15:01 GMT
2020-05-12 07:00:27,394 [myid:] - INFO  [main:Environment@98] - Client environment:host.name=hadoop101.yinzhengjie.org.cn
2020-05-12 07:00:27,394 [myid:] - INFO  [main:Environment@98] - Client environment:java.version=1.8.0_201
2020-05-12 07:00:27,396 [myid:] - INFO  [main:Environment@98] - Client environment:java.vendor=Oracle Corporation
2020-05-12 07:00:27,396 [myid:] - INFO  [main:Environment@98] - Client environment:java.home=/yinzhengjie/softwares/jdk1.8.0_201/jre
2020-05-12 07:00:27,396 [myid:] - INFO  [main:Environment@98] - Client environment:java.class.path=/yinzhengjie/softwares/zookeeper/bin/../zookeeper-server/target/classes:/yinzhengjie/softwares/zookeeper/bin/../build/classes:/yinzhengjie/softwares/zookeeper/bin/../zooke
eper-server/target/lib/*.jar:/yinzhengjie/softwares/zookeeper/bin/../build/lib/*.jar:/yinzhengjie/softwares/zookeeper/bin/../lib/zookeeper-prometheus-metrics-3.6.1.jar:/yinzhengjie/softwares/zookeeper/bin/../lib/zookeeper-jute-3.6.1.jar:/yinzhengjie/softwares/zookeeper/bin/../lib/zookeeper-3.6.1.jar:/yinzhengjie/softwares/zookeeper/bin/../lib/snappy-java-1.1.7.jar:/yinzhengjie/softwares/zookeeper/bin/../lib/slf4j-log4j12-1.7.25.jar:/yinzhengjie/softwares/zookeeper/bin/../lib/slf4j-api-1.7.25.jar:/yinzhengjie/softwares/zookeeper/bin/../lib/simpleclient_servlet-0.6.0.jar:/yinzhengjie/softwares/zookeeper/bin/../lib/simpleclient_hotspot-0.6.0.jar:/yinzhengjie/softwares/zookeeper/bin/../lib/simpleclient_common-0.6.0.jar:/yinzhengjie/softwares/zookeeper/bin/../lib/simpleclient-0.6.0.jar:/yinzhengjie/softwares/zookeeper/bin/../lib/netty-transport-native-unix-common-4.1.48.Final.jar:/yinzhengjie/softwares/zookeeper/bin/../lib/netty-transport-native-epoll-4.1.48.Final.jar:/yinzhengjie/softwares/zookeeper/bin/../lib/netty-transport-4.1.48.Final.jar:/yinzhengjie/softwares/zookeeper/bin/../lib/netty-resolver-4.1.48.Final.jar:/yinzhengjie/softwares/zookeeper/bin/../lib/netty-handler-4.1.48.Final.jar:/yinzhengjie/softwares/zookeeper/bin/../lib/netty-common-4.1.48.Final.jar:/yinzhengjie/softwares/zookeeper/bin/../lib/netty-codec-4.1.48.Final.jar:/yinzhengjie/softwares/zookeeper/bin/../lib/netty-buffer-4.1.48.Final.jar:/yinzhengjie/softwares/zookeeper/bin/../lib/metrics-core-3.2.5.jar:/yinzhengjie/softwares/zookeeper/bin/../lib/log4j-1.2.17.jar:/yinzhengjie/softwares/zookeeper/bin/../lib/json-simple-1.1.1.jar:/yinzhengjie/softwares/zookeeper/bin/../lib/jline-2.11.jar:/yinzhengjie/softwares/zookeeper/bin/../lib/jetty-util-9.4.24.v20191120.jar:/yinzhengjie/softwares/zookeeper/bin/../lib/jetty-servlet-9.4.24.v20191120.jar:/yinzhengjie/softwares/zookeeper/bin/../lib/jetty-server-9.4.24.v20191120.jar:/yinzhengjie/softwares/zookeeper/bin/../lib/jetty-security-9.4.24.v20191120.jar:/yinzhengjie/softwares/zookeeper/bin/../lib/jetty-io-9.4.24.v20191120.jar:/yinzhengjie/softwares/zookeeper/bin/../lib/jetty-http-9.4.24.v20191120.jar:/yinzhengjie/softwares/zookeeper/bin/../lib/javax.servlet-api-3.1.0.jar:/yinzhengjie/softwares/zookeeper/bin/../lib/jackson-databind-2.10.3.jar:/yinzhengjie/softwares/zookeeper/bin/../lib/jackson-core-2.10.3.jar:/yinzhengjie/softwares/zookeeper/bin/../lib/jackson-annotations-2.10.3.jar:/yinzhengjie/softwares/zookeeper/bin/../lib/commons-lang-2.6.jar:/yinzhengjie/softwares/zookeeper/bin/../lib/commons-cli-1.2.jar:/yinzhengjie/softwares/zookeeper/bin/../lib/audience-annotations-0.5.0.jar:/yinzhengjie/softwares/zookeeper/bin/../zookeeper-*.jar:/yinzhengjie/softwares/zookeeper/bin/../zookeeper-server/src/main/resources/lib/*.jar:/yinzhengjie/softwares/zookeeper/bin/../conf:2020-05-12 07:00:27,396 [myid:] - INFO  [main:Environment@98] - Client environment:java.library.path=/usr/java/packages/lib/amd64:/usr/lib64:/lib64:/lib:/usr/lib
2020-05-12 07:00:27,396 [myid:] - INFO  [main:Environment@98] - Client environment:java.io.tmpdir=/tmp
2020-05-12 07:00:27,396 [myid:] - INFO  [main:Environment@98] - Client environment:java.compiler=<NA>
2020-05-12 07:00:27,396 [myid:] - INFO  [main:Environment@98] - Client environment:os.name=Linux
2020-05-12 07:00:27,396 [myid:] - INFO  [main:Environment@98] - Client environment:os.arch=amd64
2020-05-12 07:00:27,396 [myid:] - INFO  [main:Environment@98] - Client environment:os.version=3.10.0-957.el7.x86_64
2020-05-12 07:00:27,396 [myid:] - INFO  [main:Environment@98] - Client environment:user.name=root
2020-05-12 07:00:27,396 [myid:] - INFO  [main:Environment@98] - Client environment:user.home=/root
2020-05-12 07:00:27,397 [myid:] - INFO  [main:Environment@98] - Client environment:user.dir=/root
2020-05-12 07:00:27,397 [myid:] - INFO  [main:Environment@98] - Client environment:os.memory.free=237MB
2020-05-12 07:00:27,398 [myid:] - INFO  [main:Environment@98] - Client environment:os.memory.max=245MB
2020-05-12 07:00:27,398 [myid:] - INFO  [main:Environment@98] - Client environment:os.memory.total=245MB
2020-05-12 07:00:27,403 [myid:] - INFO  [main:ZooKeeper@1005] - Initiating client connection, connectString=hadoop102.yinzhengjie.org.cn:2181,hadoop103.yinzhengjie.org.cn:2181 sessionTimeout=30000 watcher=org.apache.zookeeper.ZooKeeperMain$MyWatcher@379619aa
2020-05-12 07:00:27,407 [myid:] - INFO  [main:X509Util@77] - Setting -D jdk.tls.rejectClientInitiatedRenegotiation=true to disable client-initiated TLS renegotiation
2020-05-12 07:00:27,415 [myid:] - INFO  [main:ClientCnxnSocket@239] - jute.maxbuffer value is 1048575 Bytes
2020-05-12 07:00:27,422 [myid:] - INFO  [main:ClientCnxn@1703] - zookeeper.request.timeout value is 0. feature enabled=false
Welcome to ZooKeeper!
JLine support is enabled
2020-05-12 07:00:27,458 [myid:hadoop103.yinzhengjie.org.cn:2181] - INFO  [main-SendThread(hadoop103.yinzhengjie.org.cn:2181):ClientCnxn$SendThread@1154] - Opening socket connection to server hadoop103.yinzhengjie.org.cn/172.200.4.103:2181.
2020-05-12 07:00:27,458 [myid:hadoop103.yinzhengjie.org.cn:2181] - INFO  [main-SendThread(hadoop103.yinzhengjie.org.cn:2181):ClientCnxn$SendThread@1156] - SASL config status: Will not attempt to authenticate using SASL (unknown error)
2020-05-12 07:00:27,511 [myid:hadoop103.yinzhengjie.org.cn:2181] - INFO  [main-SendThread(hadoop103.yinzhengjie.org.cn:2181):ClientCnxn$SendThread@986] - Socket connection established, initiating session, client: /172.200.4.101:56253, server: hadoop103.yinzhengjie.org.c
n/172.200.4.103:2181[zk: hadoop102.yinzhengjie.org.cn:2181,hadoop103.yinzhengjie.org.cn:2181(CONNECTING) 0] 2020-05-12 07:00:27,674 [myid:hadoop103.yinzhengjie.org.cn:2181] - INFO  [main-SendThread(hadoop103.yinzhengjie.org.cn:2181):ClientCnxn$SendThread@1420] - Session establishment compl
ete on server hadoop103.yinzhengjie.org.cn/172.200.4.103:2181, session id = 0x67000059019b0000, negotiated timeout = 30000
WATCHER::

WatchedEvent state:SyncConnected type:None path:null

[zk: hadoop102.yinzhengjie.org.cn:2181,hadoop103.yinzhengjie.org.cn:2181(CONNECTED) 0] 
[root@hadoop101.yinzhengjie.org.cn ~]# zkCli.sh -server hadoop102.yinzhengjie.org.cn:2181,hadoop103.yinzhengjie.org.cn:2181        #生产环境中,推荐大家连接到多台服务器,其原因是增强可用性

2>.查看帮助信息

[zk: hadoop102.yinzhengjie.org.cn(CONNECTED) 0] help
ZooKeeper -server host:port -client-configuration properties-file cmd args
    addWatch [-m mode] path # optional mode is one of [PERSISTENT, PERSISTENT_RECURSIVE] - default is PERSISTENT_RECURSIVE
    addauth scheme auth
    close 
    config [-c] [-w] [-s]
    connect host:port
    create [-s] [-e] [-c] [-t ttl] path [data] [acl]
    delete [-v version] path
    deleteall path [-b batch size]
    delquota [-n|-b] path
    get [-s] [-w] path
    getAcl [-s] path
    getAllChildrenNumber path
    getEphemerals path
    history 
    listquota path
    ls [-s] [-w] [-R] path
    printwatches on|off
    quit 
    reconfig [-s] [-v version] [[-file path] | [-members serverID=host:port1:port2;port3[,...]*]] | [-add serverId=host:port1:port2;port3[,...]]* [-remove serverId[,...]*]
    redo cmdno
    removewatches path [-c|-d|-a] [-l]
    set [-s] [-v version] path data
    setAcl [-s] [-v version] [-R] path acl
    setquota -n|-b val path
    stat [-w] path
    sync path
    version 
Command not found: Command not found help
[zk: hadoop102.yinzhengjie.org.cn(CONNECTED) 1] 

3>.查看指定路径的znode中所包含的内容

[zk: hadoop102.yinzhengjie.org.cn(CONNECTED) 1] ls /
[zookeeper]
[zk: hadoop102.yinzhengjie.org.cn(CONNECTED) 2] 
[zk: hadoop102.yinzhengjie.org.cn(CONNECTED) 1] ls /
[zk: hadoop102.yinzhengjie.org.cn(CONNECTED) 3] ls -s /
[zookeeper]
cZxid = 0x0
ctime = Thu Jan 01 08:00:00 CST 1970
mZxid = 0x0
mtime = Thu Jan 01 08:00:00 CST 1970
pZxid = 0x0
cversion = -1
dataVersion = 0
aclVersion = 0
ephemeralOwner = 0x0
dataLength = 0
numChildren = 1
[zk: hadoop102.yinzhengjie.org.cn(CONNECTED) 4] 
[zk: hadoop102.yinzhengjie.org.cn(CONNECTED) 3] ls -s /            #查看根节点详细数据
[zk: hadoop102.yinzhengjie.org.cn(CONNECTED) 10] ls  -w / 
[zookeeper]
[zk: hadoop102.yinzhengjie.org.cn(CONNECTED) 11] 
[zk: hadoop102.yinzhengjie.org.cn(CONNECTED) 10] ls -w /           #查看根节点的子节点信息并监控根节点的变化,即对应watch操作。当根节点内容有变化是就会触发watch,注意:仅触发一次。

4>.创建znode

[zk: hadoop102.yinzhengjie.org.cn(CONNECTED) 13] create /yinzhengjie JasonYin        #在根节点下创建一个"yinzhengjie"这个znode,该znode存储的数据是"JasonYin"
Created /yinzhengjie
[zk: hadoop102.yinzhengjie.org.cn(CONNECTED) 14] 
[zk: hadoop102.yinzhengjie.org.cn(CONNECTED) 14] ls /
[yinzhengjie, zookeeper]
[zk: hadoop102.yinzhengjie.org.cn(CONNECTED) 16] 
[zk: hadoop102.yinzhengjie.org.cn(CONNECTED) 13] create /yinzhengjie JasonYin      #在根节点下创建一个"yinzhengjie"这个永久的znode(只要你不认为删除它会一直存在),该znode存储的数据是"JasonYin"
[zk: hadoop102.yinzhengjie.org.cn(CONNECTED) 16] create -s /yinzhengjie JasonYin          #创建一个带序列号的znode,该znode的父节点会维护一个序列号,每次创建带有序列号的节点均会使得该序列号自增1。
Created /yinzhengjie0000000001
[zk: hadoop102.yinzhengjie.org.cn(CONNECTED) 17] 
[zk: hadoop102.yinzhengjie.org.cn(CONNECTED) 17] ls /
[yinzhengjie, yinzhengjie0000000001, zookeeper]
[zk: hadoop102.yinzhengjie.org.cn(CONNECTED) 18] 
[zk: hadoop102.yinzhengjie.org.cn(CONNECTED) 18] create -s /yinzhengjie JasonYin
Created /yinzhengjie0000000002
[zk: hadoop102.yinzhengjie.org.cn(CONNECTED) 19] 
[zk: hadoop102.yinzhengjie.org.cn(CONNECTED) 19] create -s /yinzhengjie2020 JasonYin
Created /yinzhengjie20200000000003
[zk: hadoop102.yinzhengjie.org.cn(CONNECTED) 20] 
[zk: hadoop102.yinzhengjie.org.cn(CONNECTED) 20] ls /                        #很明显,创建的序号是全局递增的
[yinzhengjie, yinzhengjie0000000001, yinzhengjie0000000002, yinzhengjie20200000000003, zookeeper]
[zk: hadoop102.yinzhengjie.org.cn(CONNECTED) 21] 
[zk: hadoop102.yinzhengjie.org.cn(CONNECTED) 21] 

[zk: hadoop102.yinzhengjie.org.cn(CONNECTED) 16] create -s /yinzhengjie JasonYin    #创建一个带序列号的znode,zookeeper会维护一个全局的序列号,每次创建带有序列号的节点均会使得该序列号自增1。
[zk: hadoop102.yinzhengjie.org.cn(CONNECTED) 16] create -s /yinzhengjie JasonYin     #创建一个带序列号的znode,该znode的父节点会维护一个序列号,每次创建带有序列号的节点均会使得该序列号自增1。
[zk: hadoop102.yinzhengjie.org.cn(CONNECTED) 20] ls /
[yinzhengjie, yinzhengjie0000000001, yinzhengjie0000000002, yinzhengjie20200000000003, zookeeper]
[zk: hadoop102.yinzhengjie.org.cn(CONNECTED) 21] 
[zk: hadoop102.yinzhengjie.org.cn(CONNECTED) 21] create -e /test                  #创建一个临时znode,当创建该znode的Session会话被关闭(执行quit命令)后,该临时节点自动删除。
Created /test
[zk: hadoop102.yinzhengjie.org.cn(CONNECTED) 22] 
[zk: hadoop102.yinzhengjie.org.cn(CONNECTED) 22] ls /
[test, yinzhengjie, yinzhengjie0000000001, yinzhengjie0000000002, yinzhengjie20200000000003, zookeeper]
[zk: hadoop102.yinzhengjie.org.cn(CONNECTED) 23] 
[zk: hadoop102.yinzhengjie.org.cn(CONNECTED) 21] create -e /test              #创建一个临时znode,当创建该znode的Session会话被关闭(执行quit命令)后,该临时节点自动删除。
[zk: hadoop102.yinzhengjie.org.cn(CONNECTED) 0] ls /
[yinzhengjie, yinzhengjie0000000001, yinzhengjie0000000002, yinzhengjie20200000000003, zookeeper]
[zk: hadoop102.yinzhengjie.org.cn(CONNECTED) 1] 
[zk: hadoop102.yinzhengjie.org.cn(CONNECTED) 1] create -s -e /test 123
Created /test0000000005
[zk: hadoop102.yinzhengjie.org.cn(CONNECTED) 2] 
[zk: hadoop102.yinzhengjie.org.cn(CONNECTED) 2] ls /
[test0000000005, yinzhengjie, yinzhengjie0000000001, yinzhengjie0000000002, yinzhengjie20200000000003, zookeeper]
[zk: hadoop102.yinzhengjie.org.cn(CONNECTED) 3] 
[zk: hadoop102.yinzhengjie.org.cn(CONNECTED) 3] 
[zk: hadoop102.yinzhengjie.org.cn(CONNECTED) 1] create -s -e /test 123          #创建一个临时有序的znode

5>.获取znode的数据

[zk: hadoop102.yinzhengjie.org.cn(CONNECTED) 1] get /yinzhengjie
JasonYin
[zk: hadoop102.yinzhengjie.org.cn(CONNECTED) 2] 
[zk: hadoop102.yinzhengjie.org.cn(CONNECTED) 1] get /yinzhengjie        #获取/yinzhengjie的znode数据
[zk: hadoop102.yinzhengjie.org.cn(CONNECTED) 3] get -w /yinzhengjie                   #获取/yinzhengjie该znode存储的数据,与此同时监控该znode的数据,当数据发生修改时会通知该终端
JasonYin
[zk: hadoop102.yinzhengjie.org.cn(CONNECTED) 4] 
[zk: hadoop102.yinzhengjie.org.cn(CONNECTED) 3] get -w /yinzhengjie       #获取/yinzhengjie该znode存储的数据,与此同时监控该znode的数据,当数据发生修改时会通知该终端,注意:仅触发一次。

7>.修改znode的数据

[zk: localhost:2181(CONNECTED) 3] get /yinzhengjie
JasonYin
[zk: localhost:2181(CONNECTED) 4] 
[zk: localhost:2181(CONNECTED) 4] set /yinzhengjie JasonYin2020
[zk: localhost:2181(CONNECTED) 5] 
[zk: localhost:2181(CONNECTED) 5] get /yinzhengjie
JasonYin2020
[zk: localhost:2181(CONNECTED) 6] 
[zk: localhost:2181(CONNECTED) 4] set /yinzhengjie JasonYin2020        #将/yinzhengjie的znode存储的数据修改为"JasonYin2020"

8>.查看节点状态

[zk: localhost:2181(CONNECTED) 7] stat /yinzhengjie 
cZxid = 0x10000000c                    #创建事务的zxid(用64bit存储,即8字节),即记录每次操作的事务编号,从该编号可以得知命令的执行顺序。
ctime = Tue May 12 07:17:12 CST 2020          #被创建的毫秒数(从1970年开始)
mZxid = 0x10000001a                    #最后更新的事务zxid
mtime = Tue May 12 07:41:00 CST 2020          #最后修改的毫秒数(从1970年开始)
pZxid = 0x10000000c                    #最后更新的子节点zxid
cversion = 0                        #znode子节点变化号,即znode子节点修改次数
dataVersion = 2                       #znode数据变化号
aclVersion = 0                       #访问控制列表的变化号
ephemeralOwner = 0x0                   #如果时临时节点,这个时znode拥有者的seesion id。如果不是临时节点则是0.
dataLength = 8                       #znode的数据长度
numChildren = 0                       #znode子节点数量。
[zk: localhost:2181(CONNECTED) 8] 
[zk: localhost:2181(CONNECTED) 8] 

9>.删除znode

[zk: hadoop102.yinzhengjie.org.cn(CONNECTED) 18] ls /yinzhengjie
[test1, test2, test30000000002, test40000000003]
[zk: hadoop102.yinzhengjie.org.cn(CONNECTED) 19]
[zk: hadoop102.yinzhengjie.org.cn(CONNECTED) 19] ls /yinzhengjie/test1
[]
[zk: hadoop102.yinzhengjie.org.cn(CONNECTED) 20] 
[zk: hadoop102.yinzhengjie.org.cn(CONNECTED) 20] delete /yinzhengjie/test1        #删除/yinzhengjie/test1的znode。
[zk: hadoop102.yinzhengjie.org.cn(CONNECTED) 21] 
[zk: hadoop102.yinzhengjie.org.cn(CONNECTED) 21] ls /yinzhengjie
[test2, test30000000002, test40000000003]
[zk: hadoop102.yinzhengjie.org.cn(CONNECTED) 22] 
[zk: hadoop102.yinzhengjie.org.cn(CONNECTED) 22] 
[zk: hadoop102.yinzhengjie.org.cn(CONNECTED) 20] delete /yinzhengjie/test1        #删除/yinzhengjie/test1的znode。仅能用于删除没有子znode的znode。
[zk: hadoop102.yinzhengjie.org.cn(CONNECTED) 24] ls /
[111, yinzhengjie, yinzhengjie0000000001, yinzhengjie0000000002, yinzhengjie20200000000003, zookeeper]
[zk: hadoop102.yinzhengjie.org.cn(CONNECTED) 25] 
[zk: hadoop102.yinzhengjie.org.cn(CONNECTED) 25] ls /yinzhengjie
[test2, test30000000002, test40000000003]
[zk: hadoop102.yinzhengjie.org.cn(CONNECTED) 26] 
[zk: hadoop102.yinzhengjie.org.cn(CONNECTED) 26] delete /yinzhengjie            #delete命令无法删除有子znode的目录
Node not empty: /yinzhengjie
[zk: hadoop102.yinzhengjie.org.cn(CONNECTED) 27] 
[zk: hadoop102.yinzhengjie.org.cn(CONNECTED) 27] ls /yinzhengjie
[test2, test30000000002, test40000000003]
[zk: hadoop102.yinzhengjie.org.cn(CONNECTED) 28] 
[zk: hadoop102.yinzhengjie.org.cn(CONNECTED) 28] deleteall /yinzhengjie           #删除/yinzhengjie的znode,尽管它有子znode也会一并删除。
[zk: hadoop102.yinzhengjie.org.cn(CONNECTED) 29] 
[zk: hadoop102.yinzhengjie.org.cn(CONNECTED) 29] ls /
[111, yinzhengjie0000000001, yinzhengjie0000000002, yinzhengjie20200000000003, zookeeper]
[zk: hadoop102.yinzhengjie.org.cn(CONNECTED) 30] 
[zk: hadoop102.yinzhengjie.org.cn(CONNECTED) 30]  
[zk: hadoop102.yinzhengjie.org.cn(CONNECTED) 28] deleteall /yinzhengjie           #删除/yinzhengjie的znode,尽管它有子znode也会一并删除。

10>.查看历史命令

[zk: localhost:2181(CONNECTED) 8] history
0 - ls /
1 - ls /
2 - ls /
3 - get /yinzhengjie
4 - set /yinzhengjie JasonYin2020
5 - get /yinzhengjie
6 - set /yinzhengjie JasonYin
7 - stat /yinzhengjie 
8 - history
[zk: localhost:2181(CONNECTED) 9] 
[zk: localhost:2181(CONNECTED) 9] 
[zk: localhost:2181(CONNECTED) 8] history

 

二.zookeeper的安全相关命令

1>.

 

2>.

 

3>.

 

4>.

 

5>.

 

 

posted @ 2020-03-16 00:08  JasonYin2020  阅读(780)  评论(0编辑  收藏  举报