systemctl enable etcd.service systemctl start etcd.service systemctl status etcd.service
测试和验收
1、检查各节点
1 2 3 4
root@pts/1 $ etcdctl member list 59b0ee3829e2b866: name=etcd2 peerURLs=http://192.168.2.214:2380 clientURLs=http://192.168.2.214:2379 isLeader=false a8b07bac1693e30e: name=etcd1 peerURLs=http://192.168.2.213:2380 clientURLs=http://192.168.2.213:2379 isLeader=false cf682ab5655702b8: name=etcd3 peerURLs=http://192.168.2.215:2380 clientURLs=http://192.168.2.215:2379 isLeader=true
2、检查集群状态
1 2 3 4 5
root@pts/1 $ etcdctl cluster-health member 59b0ee3829e2b866 is healthy: got healthy result from http://192.168.2.214:2379 member a8b07bac1693e30e is healthy: got healthy result from http://192.168.2.213:2379 member cf682ab5655702b8 is healthy: got healthy result from http://192.168.2.215:2379 cluster is healthy
3、进行测试
1 2 3 4 5
root@pts/1 $ etcdctl set /demo 'hello etcd' hello etcd
root@pts/1 $ etcdctl get /demo hello etcd
故障演练
停掉Leader节点
1 2 3 4
root@pts/1 $ etcdctl member list 59b0ee3829e2b866: name=etcd2 peerURLs=http://192.168.2.214:2380 clientURLs=http://192.168.2.214:2379 isLeader=false a8b07bac1693e30e: name=etcd1 peerURLs=http://192.168.2.213:2380 clientURLs=http://192.168.2.213:2379 isLeader=true cf682ab5655702b8: name=etcd3 peerURLs=http://192.168.2.215:2380 clientURLs=http://192.168.2.215:2379 isLeader=false
看到Leader从etcd3转移到etcd1
查看集群状态
1 2 3 4 5 6
root@pts/1 $ etcdctl cluster-health member 59b0ee3829e2b866 is healthy: got healthy result from http://192.168.2.214:2379 member a8b07bac1693e30e is healthy: got healthy result from http://192.168.2.213:2379 failed to check the health of member cf682ab5655702b8 on http://192.168.2.215:2379: Get http://192.168.2.215:2379/health: dial tcp 192.168.2.215:2379: connect: connection refused member cf682ab5655702b8 is unreachable: [http://192.168.2.215:2379] are all unreachable cluster is healthy
看到etcd3连接失败,这个时候在执行如下命令进行测试,发现请求正常
1 2
root@pts/1 $ etcdctl get /demo hello etcd
然后启动故障节点之后检查,集群状态恢复
1 2 3 4 5
root@pts/1 $ etcdctl cluster-health member 59b0ee3829e2b866 is healthy: got healthy result from http://192.168.2.214:2379 member a8b07bac1693e30e is healthy: got healthy result from http://192.168.2.213:2379 member cf682ab5655702b8 is healthy: got healthy result from http://192.168.2.215:2379 cluster is healthy