ETCDCTL_API=3 etcdctl --endpoints=http://192.168.122.124:2379 member add node2 --peer-urls=http://192.168.122.23:2380
1 2 3 4 5 6 7 8 9
/opt/etcd/bin/etcdctl --endpoints=http://172.17.0.100:2379 member add test-uid-1 --peer-urls=http://172.17.0.101:2380 /opt/etcd/bin/etcdctl --write-out=table --endpoints=http://172.17.0.100:2379 member list
# remove /opt/etcd/bin/etcdctl --endpoints=http://172.17.0.100:2379 member remove $(/opt/etcd/bin/etcdctl --endpoints=http://172.17.0.100:2379 member list | grep http://172.17.0.101:2380 | cut -d',' -f1)
ETCDCTL_API=3 etcdctl --endpoints=http://192.168.122.124:2379 member add node3 --peer-urls=http://192.168.122.95:2380
验证集群状态
在任意一个节点上使用 etcdctl 命令验证集群状态,确保所有节点都已成功加入集群:
1 2 3
ETCDCTL_API=3 etcdctl --endpoints=http://192.168.122.124:2379 member list ETCDCTL_API=3 etcdctl --endpoints=http://192.168.122.23:2379 member list ETCDCTL_API=3 etcdctl --endpoints=http://192.168.122.95:2379 member list
验证数据一致性
在所有节点上验证存入的键值对:
1 2 3
ETCDCTL_API=3 etcdctl --endpoints=http://192.168.122.124:2379 get foo ETCDCTL_API=3 etcdctl --endpoints=http://192.168.122.23:2379 get foo ETCDCTL_API=3 etcdctl --endpoints=http://192.168.122.95:2379 get foo
三节点到单节点
1. 从 node3 开始移除
在 node1 (192.168.122.124) 上使用 etcdctl 命令移除 node3
1
ETCDCTL_API=3 etcdctl --endpoints=http://192.168.122.124:2379 member remove $(ETCDCTL_API=3 etcdctl --endpoints=http://192.168.122.124:2379 member list | grep http://192.168.122.95:2380 | cut -d',' -f1)
验证 node3 是否已移除:
1
ETCDCTL_API=3 etcdctl --endpoints=http://192.168.122.124:2379 member list
确认 node3 不在成员列表中。
2. 移除 node2
在 node1 (192.168.122.124) 上使用 etcdctl 命令移除 node2
1
etcdctl --endpoints=http://192.168.122.124:2379 member remove $(etcdctl --endpoints=http://192.168.122.124:2379 member list | grep http://192.168.122.23:2380 | cut -d',' -f1)
验证 node2 是否已移除:
1
ETCDCTL_API=3 etcdctl --endpoints=http://192.168.122.124:2379 member list