etcd备份和恢复

1. 初始化集群

$ etcd --name infra0 --initial-advertise-peer-urls http://192.168.26.13:2380
--listen-peer-urls http://192.168.26.13:2380
--listen-client-urls http://192.168.26.13:2379,http://127.0.0.1:2379
--advertise-client-urls http://192.168.26.13:2379
--initial-cluster-token etcd-cluster-1
--initial-cluster infra0=http://192.168.26.13:2380,infra1=http://192.168.26.162:2380,infra2=http://192.168.22.176:2380
--initial-cluster-state new
$ etcd --name infra1 --initial-advertise-peer-urls http://192.168.26.162:2380
--listen-peer-urls http://192.168.26.162:2380
--listen-client-urls http://192.168.26.162:2379,http://127.0.0.1:2379
--advertise-client-urls http://192.168.26.162:2379
--initial-cluster-token etcd-cluster-1
--initial-cluster infra0=http://192.168.26.13:2380,infra1=http://192.168.26.162:2380,infra2=http://192.168.22.176:2380
--initial-cluster-state new
$ etcd --name infra2 --initial-advertise-peer-urls http://192.168.22.176:2380
--listen-peer-urls http://192.168.22.176:2380
--listen-client-urls http://192.168.22.176:2379,http://127.0.0.1:2379
--advertise-client-urls http://192.168.22.176:2379
--initial-cluster-token etcd-cluster-1
--initial-cluster infra0=http://192.168.26.13:2380,infra1=http://192.168.26.162:2380,infra2=http://192.168.22.176:2380
--initial-cluster-state new
--endpoints=http://192.168.26.13:2380,http://192.168.26.162:2380,http://192.168.22.176:2380

2. 集群备份

任一节点
etcdctl snapshot save backup.db

3. 集群恢复

$ etcdctl snapshot restore backup.db
--name m1
--initial-cluster m1=http://192.168.26.13:2380,m2=http://192.168.26.162:2380,m3=http://192.168.22.176:2380
--initial-cluster-token etcd-cluster-1
--initial-advertise-peer-urls http://192.168.26.13:2380
$ etcdctl snapshot restore backup.db
--name m2
--initial-cluster m1=http://192.168.26.13:2380,m2=http://192.168.26.162:2380,m3=http://192.168.22.176:2380
--initial-cluster-token etcd-cluster-1
--initial-advertise-peer-urls http://192.168.26.162:2380
$ etcdctl snapshot restore backup.db
--name m3
--initial-cluster m1=http://192.168.26.13:2380,m2=http://192.168.26.162:2380,m3=http://192.168.22.176:2380
--initial-cluster-token etcd-cluster-1
--initial-advertise-peer-urls http://192.168.22.176:2380

4. 重新启动

$ nohup etcd
--name m1
--listen-client-urls http://192.168.26.13:2379,http://127.0.0.1:2379
--advertise-client-urls http://192.168.26.13:2379
--listen-peer-urls http://192.168.26.13:2380 &
$ nohup etcd
--name m2
--listen-client-urls http://192.168.26.162:2379,http://127.0.0.1:2379
--advertise-client-urls http://192.168.26.162:2379
--listen-peer-urls http://192.168.26.162:2380 &
$ nohup etcd
--name m3
--listen-client-urls http://192.168.22.176:2379,http://127.0.0.1:2379
--advertise-client-urls http://192.168.22.176:2379
--listen-peer-urls http://192.168.22.176:2380 &


实战操作
恢复
etcdctl snapshot restore backup.db \
--name ov-qabosslwetcd-01 \
--initial-cluster ov-qabosslwetcd-01=http://192.168.17.29:2380,ov-qabosslwetcd-02=http://192.168.17.199:2380,ov-qabosslwetcd-03=http://192.168.17.146:2380 \
--initial-cluster-token zlw-etcd-test \
--initial-advertise-peer-urls http://192.168.17.29:2380 \
--data-dir /data/etcd/data
重启
nohup etcd --config-file=/data/etcd/etcd.conf &


配置样例
name: ov-qacommonapisix-01
listen-client-urls: http://192.168.64.99:2379,http://127.0.0.1:2379
advertise-client-urls: http://192.168.64.99:2379,http://127.0.0.1:2379
listen-peer-urls: http://192.168.64.99:2380
initial-advertise-peer-urls: http://192.168.64.99:2380
initial-cluster: ov-qacommonapisix-01=http://192.168.64.99:2380,ov-qacommonapisix-02=http://192.168.64.39:2380,ov-qacommonapisix-03=http://192.168.64.220:2380
initial-cluster-token: qaops-gateway-etcd
initial-cluster-state: new
data-dir: /data/etcd/data
enable-grpc-gateway: true
quota-backend-bytes: 8589934592
auto-compaction-mode: periodic
auto-compaction-retention: "1"
heartbeat-interval: 1000
election-timeout: 5000
max-request-bytes: 10485760
logger: zap

posted on 2023-10-08 14:35  流年似水zlw  阅读(89)  评论(0编辑  收藏  举报

导航