【问题标题】:How to get etcd cluster ID from script?如何从脚本中获取 etcd 集群 ID?
【发布时间】:2019-10-14 22:37:21
【问题描述】:

我正在编写一个脚本来记录我创建的etcd 集群。我想检索集群 ID 和成员 ID 并将其写入报告。

我可以使用etcdctl member list轻松获取会员ID。

$ etcdctl member list
7a37a8973f10a944, started, etcd22, http://192.168.144.22:2380, http://192.168.144.22:2379
bda5a1801ac0115d, started, etcd21, http://192.168.144.21:2380, http://192.168.144.21:2379
c0f27f3c63dd09c6, started, etcd23, http://192.168.144.23:2380, http://192.168.144.23:2379

但是,如何从脚本中获取集群 ID?我看到它打印的唯一地方是stdout 第一次初始化etcd 时。

etcdserver:集群中的起始成员 c0f27f3c63dd09c6 bd535900b5473128

【问题讨论】:

    标签: etcd etcdctl


    【解决方案1】:

    来自服务器的 RPC 响应具有包含集群 ID 的标头。通过改变输出格式,可以显示表头信息。

    例如:

    $ etcdctl member list -w fields
    "ClusterID" : 14841639068965178418
    "MemberID" : 10276657743932975437
    "Revision" : 0
    "RaftTerm" : 3
    "ID" : 10276657743932975437
    "Name" : "default"
    "PeerURL" : "http://localhost:2380"
    "ClientURL" : "http://localhost:2379"
    

    $ etcdctl member list -w json
    {"header":{"cluster_id":14841639068965178418,"member_id":10276657743932975437,"raft_term":3},"members":[{"ID":10276657743932975437,"name":"default","peerURLs":["http://localhost:2380"],"clientURLs":["http://localhost:2379"]}]}
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2021-01-22
      • 1970-01-01
      • 2021-02-08
      • 2019-06-04
      • 2020-04-05
      • 2019-11-21
      • 2015-12-18
      • 1970-01-01
      相关资源
      最近更新 更多