ETCD 常用操作,及数据备份和恢复
ETCD 常用操作,及数据备份和恢复。
·
ETCD常用命令
1. ETCD健康度检测
单节点方式
./etcdctl --endpoints=localhost:2379 --user=root:'****' endpoint health
集群方式
./etcdctl endpoint health --user=root:'****' --cluster
2. 查询ETCD状态
单节点
./etcdctl endpoint status -w table --endpoints="127.0.0.1:2379"
集群方式
ETCDCTL_API=3 ./etcdctl endpoint status --cluster -w table
3.ETCD数据备份
注:etcd-snapshot.db 为备份文件名
./etcdctl --endpoints=localhost:2379 --user=root:’****’ snapshot save etcd-snapshot.db
4.ETCD数据恢复
4.1 准备工作:上传备份文件 **.db 至需要恢复的etcd机器
scp ***.db ip:/
4.2 停止单机或者集群内所有etcd进程
ps -ef |grep etcd
sudo kill -9 pid
4.3单节点恢复方式: etcd-snapshot.db为备份文件位置 m1.etcd 数据恢复所保存的路径
./etcdutl snapshot restore etcd-snapshot.db --data-dir m1.etcd
4.4 集群恢复方式: 注:***.db为备份文件名称; etcd1ip、etcd2ip、etcd3ip 分别对应三台机器的ip;
–data-dir=infra01.etcd、infra02.etcd、infra03.etcd 分别为恢复后数据保存的目录
etcd1机器
ETCDCTL_API=3 ./etcdctl snapshot restore ***.db --name infra0 --initial-cluster "infra0=http://etcd1ip:2380,infra1=http://etcd2ip:2380,infra2=http://etcd3ip:2380" --initial-cluster-token etcd-cluster-1 --initial-advertise-peer-urls http://本机ip:2380 --data-dir=infra01.etcd
etcd2机器
ETCDCTL_API=3 ./etcdctl snapshot restore ***.db --name infra1 --initial-cluster "infra0=http://etcd1ip:2380,infra1=http://etcd2ip:2380,infra2=http://etcd3ip:2380" --initial-cluster-token etcd-cluster-1 --initial-advertise-peer-urls http://本机ip:2380 --data-dir=infra02.etcd
etcd3机器
ETCDCTL_API=3 ./etcdctl snapshot restore ***.db --name infra2 --initial-cluster "infra0=http://etcd1ip:2380,infra1=http://etcd2ip:2380,infra2=http://etcd3ip:2380" --initial-cluster-token etcd-cluster-1 --initial-advertise-peer-urls http://本机ip:2380 --data-dir=infra03.etcd
4.5 数据恢复成功后,集群方式启动三台etcd
4.ETCD数据恢复后可能密码也会变更至恢复节点的密码,需要手动更改
更改密码原因为:apisixdasboard及apisix连接etcd密码在配置文件中,如不更改,其他服务连接不上etcd
./etcdctl user passwd root --user=root:****

DAMO开发者矩阵,由阿里巴巴达摩院和中国互联网协会联合发起,致力于探讨最前沿的技术趋势与应用成果,搭建高质量的交流与分享平台,推动技术创新与产业应用链接,围绕“人工智能与新型计算”构建开放共享的开发者生态。
更多推荐
所有评论(0)