etcd操作

--name:方便理解的节点名称,默认为default,在集群中应该保持唯一,可以使用 hostname
--data-dir:服务运行数据保存的路径,默认为 ${name}.etcd
--snapshot-count:指定有多少事务(transaction)被提交时,触发截取快照保存到磁盘
--heartbeat-interval:leader 多久发送一次心跳到 followers。默认值是 100ms
--eletion-timeout:重新投票的超时时间,如果 follow 在该时间间隔没有收到心跳包,会触发重新投票,默认为 1000 ms
--listen-peer-urls:和同伴通信的地址,比如 http://ip:2380,如果有多个,使用逗号分隔。需要所有节点都能够访问,所以不要使用 localhost!
--listen-client-urls:对外提供服务的地址:比如 http://ip:2379,http://127.0.0.1:2379,客户端会连接到这里和 etcd 交互
--advertise-client-urls:对外公告的该节点客户端监听地址,这个值会告诉集群中其他节点
--initial-advertise-peer-urls:该节点同伴监听地址,这个值会告诉集群中其他节点
--initial-cluster:集群中所有节点的信息,格式为 node1=http://ip1:2380,node2=http://ip2:2380,…。注意:这里的 node1 是节点的 --name 指定的名字;后面的 ip1:2380 是 --initial-advertise-peer-urls 指定的值
--initial-cluster-state:新建集群的时候,这个值为new;假如已经存在的集群,这个值为 existing
--initial-cluster-token:创建集群的token,这个值每个集群保持唯一。这样的话,如果你要重新创建集群,即使配置和之前一样,也会再次生成新的集群和节点 uuid;否则会导致多个集群之间的冲突,造成未知的错误

所有以--init开头的配置都是在bootstrap集群的时候才会用到,后续节点的重启会被忽略

查看版本

etcd --version

etcd Version: 3.1.20
Git SHA: 992dbd4d1
Go Version: go1.8.7
Go OS/Arch: linux/amd64

key操作

查看key列表

etcdctl ls

写入一个key

etcdctl set foo bar
etcdctl set /coreos.com/network/config '{"Network": "172.7.0.0/16", "Backend": {"Type": "host-gw"}}'

更新key

当键存在时,更新值内容

etcdctl update /testdir/testkey "Hello"

读取key

etcdctl get foo
etcdctl get /coreos.com/network/config

删除key

etcdctl rm foo

节点操作

集群健康检查

etcdctl cluster-health

member 988139385f78284 is healthy: got healthy result from http://127.0.0.1:2379
member 5a0ef2a004fc4349 is healthy: got healthy result from http://127.0.0.1:2379
member f4a0cb0a765574a8 is healthy: got healthy result from http://127.0.0.1:2379
cluster is healthy
kubectl get cs

NAME                 STATUS      MESSAGE                                                                                 ERROR
scheduler            Healthy     ok                                                                                      
controller-manager   Healthy     ok                                                                                      
etcd-0               Healthy     {"health": "true"}                                                                      
etcd-1               Healthy     {"health": "true"}                                                                      
etcd-2               Unhealthy   Get https://10.4.7.22:2379/health: dial tcp 10.4.7.22:2379: connect: no route to host

列出节点

etcdctl member list
988139385f78284: name=etcd-server-7-22 peerURLs=https://10.4.7.22:2380 clientURLs=http://127.0.0.1:2379,https://10.4.7.22:2379 isLeader=false
5a0ef2a004fc4349: name=etcd-server-7-21 peerURLs=https://10.4.7.21:2380 clientURLs=http://127.0.0.1:2379,https://10.4.7.21:2379 isLeader=false
f4a0cb0a765574a8: name=etcd-server-7-12 peerURLs=https://10.4.7.12:2380 clientURLs=http://127.0.0.1:2379,https://10.4.7.12:2379 isLeader=true

增加一个节点

新加的节点取名为 infra3, peerURLs 是 https://10.0.1.13:2380

etcdctl member add infra3 https://10.0.1.13:2380

删除一个节点

etcdctl member remove a8266ecf031671f3

备份

etcdctl backup --data-dir /data/etcd/etcd-server --backup-dir /root/etcd7-21

恢复

etcd --data-dir=/data/etcd/etcd-server --force-new-cluster &

数据同步

curl http://127.0.0.1:2379/v2/members/1c4358be138c6d94 -XPUT \
-H "Content-Type:application/json" -d '{"peerURLs":["http://127.0.0.1:2379"]}'
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

wuxingge

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值