完全新实例替换
从集群中删除节点
$ etcdctl member remove a8266ecf031671f3
删除的即使是leader,也是安全的,但在选举新leader期间,集群会处于非活跃状态。此持续时间通常是选举超时时间加上投票过程的时间
添加新节点
$ etcdctl member add infra3 --peer-urls=http://10.0.1.13:2380
执行此命令会并打印出成功启动新实例所需的环境变量
在使用新成员的相关标志启动新的 etcd 进程,新实例会立刻开始同步追赶集群
!!!如果添加多个成员,需要逐一添加,在添加更多新成员之前验证其是否正确启动
迁移异常member的数据目录
如果集群的v2 data大小超过50MB,建议执行此操作
当计划进行机器维护或退役时,可以将 etcd 成员迁移到另一台机器,而不会丢失数据和更改成员 ID
1.停止etcd进程
2.拷贝etcd data数据
3.更新peer URL
3.1)查看确认集群信息
$ export ETCDCTL_ENDPOINT=http://10.0.1.10:2379,http://10.0.1.11:2379,http://10.0.1.12:2379
$ etcdctl member list
84194f7c5edd8b37: name=infra0 peerURLs=http://10.0.1.10:2380 clientURLs=http://127.0.0.1:2379,http://10.0.1.10:2379
b4db3bf5e495e255: name=infra1 peerURLs=http://10.0.1.11:2380 clientURLs=http://127.0.0.1:2379,http://10.0.1.11:2379
bc1083c870280d44: name=infra2 peerURLs=http://10.0.1.12:2380 clientURLs=http://127.0.0.1:2379,http://10.0.1.12:2379
3.2)执行更新
$ curl http://10.0.1.10:2379/v2/members/b4db3bf5e495e255 -XPUT \
-H "Content-Type: application/json" -d '{"peerURLs":["http://10.0.1.13:2380"]}'
或者
$ etcdctl member update b4db3bf5e495e255 http://10.0.1.13:2380