我正在编写一个脚本来记录我创建的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: starting member c0f27f3c63dd09c6 in cluster bd535900b5473128
答案 0 :(得分: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"]}]}