Problem Guidance
1. What Common commands does zookeeper contain?
2. What command can be used to list the watch details of the server?
3. What operations does zookeeper contain?
4. How does zookeeper create zookeeper?
Common commands
Zookeeper supports the interaction between certain four-character command letters. Most of them are query commands used to obtain the current status and related information of the zookeeper service. You can use Telnet or NC to submit commands to zookeeper on the client. Common four-character commands for zookeeper are shown in table 1 below:
Table 1: zookeeper command
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. |
1 is a simple example of the zookeeper command:
<Ignore_js_op> Figure 1: zookeeper Command case
Command line tool:
After the zookeeper service is successfully started, enter the following command to connect to the zookeeper service:
- Zkcli. Sh-server 10.77.20.23: 2181
Copy code
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. After you enter help, the available zookeeper commands are displayed, as shown in 1:
<Ignore_js_op> Figure 1: zookeeper command
Zookeeper simple operation 1) Use the LS command to view the content contained in the current zookeeper:
- [ZK: 10.77.000023: 2181 (connected) 1] ls/
- [Zookeeper]
Copy code
2) create a new znode and use create/ZK mydata. This command creates a new znode node "zk" and the strings associated with it:
- <Div style = "text-align: Left;"> <span style = "line-Height: 1.5;"> [ZK: 10.77.20.23: 2181 (connected) 2] Create/ZK mydata </span> </div> <Div style = "text-align: Left;"> <span style = "line-Height: 1.5; "> created/ZK </span> </div>
Copy code
3) run the LS command again to view the content contained in zookeeper:
- [ZK: 10.77.000023: 2181 (connected) 3] ls/
- [ZK, Zookeeper]
Copy the code and you will see that the zk node has been created.
4) run the GET command to check whether the znode created in step 2 contains the string we created:
- [ZK: 10.77.000023: 2181 (connected) 4] GET/ZK
- Mydata
- Zxid = 0x40000000c
- Time = Tue Jan 18 18:48:39 CST 2011
- Zxid = 0x40000000c
- Mtime = Tue Jan 18 18:48:39 CST 2011
- Pzxid = 0x40000000c
- Cversion = 0
- Dataversion = 0
- Aclversion = 0
- Ephemeralowner = 0x0
- Datalength = 6
- Numchildren = 0
Copy code
5) Below we use the set command to set the string associated with ZK:
- [ZK: 10.77.000023: 2181 (connected) 5] Set/ZK shenlan211314
- Czxid = 0x40000000c
- Ctime = Tue Jan 18 18:48:39 CST 2011
- Mzxid = 0x40000000d
- Mtime = Tue Jan 18 18:52:11 CST 2011
- Pzxid = 0x40000000c
- Cversion = 0
- Dataversion = 1
- Aclversion = 0
- Ephemeralowner = 0x0
- Datalength = 13
- Numchildren = 0
Copy code
6) Below we will delete the created znode:
- [ZK: 10.77.000023: 2181 (connected) 6] delete/ZK
Copy code
7) run the LS command again to view the content of zookeeper:
- [ZK: 10.77.000023: 2181 (connected) 7] ls/
- [Zookeeper]
Copy code
After verification, the zk node has been deleted. Article transferred from: http://www.aboutyun.com/thread-9310-1-1.html
Zookeeper Series 3: zookeeper commands, command line tools, and simple operations