bigywater.tech
ZooKeeper · 66

ZooKeeper 四字命令

四字命令(ruok、stat、mntr……)是 ZooKeeper 运维最古老的接口。现在它默认几乎全部被禁用了。这篇把每条命令在默认配置和放开白名单之后的真实输出都打印一遍。

只有 srvr
默认白名单里唯一能用的命令
4lw.commands.whitelist
用这个参数放开,* 表示全部
17 个命令
本文实测的四字命令个数

默认只有 srvr

实测 · 本机执行输出
  默认白名单生效的配置行: (没有写 4lw 白名单)
  ruok  → ruok is not executed because it is not in the whitelist.
  srvr  → Zookeeper version: 3.9.6-${mvngit.commit.id}, built on 2026-09-14 21:34 UTC
  stat  → stat is not executed because it is not in the whitelist.
  conf  → conf is not executed because it is not in the whitelist.
  cons  → cons is not executed because it is not in the whitelist.
  crst  → crst is not executed because it is not in the whitelist.
  dirs  → dirs is not executed because it is not in the whitelist.
  dump  → dump is not executed because it is not in the whitelist.
  envi  → envi is not executed because it is not in the whitelist.
  gtmk  → gtmk is not executed because it is not in the whitelist.
  isro  → isro is not executed because it is not in the whitelist.
  mntr  → mntr is not executed because it is not in the whitelist.
  srst  → srst is not executed because it is not in the whitelist.
  wchc  → wchc is not executed because it is not in the whitelist.
  wchp  → wchp is not executed because it is not in the whitelist.
  wchs  → wchs is not executed because it is not in the whitelist.
  hash  → hash is not executed because it is not in the whitelist.
  日志里的启用列表: ['The list of enabled four letter word commands is : [[srvr]]']

放开白名单后的输出

实测 · 本机执行输出
  [ruok]
      imok
  [srvr]
      Zookeeper version: 3.9.6-${mvngit.commit.id}, built on 2026-09-14 21:34 UTC
      Latency min/avg/max: 1/5.25/9
      Received: 8
  [stat]
      Zookeeper version: 3.9.6-${mvngit.commit.id}, built on 2026-09-14 21:34 UTC
      Clients:
       /127.0.0.1:59127[0](queued=0,recved=1,sent=0)
  [conf]
      clientPort=7301
      secureClientPort=-1
      dataDir=<实验目录>
  [cons]
      /127.0.0.1:59123[1](queued=0,recved=3,sent=3,sid=0x1000c5946950000,lop=GETD,est=1790827416994,to=10000,lcxid=0
       /127.0.0.1:59124[1](queued=0,recved=1,sent=1,sid=0x1000c5946950001,lop=SESS,est=1790827417020,to=10000,lcxid=
       /127.0.0.1:59129[0](queued=0,recved=1,sent=0)
  [dirs]
      datadir_size: 67109358
      logdir_size: 67109358
  [dump]
      SessionTracker dump:
      Session Sets (1)/(2):
      2 expire at Thu Oct 01 12:03:47 CST 2026:
  [envi]
      Environment:
      zookeeper.version=3.9.6-${mvngit.commit.id}, built on 2026-09-14 21:34 UTC
      host.name=localhost
  [gtmk]
      306
  [isro]
      rw
  [wchs]
      1 connections watching 1 paths
      Total watches:1
  [wchp]
      /a
      	0x1000c5946950000
  [wchc]
      0x1000c5946950000
      	/a

另外还有 mntr、crst、srst、hash 等命令,mntr 的输出在第 65 篇,srst / crst 会清零统计(第 67 篇)。

分步演示

四字命令
本步的对象

    本文用到的工具与边界

    • 本机 macOS 27 / ZooKeeper 3.9.6(brew 安装的 jar,用 java -cp 直接启动自己的实例,OpenJDK 17 Temurin,JVM 堆 128 MiB)/ 本机回环端口 7300+,数据在临时目录;默认 tickTime=2000;计时用 time.perf_counter,数字每次运行会有小幅抖动。单机;命令通过 TCP 连到客户端端口直接发送四个字母;输出只截取前几行
    • 没有验证:AdminServer 上对应的命令(第 68 篇)、集群里 leader 才有的信息(dump 的 Session Sets 等,第 12 篇)、较旧版本的默认值
    京ICP备2026067502号-1京公网安备11010502063487号