1. Four-word command

Zookeeper provides many four-letter O&M commands, which are called four-character commands for short.

1.1. Method of use

Four-word commands can be used in two simple ways. The introduction is as follows:

  • Telnet way

    Example:

    #The connection
    telnet <ip> <port>
    
    #Type the commandThe < command >Copy the code
  • Nc mode

    The echo command < > | nc < IP > < port >Copy the code

    If no, install it first

    #Installation as user root
    #Downloading the Installation packageWget HTTP: / / http://vault.centos.org/6.6/os/x86_64/Packages/nc-1.84-22.el6.x86_64.rpm#The RPM installationThe RPM - iUv nc - 1.84-22. El6. X86_64. RPMCopy the code

1.2 commands

1.2.1, conf

The conf command is used to display the basic configuration information of the Zookeeper server.

echo conf | nc localhost 2181
Copy the code
attribute instructions
clientPort The client connection port number is leaked.
dataDir Data snapshot file directory. By default, a snapshot is generated every 100,000 transactions.
dataLogDir Transaction log file directory on a separate disk in a production environment.
tickTime The interval, in milliseconds, between servers or between clients and servers for maintaining heartbeats.
maxClientCnxns Maximum number of connections.
minSessionTimeout MinSessionTimeout minSessionTimeout=tickTime*2
maxSessionTimeout MaxSessionTimeout =tickTime*20
serverId Number of the server.
initLimit Maximum number of heartbeats tolerated by the follower server (F) and the leader server (L) in the cluster during the initial connection.
syncLimit Maximum number of heartbeats that can be tolerated between the follower server (F) and the leader server (L) in the cluster.
electionAlg 0: UDP-based LeaderElection 1: UDP-based FastLeaderElection 2: UDP-based and Authenticated FastLeaderElection 3: TCP-based FastLeaderElection in version 3.4.10, The default value is 3. The other three algorithms have been deprecated and there are plans to remove them completely from support in future releases.
electionPort Election port.
quorumPort Data communication port.
peerType Observer 1: observer.
1.2.2, cons

The cons command is used to print details of all client connections on the current server.

echo cons | nc localhost 2181
Copy the code
attribute instructions
ip The IP address
port The port number
queued The number of requests waiting to be processed, cached in the queue
received Number of packets received
sent Number of packets sent
sid The session id
lop The final operation GETD- read data DELE- delete data CREA- create data
est Connection timestamp
to timeout
lcxid Operation ID of the current session
lzxid Maximum transaction ID
lresp Last response time stamp
llat Last/latest delay
minlat The minimum time delay
maxlat Maximum delay
avglat Average latency
1.2.3, CRST

The CRST command is a functional command that resets all client connection statistics.

echo crst | nc localhost 2181
Copy the code
1, the dump

The dump command displays information about all sessions in the current cluster, including the session ids of these sessions and temporary nodes created for each session.

echo dump | nc localhost 2181
Copy the code
attribute instructions
session id Znode path (1 to many, queued session and temporary node)
1.2.5, envi

The envi command is used to output the running environment information of the Zookeeper server.

echo envi | nc localhost 2181
Copy the code
attribute instructions
zookeeper.version version
host.name The host information
java.version Java version
java.vendor supplier
java.home Directory where the running environment resides
java.class.path classpath
java.library.path Third-party libraries specify the location of non-Java class packages (e.g., DLL, SO)
java.io.tmpdir Default temporary file path
java.compiler The name of the JIT compiler
os.name Linux
os.arch amd64
os.version 3.10.0-514. El7 x86_64
user.name zookeeper
user.home User name Directory
user.dir Service Directory
1.2.6, ruok

The ruok command is used to display whether the Zookeeper server is running.

echo ruok | nc localhost 2181
Copy the code

Return “imok” if the current Zookeeper server is running, otherwise there is no response.

1.2.7, stat

The stat command is used to obtain the running status of the Zookeeper server.

echo stat | nc localhost 2181
Copy the code
attribute instructions
Zookeeper version version
Clients List of client connections
Latency min/avg/max Time delay
Received Receive package
Sent Contract awarding
Connections The number of connections
Outstanding Accumulation number
Zxid Maximum transaction ID
Mode Server role
Node Number of nodes
1.2.8, SRVR

