ETCD数据迁移
背景:由于k8s集群数据迁移,集群的网关数据库Etcd也随之迁移,因此涉及到Etcd数据的导出导入
1、源库导出:
bash
etcdctl snapshot save snapshot-2026.db --endpoints=10.100.100.15:12379
# 数据库端口修改为自己的
2、当目标库为单机时:
bash
直接在目标库机器上执行:
etcdctl snapshot restore snapshot-2026.db --data-dir=/var/lib/etcd-new
然后使用这个新目录etcd-new作为Etcd的数据目录重启Etcd服务
3、当目标库为集群但是只有一节点时:
bash
etcdctl snapshot restore snapshot-2026.db \
--name etcd-1 \
--initial-cluster-token etcd-cluster \
--initial-advertise-peer-urls http://10.10.10.1:12380 \
--data-dir /var/lib/etcd-new
参数解释:
--initial-cluster-token 为整个 etcd 集群设置一个唯一标识令牌
--initial-advertise-peer-urls 告诉其他 etcd 节点如何访问本节点
4、当目标库为集群多节点时:
在节点1 (名为 node1) 上执行
bash
etcdctl snapshot restore ssnapshot-2026.db \
--name node1 \
--initial-cluster-token etcd-cluster \
--initial-advertise-peer-urls http://192.168.1.101:12380 \
--initial-cluster "node1=http://192.168.1.101:12380,node2=http://192.168.1.102:12380 \
--data-dir=/var/lib/etcd-new
在节点2 (名为 node2) 上执行
bash
etcdctl snapshot restore snapshot-2026.db \
--name node2 \
--initial-cluster-token etcd-cluster \
--initial-advertise-peer-urls http://192.168.1.102:2380 \
--initial-cluster "node1=http://192.168.1.101:12380,node2=http://192.168.1.102:12380 \
--data-dir=/var/lib/etcd-new
然后分别使用新的数据目录重启Etcd数据库