Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to understand the zkServer.sh command, zkCli.sh command and four-word command in zookeeper

2025-02-24 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >

Share

Shulou(Shulou.com)06/01 Report--

This article to share with you is about zookeeper zkServer.sh command, zkCli.sh command, four-word command how to understand, Xiaobian think quite practical, so share to everyone to learn, I hope you can read this article after harvest, not much to say, follow Xiaobian to see it.

I. zkServer.sh

1. View zkServer.sh Help Information

[root@bigdata05 bin]# ./ zkServer.sh help

ZooKeeper JMX enabled by default

Using config: /bigdata/zookeeper-3.4.10/bin/../ conf/zoo.cfg

Usage: ./ zkServer.sh {start|start-foreground|stop|restart|status|upgrade|print-cmd}

2. Start/close zk server

[root@bigdata05 bin]# ./ zkServer.sh start

[root@bigdata05 bin]# ./ zkServer.sh stop

3. View server status

[root@bigdata05 bin]# ./ zkServer.sh status

ZooKeeper JMX enabled by default

Using config: /bigdata/zookeeper-3.4.10/bin/../ conf/zoo.cfg

Mode: follower

II. zkCli.sh

1. View zkCli.sh Help Information

[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

frequently used commands

0) Connect zookeeper

[root@bigdata05 bin]# ./ zkCli.sh -server localhost:2181

1) View current node list

[zk: localhost:2181(CONNECTED) 1] ls /

[zookeeper, yarn-leader-election, hadoop-ha]

2) Create a node

[zk: localhost:2181(CONNECTED) 1] ls /

[zookeeper, yarn-leader-election, hadoop-ha]

[zk: localhost:2181(CONNECTED) 2] create /test "test"

Created /test

[zk: localhost:2181(CONNECTED) 3] ls /

[zookeeper, test, yarn-leader-election, hadoop-ha]

[zk: localhost:2181(CONNECTED) 4] create /test/test "test"

Created /test/test

[zk: localhost:2181(CONNECTED) 5] ls /

[zookeeper, test, yarn-leader-election, hadoop-ha]

[zk: localhost:2181(CONNECTED) 6] ls /test

[test]

3) View node data

[zk: localhost:2181(CONNECTED) 7] get /test

test

cZxid = 0x400000031

ctime = Mon Oct 16 04:05:02 CST 2017

mZxid = 0x400000031

mtime = Mon Oct 16 04:05:02 CST 2017

pZxid = 0x400000032

cversion = 1

dataVersion = 0

aclVersion = 0

ephemeralOwner = 0x0

dataLength = 4

numChildren = 1

4) Set node data

[zk: localhost:2181(CONNECTED) 8] set /test "666666"

cZxid = 0x400000031

ctime = Mon Oct 16 04:05:02 CST 2017

mZxid = 0x400000033

mtime = Mon Oct 16 04:08:44 CST 2017

pZxid = 0x400000032

cversion = 1

dataVersion = 1

aclVersion = 0

ephemeralOwner = 0x0

dataLength = 6

numChildren = 1

[zk: localhost:2181(CONNECTED) 10] get /test

666666

cZxid = 0x400000031

ctime = Mon Oct 16 04:05:02 CST 2017

mZxid = 0x400000033

mtime = Mon Oct 16 04:08:44 CST 2017

pZxid = 0x400000032

cversion = 1

dataVersion = 1

aclVersion = 0

ephemeralOwner = 0x0

dataLength = 6

numChildren = 1

5) Delete nodes

[zk: localhost:2181(CONNECTED) 11] delete /test

Node not empty: /test

[zk: localhost:2181(CONNECTED) 12] ls /

[zookeeper, test, yarn-leader-election, hadoop-ha]

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

[zk: localhost:2181(CONNECTED) 14] ls /test

[]

[zk: localhost:2181(CONNECTED) 15] delete /test

[zk: localhost:2181(CONNECTED) 16] ls /

[zookeeper, yarn-leader-election, hadoop-ha]

Three, ZooKeeper server-side four-word command

