[Apache zookeeper] command line zkcli. Sh User Guide

Source: Internet
Author: User
Tags zookeeper client

Zookeeper command line

 OriginalHttp://blog.csdn.net/ganglia/article/details/11606807

The Zookeeper client has two versions: C and Java.

The Zookeeper command is in the/usr/lib/zookeeper/bin folder.

Clients running Java use Bash zkcli. Sh-Server IP: Port and C language version./cli_mt IP: port. The following describes the Java version, which is similar to the C language version.

View node Information

Bash zkserver. sh status [email protected]:/usr/lib/zookeeper/bin # bash zkserver. sh status JMX enabled by default using config:/usr/lib/zookeeper/bin /.. /CONF/Zoo. CFG mode: Standalone
Check which node is selected as the leader or follower.Echo stat | NC 127.0.0.1 2181 [email protected]:/usr/lib/zookeeper/bin # echo stat | NC 127.0.0.1 2181 zookeeper version: 3.4.5-cdh4.4.0 -- 1, built on 09/04/2013 0gmt clients:/127.0.0.1: 57736 [0] (queued = 0, recved = 1, sent = 0)
Latency min/AVG/MAX: 0/0/0 Received: 1 sent: 0 connections: 1 outstanding: 0 zxid: 0x0 mode: Standalone node count: 4
Test whether the server is started. If you reply to imok, the server is started.Echo ruok | NC 127.0.0.1 2181 [email protected]:/usr/lib/zookeeper/bin # echo ruok | NC 127.0.0.1 2181 imok
The Zookeeper command line is similar to shell. After the zookeeper service is successfully started, run the following command to connect to the zookeeper service: Bash zkcli. Sh-server 192.168.20.133: 2181
[Email protected]:/usr/lib/zookeeper/bin # bash zkcli. sh-server 192.168.20.0000: 2181 connecting to 192.168.20.0000: 2181 15:38:39, 654 [myid:]-info [main: [email protected]-client environment: zookeeper. version = 3.4.5-cdh4.4.0 -- 1, built on 09/04/2013 015:38:39 GMT, 657 [myid:]-info [main: [email protected]-client environment: host. name = Ubuntu 2013-09-12 15:38:39, 659 [My ID:]-info [main: [email protected]-client environment: Java. version = 1.6.0 _ 43 2013-09-12 15:38:39, 660 [myid:]-info [main: [email protected]-client environment: Java. vendor = Sun Microsystems Inc. 2013-09-12 15:38:39, 662 [myid:]-info [main: [email protected]-client environment: Java. home =/usr/local/jdk1.6.0 _ 43/JRE 2013-09-12 15:38:39, 664 [myid:]-info [main: [email protected]-client enviro Nment: Java. class. path =/usr/lib/zookeeper/bin /.. /build/classes:/usr/lib/zookeeper/bin /.. /build/lib /*. jar:/usr/lib/zookeeper/bin /.. /lib/slf4j-log4j12-1.6.1.jar:/usr/lib/zookeeper/bin /.. /lib/slf4j-api-1.6.1.jar:/usr/lib/zookeeper/bin /.. /lib/netty-3.2.2.Final.jar:/usr/lib/zookeeper/bin /.. /lib/log4j-1.2.15.jar:/usr/lib/zookeeper/bin /.. /lib/jline-0.9.94.jar:/usr/lib/zookeeper/bin /.. zookeeper-3.4.5-cdh4. 4.0.jar:/usr/lib/zookeeper/bin /.. /src/Java/lib /*. jar:/usr/lib/zookeeper/bin /.. /conf: 15:38:39, 665 [myid:]-info [main: [email protected]-client environment: Java. library. path =/usr/local/jdk1.6.0 _ 43/JRE/lib/amd64/Server:/usr/local/jdk1.6.0 _ 43/JRE/lib/amd64: /usr/local/jdk1.6.0 _ 43/JRE /.. /lib/amd64:/usr/Java/packages/lib/amd64:/usr/lib64:/lib64:/lib:/usr/lib 15:38:39, 667 [myid :]-Info [main: [email protected]-client environment: Java. io. tmpdir =/tmp 15:38:39, 668 [myid:]-info [main: [email protected]-client environment: Java. compiler = <Na> 15:38:39, 669 [myid:]-info [main: [email protected]-client environment: OS. name = Linux 15:38:39, 670 [myid:]-info [main: [email protected]-client environment: OS. arch = amd64 2013-09-12 15:38:39, 67 0 [myid:]-info [main: [email protected]-client environment: OS. version = 3.2.0-51-generic 2013-09-12 15:38:39, 672 [myid:]-info [main: [email protected]-client environment: user. name = root 2013-09-12 15:38:39, 672 [myid:]-info [main: [email protected]-client environment: user. home =/root 15:38:39, 673 [myid:]-info [main: [email protected]-client environment: user. dir =/usr/lib/zooke EPER/bin 15:38:39, 674 [myid:]-info [main: [email protected]-initiating client connection, connectstring = 192.168.20.133: 2181 sessiontimeout = 30000 [email protected] 815 welcome to zookeeper! Jline support is enabled 15:38:39, 720 [myid:]-info [main-sendthread (192.168.20.0000: 2181): [email protected]-opening socket connection to server 192.168.20.0000/ 192.168.20.0000: 2181. will not attempt to authenticate using SASL (unable to locate a login configuration) 15:38:39, 729 [myid:]-info [main-sendthread (192.168.20.0000: 2181 ): [email protected]-socket connection established to 192.168.20.20.0000/ 192.168.20.0000: 2181, initiating session [ZK: 192.168.20.00000000: 2181 (connecting) 0] 15:38:39, 748 [myid:] -info [main-sendthread (192.168.20.0000: 2181): [email protected]-session establishment complete on server 192.168.20.00000000/ 192.168.20.0000: 2181, sessionid = 0x141102059a70001, negotiated timeout = 30000
Watcher ::
Watchedevent state: syncconnected type: None path: NULL
Enter help to display help information:
Help zookeeper-server host: Port cmd ARGs Connect Host: port get path [Watch] ls path [Watch] set path data [version] RMR path delquota [-N |-B] path quit printwatches on | off create [-S] [- e] path data ACL stat path [Watch] Close ls2 path [Watch] History listquota path setacl path ACL getacl path sync path redo records no addauth scheme auth Delete path [version] setquota-N | -B Val path [ZK: 192.168.255.255.255.: 2181 (connected) 1]

