zookeeper-查询zk服务器成员列表

查询zookeeper服务器成员列表

1. 通过Jmx公开的信息,查询服务器成员列表。

2. 您可以阅读zoo.cfg文件以获取zk服务器成员列表(死亡和活动的)

3. 自从3.4.0开始,新增内容:输出可用于监视群集运行状况的变量列表。

$ echo mntr | nc 192.168.10.133 2181

zk_version  3.4.0
zk_avg_latency  0
zk_max_latency  0
zk_min_latency  0
zk_packets_received 70
zk_packets_sent 69
zk_outstanding_requests 0
zk_server_state leader
zk_znode_count   4
zk_watch_count  0
zk_ephemerals_count 0
zk_approximate_data_size    27
zk_followers    4                   - only exposed by the Leader
zk_synced_followers 4               - only exposed by the Leader
zk_pending_syncs    0               - only exposed by the Leader
zk_open_file_descriptor_count 23    - only available on Unix platforms
zk_max_file_descriptor_count 1024   - only available on Unix platforms

注释:

  • zk_server_state leader #本节点是leader
  • zk_followers    4      #有4个followers

4. 显示zkServer配置文件中的成员列表:

echo stat |nc kafka-03.server 2181
Zookeeper version: 3.4.10-39d3a4f269333c922ed3db283be479f9deacaa0f, built on 03/23/2017 10:13 GMT
Clients:
 /192.168.10.133:59882[1](queued=0,recved=567716,sent=567716)
 /192.168.10.134:39442[1](queued=0,recved=523923,sent=523924)
 /192.168.15.115:62226[0](queued=0,recved=1,sent=0)
 /192.168.10.133:59332[1](queued=0,recved=82636,sent=82638)

Latency min/avg/max: 0/0/5754
Received: 8304257
Sent: 8302764
Connections: 4
Outstanding: 0
Zxid: 0x40001b172
Mode: leader
Node count: 14058

 

5. 使用zkCli.sh 查询zk服务器中配置文件的服务列表:

$ ./bin/zkCli.sh -server localhost:2181
[zk: localhost:3181(CONNECTED) 3] get /zookeeper/config
server.1=192.168.5.20:2881:3881:participant
server.2=192.168.5.21:3881:4881:participant
version=0

AdminServer : https://zookeeper.apache.org/doc/r3.5.1-alpha/zookeeperAdmin.html

3.5.0中的新增功能: AdminServer是嵌入式Jetty服务器,为四个字母单词命令提供HTTP接口。默认情况下,服务器在端口8080上启动,并且通过访问URL"/commands/[command name]"发出命令,例如http://localhost:8080/commands/stat。命令响应作为JSON返回。与原始协议不同,命令不限于四个字母的名称,命令可以具有多个名称。例如,“ stmk”也可以称为"set_trace_mask"。要查看所有可用命令的列表,请将浏览器指向URL/commands(例如,http://localhost:8080/commands)。

AdminServer默认情况下处于启用状态,但可以通过以下任一方式禁用:

  • 将zookeeper.admin.enableServer系统属性设置为false。

  • 从类路径中删除Jetty。(如果您想覆盖ZooKeeper's jetty依赖,则此选项很有用。)

请注意,如果AdminServer被禁用,则TCP四字母词接口仍然可用。

$ curl http://localhost:8081/commands/mntr
{
  "version" : "3.5.5-390fe37ea45dee01bf87dc1c042b5e3dcce88653, built on 05/03/2019 12:07 GMT",
  "avg_latency" : 0,
  "max_latency" : 0,
  "min_latency" : 0,
  "packets_received" : 0,
  "packets_sent" : 0,
  "num_alive_connections" : 0,
  "outstanding_requests" : 0,
  "server_state" : "leader",
  "znode_count" : 5,
  "watch_count" : 0,
  "ephemerals_count" : 0,
  "approximate_data_size" : 135,
  "open_file_descriptor_count" : 73,
  "max_file_descriptor_count" : 10240,
  "last_client_response_size" : -1,
  "max_client_response_size" : -1,
  "min_client_response_size" : -1,
  "followers" : 2,
  "synced_followers" : 2,
  "pending_syncs" : 0,
  "last_proposal_size" : 36,
  "max_proposal_size" : 36,
  "min_proposal_size" : 36,
  "command" : "monitor",
  "error" : null
}
  • "server_state" : "leader" #本节点是leader
  •  "followers" : 2 # 有两个fowllower
$ curl http://localhost:8081/commands/stat
{
  "version" : "3.5.5-390fe37ea45dee01bf87dc1c042b5e3dcce88653, built on 05/03/2019 12:07 GMT",
  "read_only" : false,
  "server_stats" : {
    "packets_sent" : 0,
    "packets_received" : 0,
    "max_latency" : 0,
    "min_latency" : 0,
    "fsync_threshold_exceed_count" : 0,
    "client_response_stats" : {
      "last_buffer_size" : -1,
      "min_buffer_size" : -1,
      "max_buffer_size" : -1
    },
    "data_dir_size" : 201328199,
    "log_dir_size" : 201328199,
    "last_processed_zxid" : 12884901889,
    "provider_null" : false,
    "num_alive_client_connections" : 0,
    "server_state" : "leader",
    "outstanding_requests" : 0,
    "avg_latency" : 0
  },
  "client_response" : {
    "last_buffer_size" : -1,
    "min_buffer_size" : -1,
    "max_buffer_size" : -1
  },
  "proposal_stats" : {
    "last_buffer_size" : 36,
    "min_buffer_size" : 36,
    "max_buffer_size" : 36
  },
  "node_count" : 5,
  "connections" : [ ],
  "command" : "stats",
  "error" : null
}

 

如果使用nc 访问,提示:“stat is not executed because it is not in the whitelist.” 参考:https://www.cnblogs.com/jonrain0625/p/11377508.html 解决。

参考:
zk命令行使用:http://zookeeper.apache.org/doc/r3.4.10/zookeeperAdmin.html#sc_zkCommands
zk监控:http://zookeeper.apache.org/doc/r3.4.10/zookeeperJMX.html
https://stackoverflow.com/questions/16669104/how-to-get-current-zookeeper-clusters-member-server-list

你可能感兴趣的:(kafka)