作者介绍:简历上没有一个精通的运维工程师,下面的思维导图也是预计更新的内容和当前进度(不定时更新)。
前面我们介绍介绍了几个常用的代理服务器,本章节我们讲来讲解Zookeeper这个中间件。
前面我们讲了很多关于ZooKeeper的细节信息,但是这些信息实际上都是原理类,在实际运维中很难用到,下面几个小节我们讲解下日常运维中的经常用到的操作。
我们前面已经讲过使用ZooKeeper给我们提供的脚本可以检查集群的角色,但是这个信息还是太少,我们怎么看到ZooKeeper运行详细信息呢,有没有可以查看集群运行情况的命令呢?他就是官方给我们提供了一个最简单的四字命令接口,可以读取Zookeeper的详细运行信息。
四字命令主要用于监控 ZooKeeper 服务器的状态,通过telnet
或nc
工具直接向 ZooKeeper 服务器发送指令。telnet 需要交互输入,所以使用没有nc方便,后面的演示都以nc命令为准(如果系统没有命令可以通过yum安装)。
在当前我使用的版本3.8.x里面默认就是关闭了该功能,或者说默认启用了黑名单,需要先添加白名单以后能使用,如果未添加则会出现下面的提示。
[root@localhost ~]# echo ruok |nc localhost 2181
ruok is not executed because it is not in the whitelist.
#添加配置文件以后,重启zookeeper服务
#实际环境需要考虑安全问题,避免将服务器信息暴露出去
#*代表开启所有,根据安全需求自己选择可以开启的指标。
4lw.commands.whitelist=*
下面则是4字命令的介绍
ruok
imok
,则表示服务器运行正常,检查状态推荐使用该命令,以前在生产环境使用另外一个命令,在高负载下可能会返回异常或超时。[root@localhost]# echo ruok |nc localhost 2181
imok[root@localhost]#
stat
[root@localhost ~]# echo stat |nc localhost 2181
Zookeeper version: 3.8.4-9316c2a7a97e1666d8f4593f34dd6fc36ecc436c, built on 2024-02-12 22:16 UTC
Clients:
/0:0:0:0:0:0:0:1:34710[0](queued=0,recved=1,sent=0)
Latency min/avg/max: 0/0.0/0
Received: 28
Sent: 27
Connections: 1
Outstanding: 0
Zxid: 0xe
Mode: standalone
Node count: 11
You have mail in /var/spool/mail/root
[root@localhost ~]#
envi
[root@localhost ~]# echo envi |nc localhost 2181
Environment:
zookeeper.version=3.8.4-9316c2a7a97e1666d8f4593f34dd6fc36ecc436c, built on 2024-02-12 22:16 UTC
host.name=localhost
java.version=1.8.0_231
java.vendor=Oracle Corporation
java.home=/usr/local/jdk1.8/jre
java.class.path=/opt/zookeeper1/bin/../zookeeper-server/target/classes:/opt/zookeeper1/bin/../build/classes:/opt/zookeeper1/bin/../zookeeper-server/target/lib/*.jar:/opt/zookeeper1/bin/../build/lib/*.jar:/opt/zookeeper1/bin/../lib/zookeeper-prometheus-metrics-3.8.4.jar:/opt/zookeeper1/bin/../lib/zookeeper-jute-3.8.4.jar:/opt/zookeeper1/bin/../lib/zookeeper-3.8.4.jar:/opt/zookeeper1/bin/../lib/snappy-java-1.1.10.5.jar:/opt/zookeeper1/bin/../lib/slf4j-api-1.7.30.jar:/opt/zookeeper1/bin/../lib/simpleclient_servlet-0.9.0.jar:/opt/zookeeper1/bin/../lib/simpleclient_hotspot-0.9.0.jar:/opt/zookeeper1/bin/../lib/simpleclient_common-0.9.0.jar:/opt/zookeeper1/bin/../lib/simpleclient-0.9.0.jar:/opt/zookeeper1/bin/../lib/netty-transport-native-unix-common-4.1.105.Final.jar:/opt/zookeeper1/bin/../lib/netty-transport-native-epoll-4.1.105.Final.jar:/opt/zookeeper1/bin/../lib/netty-transport-classes-epoll-4.1.105.Final.jar:/opt/zookeeper1/bin/../lib/netty-transport-4.1.105.Final.jar:/opt/zookeeper1/bin/../lib/netty-resolver-4.1.105.Final.jar:/opt/zookeeper1/bin/../lib/netty-handler-4.1.105.Final.jar:/opt/zookeeper1/bin/../lib/netty-common-4.1.105.Final.jar:/opt/zookeeper1/bin/../lib/netty-codec-4.1.105.Final.jar:/opt/zookeeper1/bin/../lib/netty-buffer-4.1.105.Final.jar:/opt/zookeeper1/bin/../lib/metrics-core-4.1.12.1.jar:/opt/zookeeper1/bin/../lib/logback-core-1.2.13.jar:/opt/zookeeper1/bin/../lib/logback-classic-1.2.13.jar:/opt/zookeeper1/bin/../lib/jline-2.14.6.jar:/opt/zookeeper1/bin/../lib/jetty-util-ajax-9.4.53.v20231009.jar:/opt/zookeeper1/bin/../lib/jetty-util-9.4.53.v20231009.jar:/opt/zookeeper1/bin/../lib/jetty-servlet-9.4.53.v20231009.jar:/opt/zookeeper1/bin/../lib/jetty-server-9.4.53.v20231009.jar:/opt/zookeeper1/bin/../lib/jetty-security-9.4.53.v20231009.jar:/opt/zookeeper1/bin/../lib/jetty-io-9.4.53.v20231009.jar:/opt/zookeeper1/bin/../lib/jetty-http-9.4.53.v20231009.jar:/opt/zookeeper1/bin/../lib/javax.servlet-api-3.1.0.jar:/opt/zookeeper1/bin/../lib/jackson-databind-2.15.2.jar:/opt/zookeeper1/bin/../lib/jackson-core-2.15.2.jar:/opt/zookeeper1/bin/../lib/jackson-annotations-2.15.2.jar:/opt/zookeeper1/bin/../lib/commons-io-2.11.0.jar:/opt/zookeeper1/bin/../lib/commons-cli-1.5.0.jar:/opt/zookeeper1/bin/../lib/audience-annotations-0.12.0.jar:/opt/zookeeper1/bin/../zookeeper-*.jar:/opt/zookeeper1/bin/../zookeeper-server/src/main/resources/lib/*.jar:/opt/zookeeper1/bin/../conf:
java.library.path=/usr/java/packages/lib/amd64:/usr/lib64:/lib64:/lib:/usr/lib
java.io.tmpdir=/tmp
java.compiler=<NA>
os.name=Linux
os.arch=amd64
os.version=3.10.0-1127.19.1.el7.x86_64
user.name=root
user.home=/root
user.dir=/opt/zookeeper1/conf
os.memory.free=12MB
os.memory.max=966MB
os.memory.total=27MB
[root@localhost ~]#
conf
[root@localhost ~]# echo conf |nc localhost 2181
clientPort=2181
secureClientPort=-1
dataDir=/opt/zookeeper/data/version-2
dataDirSize=134221115
dataLogDir=/opt/zookeeper/data/version-2
dataLogSize=134221115
tickTime=2000
maxClientCnxns=60
minSessionTimeout=4000
maxSessionTimeout=40000
clientPortListenBacklog=-1
serverId=0
srst
[root@localhost ~]# echo srst |nc localhost 2181
Server stats reset.
[root@localhost ~]#
wchs
[root@localhost ~]# echo wchs |nc localhost 2181
0 connections watching 0 paths
Total watches:0
[root@localhost ~]#
mntr
[root@localhost ~]# echo mntr |nc localhost 2181
zk_version 3.8.4-9316c2a7a97e1666d8f4593f34dd6fc36ecc436c, built on 2024-02-12 22:16 UTC
zk_server_state standalone
zk_dead_watchers_queued 0.0
zk_sessionless_connections_expired 0.0
zk_om_proposal_process_time_ms{quantile="0.5"} NaN
zk_om_proposal_process_time_ms{quantile="0.9"} NaN
zk_om_proposal_process_time_ms{quantile="0.99"} NaN
#后面部分省略
当然这里只列举了部分4字命令,不同的版本会有不同的4字命令,使用这个需要注意的就是安全。