etcd 3.1.9版本,使用。
etcdcrt member list.
可以看到 isLeader=false
或isLeader=true
。
etcd -version
etcd Version: 3.1.9
Git SHA: 0f4a535
Go Version: go1.7.4
Go OS/Arch: linux/amd64
etcdctl member list
29cae73abe8480e0: name=infra3 peerURLs=http://192.168.2.188:2380 clientURLs=http://192.168.2.188:2379 isLeader=false
ddfd1a6f3be67384: name=infra1 peerURLs=http://192.168.2.186:2380 clientURLs=http://192.168.2.186:2379 isLeader=true
fd49f5e3ec73b0d2: name=infra2 peerURLs=http://192.168.2.187:2380 clientURLs=http://192.168.2.187:2379 isLeader=false
但 etcd 3.2.x
和 3.3.1
版本没有显示这个。
那么我怎么知道哪个是leader呢?
etcd --version
etcd Version: 3.3.1
Git SHA: 28f3f26
Go Version: go1.9.4
Go OS/Arch: linux/amd64
etcdctl member list
1114740c6d5f9f2, started, etcd1, https://192.168.9.186:2380, https://192.168.9.186:2379
4d19012a3d971b72, started, etcd2, https://192.168.9.187:2380, https://192.168.9.187:2379
e30c8a56457f8a6a, started, etcd3, https://192.168.9.188:2380, https://192.168.9.188:2379
我想知道哪一个是leader?
有什么命令可以显示谁是master吗?
使用
endpoint status
可以显示leader。$ ETCDCTL_API=3 etcdctl -w table --endpoints=etcd1:2379,etcd2:2379,etcd0:2379 endpoint status +------------+------------------+---------+---------+-----------+-----------+------------+ | ENDPOINT | ID | VERSION | DB SIZE | IS LEADER | RAFT TERM | RAFT INDEX | +------------+------------------+---------+---------+-----------+-----------+------------+ | etcd1:2379 | ade526d28b1f92f7 | 3.3.1 | 467 MB | true | 27 | 6289071 | | etcd2:2379 | d282ac2ce600c1ce | 3.3.1 | 467 MB | false | 27 | 6289071 | | etcd0:2379 | cf1d15c5d194b5c9 | 3.3.1 | 467 MB | false | 27 | 6289071 | +------------+------------------+---------+---------+-----------+-----------+------------+
还有可以使用
--cluster
,更便捷,不必使用--endpoints
标志来单独指定每个端点。$ ETCDCTL_API=3 etcdctl endpoint status --cluster -w table +----------------------------+------------------+---------+---------+-----------+-----------+------------+ | ENDPOINT | ID | VERSION | DB SIZE | IS LEADER | RAFT TERM | RAFT INDEX | +----------------------------+------------------+---------+---------+-----------+-----------+------------+ | http://192.168.144.11:2379 | 939e974d80fa7dd5 | 3.3.13 | 20 kB | true | 2 | 12 | | http://192.168.144.13:2379 | bd04095b49eb535c | 3.3.13 | 20 kB | false | 2 | 12 | | http://192.168.144.12:2379 | cf7585769b2ce974 | 3.3.13 | 20 kB | false | 2 | 12 | +----------------------------+------------------+---------+---------+-----------+-----------+------------+
感谢大佬,save my live!
请问大佬,api里面有这种查看集群节点和leader的接口么,找了半天,发现在client里面有NewMemberAPI可以导出,但是client3里面的MemberList看不到leader信息。。
看了下源码实现,找到了,这个命令是用的cli.Status,但是查出来的是ID,需要用member list的名称对应一下
你的答案