ZooKeeper supports certain commands (The Four Letter Words) to interact with. Most of them are query commands used to get the current status and related information of ZooKeeper service. Users can submit commands to ZooKeeper via telnet or nc on the client side. ZooKeeper commonly used four-word commands are mainly as follows:

conf

3.3.0 Version introduced. Prints out the details of the service-related configuration. Cons version 3.3.0 was introduced. Lists all connection/session details for all clients connected to this server. Includes information such as the number of packets received/sent, session id, operation delay, final operation execution, etc. CRST version 3.3.0 was introduced. Reset connection and session statistics for all connections. Dump lists important sessions and temporary nodes. This command is only useful on the leader node. Envi prints out details of the service environment. Reqs lists unprocessed requests ruok tests whether the service is in the correct state. If so, the service returns "imok," otherwise nothing is done. stat outputs a list of clients about performance and connections. srst resets server statistics. srvr version 3.3.0 introduced. Lists the details of the connection server wchs version 3.3.0 introduced. Lists details of server watch. WCHC version 3.3.0 was introduced. By listing the details of the server watch session, its output is a list of watch-related sessions. WCHP version 3.3.0 was introduced. Lists details of server watch by path. It outputs a path associated with the session. mntr version 3.4.0 introduced. Outputs a list of variables that can be used to detect cluster health

The ##conf command, introduced in version 3.3.0, prints out server configuration details. So that OPS personnel can quickly view some configuration parameters of ZooKeeper server when it is currently running.

telnet example

You can see that some configuration items we did not configure in the zoo.cfg configuration file, the server uses the default configuration.

NC Example

operation mode

The conf command determines the server configuration information printed out according to the current running mode. The two examples above are examples in cluster mode. If it is standalone mode, cluster configuration information such as initLimit, syncLimit, electionAlg, and electionPort will not be output.

##cons cons The cons cons command, introduced in version 3.3.0, is used to output complete connection and session information for all clients connected to the server, including the number of packets received and sent, session IDs, operation delays, and last operations performed.

You can see that there is a client connection on this machine.

##crst The crst command was introduced in version 3.3.0 to reset connection and session statistics for all client connections.

##The dump dump command is used to output unfinished sessions and temporary nodes. ###leader example ###follower example

##envi The envi command prints information about environment variables when the server is running.

The ##ruok ruok command is used to test whether the current server is running. Returns "imok" if the server is running, otherwise nothing.

Note that the "imok" response does not necessarily indicate that the server has joined the cluster, only that the server process is active and bound to the specified client port. You can use "stat" to get cluster status and client connection information.

The ##srst srst command resets server statistics.

##srvr The srvr command was introduced in version 3.3.0 to output complete information about the server.

##stat The stat command is used to output profile information about the server and the clients connected to it.

The only difference between srvr and stat is that srvr does not output client profile information.

##wchs The wchs command was introduced in version 3.3.0 to output profile information about Watchers on the current server.

##wchc The wchc command was introduced in version 3.3.0 to output details of watches on the current server per session. It outputs a list of sessions (connections) and associated watches (paths).

Because there are no watches, there is no output.

Note that depending on the number of watches, this operation can be time-consuming (affecting server performance), so use it with caution.

##wchp The wchp command was introduced in version 3.3.0 to output details of watches on the current server by path. It outputs the path (znodes) along with a list of related sessions.

Again, because there are no watches, there is no output.

Note that depending on the number of watches, this operation can be time-consuming (affecting server performance), so use it with caution.

##mntr The mntr command was introduced in version 3.4.0 to output a list of variables that can be used to monitor cluster health. ###leader example ###follower example

As you can see from the above two examples, zk_followers, zk_synced_followers, and zk_pending_syncs are output only when the mntr command is run on the leader server. Note also that zk_open_file_descriptor_count and zk_max_file_descriptor_count are only available on Unix platforms.

The above is how to understand the zkServer.sh command, zkCli.sh command and four-word command in zookeeper. Xiaobian believes that some knowledge points may be seen or used in our daily work. I hope you can learn more from this article. For more details, please follow the industry information channel.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Internet Technology

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report