AdminServer 是 ZooKeeper 3.5 起内置的 HTTP 管理接口,默认端口 8080,命令比四字命令多、输出是 JSON。这篇在自己选定的端口上开启它,看有哪些命令、返回什么、和 mntr 的关系。
GET /commands → 200,Content-Type: None;返回的是一个 HTML 链接列表,可用命令 28 个:['configuration', 'connection_stat_reset', 'connections', 'dirs', 'dump', 'environment', 'get_trace_mask', 'hash', 'initial_configuration', 'is_read_only', 'last_snapshot', 'leader', 'monitor', 'observer_connection_stat_reset', 'observers', 'restore', 'ruok', 'server_stats', 'set_trace_mask', 'snapshot', 'stat_reset', 'stats', 'system_properties', 'voting_view', 'watch_summary', 'watches', 'watches_by_path', 'zabstate']
默认端口 8080 是个常见的冲突点(很多服务都用它),我在本机就遇到了这种情况,所以全部实验里都关闭了 AdminServer(admin.enableServer=false),只有这一篇用自选的端口打开它。
/commands/ruok → 200 {'command': 'ruok', 'error': None}
/commands/stats → 200 {'version': '3.9.6-${mvngit.commit.id}, built on 2026-09-14 21:34 UTC', 'read_only': False, 'server_stats': '<dict 18>', 'client_response': '<dict 3>', 'node_count': 25, 'connections': '<list 1>'}
/commands/monitor → 200 {'version': '3.9.6-${mvngit.commit.id}, built on 2026-09-14 21:34 UTC', 'server_state': 'standalone', 'ephemerals_count': 0, 'num_alive_connections': 1, 'avg_latency': 3.5238, 'outstanding_requests': 0}
/commands/configuration → 200 {'client_port': 7300, 'data_dir': '<实验目录>', 'data_log_dir': '/privat
/commands/connections → 200 {'connections': '<list 1>', 'secure_connections': '<list 0>', 'command': 'connections', 'error': None}monitor 里的 znode_count = 25 | mntr 里的 zk_znode_count = 25 | monitor 里 outstanding_requests = 0 monitor 的字段数: 596 | mntr 的指标数: 402
GET /commands/nope → 200 {
"command" : "nope",
"error" : "Unknown command: nope"
}AdminServer 也没有内置认证(是否需要 HTTPS / 客户端证书用 admin.portUnification、admin.forceHttps 之类的参数,本文没有测),所以与四字命令一样,应当只绑定内网或本机。