etcd3集群数据备份与恢复

Posted sxlong_work

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了etcd3集群数据备份与恢复相关的知识,希望对你有一定的参考价值。


ETCD3数据备份与恢复


1.备份数据
备份etcd集群任意一个节点的数据就行

export ETCD_ENDPOINTS="https://192.168.0.20:2379,https://192.168.0.21:2379,https://192.168.0.22:2379"
etcdctl --endpoints=${ETCD_ENDPOINTS} snapshot save "/home/snapshot.db"

2.恢复数据
将/home/snapshot.db拷贝到其他etcd集群节点同一目录,之后在各个节点分别执行以下命令,--data-dir是新的数据目录,原数据目录是/data/apps/etcd/data/default.etcd,各个参数配置可查看原配置文件/data/apps/etcd/etc/etcd.conf
节点192.168.0.20执行

export ETCDCTL_API=3
etcdctl snapshot restore /home/snapshot.db --data-dir="/data/apps/etcd/data/etcd.restore" --name etcd-01 --initial-cluster "etcd-01=https://192.168.0.20:2380,etcd-02=https://192.168.0.21:2380,etcd-03=https://192.168.0.22:2380" --initial-cluster-token etcd-cluster --initial-advertise-peer-urls "https://192.168.0.20:2380"

 

节点192.168.0.21执行

export ETCDCTL_API=3
etcdctl snapshot restore /home/snapshot.db --data-dir="/data/apps/etcd/data/etcd.restore" --name etcd-02 --initial-cluster "etcd-01=https://192.168.0.20:2380,etcd-02=https://192.168.0.21:2380,etcd-03=https://192.168.0.22:2380" --initial-cluster-token etcd-cluster --initial-advertise-peer-urls "https://192.168.0.21:2380"

节点192.168.0.22执行

export ETCDCTL_API=3
etcdctl snapshot restore /home/snapshot.db --data-dir="/data/apps/etcd/data/etcd.restore" --name etcd-03 --initial-cluster "etcd-01=https://192.168.0.20:2380,etcd-02=https://192.168.0.21:2380,etcd-03=https://192.168.0.22:2380" --initial-cluster-token etcd-cluster --initial-advertise-peer-urls "https://192.168.0.22:2380"

 

3.停止各个节点的etcd服务

systemctl stop etcd

4.使用新的数据目录启动各个节点etcd
需要修改/data/apps/etcd/etc/etcd.conf配置文件中--data-dir对应的新的数据目录为/data/apps/etcd/data/etcd.restore

#[Member]
ETCD_NAME="etcd-01"
#ETCD_DATA_DIR="/data/apps/etcd/data/default.etcd"
ETCD_DATA_DIR="/data/apps/etcd/data/etcd.restore"
ETCD_LISTEN_PEER_URLS="https://192.168.0.20:2380"
ETCD_LISTEN_CLIENT_URLS="https://127.0.0.1:2379,https://192.168.0.20:2379"
#
#[Clustering]
ETCD_INITIAL_ADVERTISE_PEER_URLS="https://192.168.0.20:2380"
ETCD_ADVERTISE_CLIENT_URLS="https://127.0.0.1:2379,https://192.168.0.20:2379"
ETCD_INITIAL_CLUSTER="etcd-01=https://192.168.0.20:2380,etcd-02=https://192.168.0.21:2380,etcd-03=https://192.168.0.22:2380"
ETCD_INITIAL_CLUSTER_TOKEN="etcd-cluster"
ETCD_INITIAL_CLUSTER_STATE="new"

#[Security]
ETCD_CERT_FILE="/data/apps/etcd/ssl/etcd.pem"
ETCD_KEY_FILE="/data/apps/etcd/ssl/etcd-key.pem"
ETCD_TRUSTED_CA_FILE="/data/apps/etcd/ssl/etcd-ca.pem"
ETCD_PEER_CERT_FILE="/data/apps/etcd/ssl/etcd.pem"
ETCD_PEER_KEY_FILE="/data/apps/etcd/ssl/etcd-key.pem"
ETCD_PEER_TRUSTED_CA_FILE="/data/apps/etcd/ssl/etcd-ca.pem"
#
[Logging]
ETCD_DEBUG="false"
ETCD_LOG_OUTPUT="default"

之后启动etcd即可

systemctl start etcd

 

以上是关于etcd3集群数据备份与恢复的主要内容,如果未能解决你的问题,请参考以下文章

(一) etcd3-server-API

EMC Isilon(OneFS)存储误删除数据恢复方法数据恢复实例

Oracle 数据库 - 使用UEStudio修改dmp文件版本号,解决imp命令恢复的数据库与dmp本地文件版本号不匹配导致的导入失败问题,“ORACLE error 12547”问题处理(代码片段

Rancher RKE 集群备份与恢复

大话OracleRAC集群、高可用性、备份与恢复的前言

简单实用kubernetes的etcd备份与恢复实现恢复集群配置