The SRVR command has the same function as the stat command. The only difference is that the SRVR command does not output the connection information of the client, but only the information about the server.

1.2.9, SRST

The SRST command is a feature line command that resets statistics for all servers.

echo srst | nc localhost 2181
Copy the code
1.2.10, WCHS

The WCHS command is used to display the summary of the Watcher managed on the current server.

echo wchs | nc localhost 2181
Copy the code
attribute instructions
connectsions The number of connections
watch-paths Watch the node number
watchers Watcher number
1.2.11, WCHC

The WCHC command is used to display detailed information about the Watcher managed on the current server, which is grouped by session, and lists the paths of nodes registered with the Watcher by the session.

echo wchc | nc localhost 2181
Copy the code

Question:

wchc is not executed because it is not in the whitelist.
Copy the code

Solutions:

# Change the startup command zkserver.shPay attention to find this information
else
    echo "JMX disabled by user request" >&2
    ZOOMAIN="org.apache.zookeeper.server.quorum.QuorumPeerMain" 
fiAdd the following information below
ZOOMAIN="-Dzookeeper.4lw.commands.whitelist=* ${ZOOMAIN}"
Copy the code
1.2.12, WCHP

The WCHP command is similar to the WCHC command. It is also used to display details about the Watcher managed on the current server. The difference is that the output information of the WCHP command is grouped by node path.

echo wchp | nc localhost 2181
Copy the code
1.2.13, MNTR

The MNTR command is used to output more detailed server statistics than the stat command.

attribute instructions
zk_version version
zk_avg_latency Average latency
zk_max_latency Maximum delay
zk_min_latency The minimum time delay
zk_packets_received Receive packets
zk_packets_sent Contract number
zk_num_alive_connections The number of connections
zk_outstanding_requests Stack request number
zk_server_state The leader/follower state
zk_znode_count Number of znode
zk_watch_count Watch the number
zk_ephemerals_count Temporary node (ZNode)
zk_approximate_data_size Data size
zk_open_file_descriptor_count Number of open file descriptors
zk_max_file_descriptor_count Maximum number of file descriptors
zk_fsync_threshold_exceed_count 0

2, Zookeeper graphical client tool (ZooInspector)

ZooInspector download

https://issues.apache.org/jira/secure/attachment/12436620/ZooInspector.zip
Copy the code

Unzip the file, go to the directory ZooInspector\build, and run zookeeper-dev-zooinspector

# Java -jar zookeeper-dev-zooinspectorCopy the code

Click the connect button in the upper left corner and enter zK service address: IP or host name :2181

Click OK to view ZK node information

TaoKeeper monitoring tool

Taokeeper, a monitoring and management tool based on ZooKeeper, is an open source ZK management middleware from Taobao team. Nc and SSHD are required to be configured before installation

1. Download the database script

wget https://github.com/downloads/alibaba/taokeeper/taokeeper.sql
Copy the code

2. Download the main program

wget https://github.com/downloads/alibaba/taokeeper/taokeeper-monitor.tar.gz
Copy the code

3. Download the configuration file

wget https://github.com/downloads/alibaba/taokeeper/taokeeper-monitor-config.properties
Copy the code

4. Configuration taokeeper – monitor – config. Properties

#Daily systeminfo. envName= Daily #DBCP dbcp.driverClassName= com.mysql.jdbc.driver # MYSQL connection IP address port number DBCP. DbJDBCUrl = JDBC: mysql: / / localhost: 3306 / taokeeper DBCP. GBK characterEncoding = # username DBCP. # username = root password Dbcp. password=root dbcp.maxActive=30 dbcp.maxIdle=10 dbcp.maxWait=10000 #SystemConstant # Folder where the user stores internal data # to create/home/zookeeper/taokeeperdata/ZooKeeperClientThroughputStat SystemConstent. DataStoreBasePath = / home/zookeeper/taokeeperdata # SSH user SystemConstant userNameOfSSH = zookeeper # SSH password SystemConstant.passwordOfSSH=zookeeper #Optional SystemConstant.portOfSSH=22Copy the code

5. Install and configure Tomcat, and modify catalina.sh

# point to the location of the configuration file JAVA_OPTS=-DconfigFilePath="/home/zookeeper/taokeeper-monitor-tomcat/webapps/ROOT/conf/taokeeper-monitor-config.properti es"Copy the code

6. The deployment project is started