After the connection is successful, the system outputs the relevant environment and configuration information of zookeeper, and outputs "Welcome to zookeeper" and other information on the screen.

Some simple operations of the command line tool are as follows:

 

1) Use the LS command to view the content contained in the current zookeeper:[ZK: 202.115.36.133: 2181 (connected) 1] ls/[zookeeper]
2) create a new znode and use create/ZK mydata. This command creates a new znode node "zk" and the strings associated with it:[ZK: 202.115.36.133: 2181 (connected) 2] Create/ZK "mydata" created/ZK
3) run the GET command to check whether znode contains the string we created:[ZK: 202.115.36.133: 2181 (connected) 3] GET/ZK czxid = 0x6 ctime = Thu Sep 12 15:49:16 CST 2013 mzxid = 0x7 mtime = Thu Sep 12 15:49:38 CST 2013 pzxid = 0x6 cversion = 0 dataversion = 1 aclversion = 0 ephemeralowner = 0x0 datalength = 10 numchildren = 0
4) Below we use the set command to set the string associated with ZK:[ZK: 202.115.36.133: 2181 (connected) 4] Set/ZK "zsl" "mydata" czxid = 0x4 ctime = Thu Sep 12 15:46:37 CST 2013 mzxid = 0x4 mtime = Thu Sep 12 15:46:37 CST 2013 pzxid = 0x4 cversion = 0 dataversion = 0 aclversion = 0 ephemeralowner = 0x0 datalength = 8 numchildren = 0
5) Below we will delete the created znode:[ZK: 202.115.36.133: 2181 (connected) 5] delete/ZK
Of course, we can also create a directory that was previously created. For example, we can use create/ZK/node1 to create a new directory node1 under the zk directory [ZK: 192.168.20.133: 2181 (connected) 18] Create/ZK/node1 "node1" created/ZK/node1 [ZK: 192.168.20.20.: 2181 (connected) 19] ls/ZK [node1]
Use the zookeeper command

 

When a string of four letters is passed to zookeeper, Zookeeper returns some useful information.

Zookeeper command

Function Description

Conf

Output detailed service configuration information.

Cons

Lists the full connection/session details of all clients connected to the server. Including the number of "Accept/Send" packets, session ID, Operation delay, and last operation execution.

Dump

Lists unprocessed sessions and temporary nodes.

ENVI

Output detailed information about the service environment (different from the conf command ).

Reqs

List unprocessed requests

Ruok

Test whether the service is in the correct status. If so, the service returns "imok"; otherwise, no response is made.

Stat

Output A list of performance and connected clients.

Wchs

List the detailed information of the server watch.

Wchc

A session is used to list the detailed information of the server watch. Its output is a list of watch-related sessions.

Wchp

List the detailed information of the server watch in the path. It outputs a session-related path.

 

 

For example:

[Email protected]: /usr/lib/zookeeper/bin # echo conf | NC 192.168.20.1_2181 clientport = 2181 datadir =/var/lib/zookeeper/version-2 datalogdir =/var/log/zookeeper/version -2 ticktime = 2000 maxclientcnxns = 50 minsessiontimeout = 4000 maxsessiontimeout = 40000 serverid = 0

 

[Apache zookeeper] command line zkcli. Sh User Guide

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.