2024年11月

ETCD数据目录

ETCD_DATA_DIR="/var/lib/etcd/data"

备份ETCD数据

1)使用cp命令进行备份

cp -R /var/lib/etcd/ /opt/backup/etcd/

2)创建ETCD快照备份

etcdctl snapshot save /opt/snapshot.db

恢复etcd快照文件

1)停止etcd服务

systemctl stop etcd

2)恢复数据

实例1恢复

etcdctl snapshot restore /opt/snapshot.db \
--name etcd1 \
--initial-cluster etcd1=http://etcd1:2380,etcd2=http://etcd2:2380,etcd3=http://etcd3:2380 \
--initial-cluster-token mro \
--initial-advertise-peer-urls http://etcd1:2380 \
--data-dir /var/lib/etcd/data

实例2恢复

etcdctl snapshot restore /opt/snapshot.db \
--name etcd2 \
--initial-cluster etcd1=http://etcd1:2380,etcd2=http://etcd2:2380,etcd3=http://etcd3:2380 \
--initial-cluster-token mro \
--initial-advertise-peer-urls http://etcd2:2380 \
--data-dir /var/lib/etcd/data

实例3恢复

etcdctl snapshot restore /opt/snapshot.db \
--name etcd3 \
--initial-cluster etcd1=http://etcd1:2380,etcd2=http://etcd2:2380,etcd3=http://etcd3:2380 \
--initial-cluster-token mro \
--initial-advertise-peer-urls http://etcd3:2380 \
--data-dir /var/lib/etcd/data

3)启动服务

systemctl daemon-reload
systemctl start etcd

4)查看集群

etcdctl --endpoints="http://etcd1:2379,http://etcd2:2379,http://etcd3:2379" endpoint status --write-out=table