etcd数据备份
###etcd备份数据 cp etcdctl /usr/bin/ #查看etcd状态 ETCDCTL_API=3 etcdctl --cacert=/opt/etcd/ssl/ca.pem --cert=/opt/etcd/ssl/server.pem --key=/opt/etcd/ssl/server-key.pem --endpoints=https://172.22.154.215:2379,https://172.22.154.216:2379,https://172.22.154.217:2379 endpoint health 备份数据 ETCDCTL_API=3 etcdctl --cacert=/opt/etcd/ssl/ca.pem --cert=/opt/etcd/ssl/server.pem --key=/opt/etcd/ssl/server-key.pem --endpoints=https://172.22.154.215:2379 snapshot save /data/etcd_backup_dir/etcd-snapshot-`date +%Y%m%d`.db 备份脚本 ####为避免集群服务器崩溃建议将备份数据在其它服务器上也存储一份! #!/usr/bin/env bash date; CACERT="/opt/etcd/ssl/ca.pem" CERT="/opt/etcd/ssl/server.pem" EKY="/opt/etcd/ssl/server-key.pem" ENDPOINTS="172.22.154.215:2379" ETCDCTL_API=3 etcdctl \ --cacert="${CACERT}" --cert="${CERT}" --key="${EKY}" \ --endpoints=${ENDPOINTS} \ snapshot save /data/etcd_backup_dir/etcd-snapshot-`date +%Y%m%d`.db # 备份保留30天 find /data/etcd_backup_dir/ -name *.db -mtime +30 -exec rm -f {} \; #恢复验证 停止kube-apiserver 停止etcd集群 移走etcd数据 cd /var/lib/etcd/ mv default.etcd default.etcd.bak 拷贝备份数据 scp etcd-snapshot-20220328.db node216:/data/etcd_backup_dir/ scp etcd-snapshot-20220328.db node217:/data/etcd_backup_dir/ 恢复数据 ETCDCTL_API=3 etcdctl snapshot restore /data/etcd_backup_dir/etcd-snapshot-20220328.db \ --name etcd-1 \ --initial-cluster "etcd-1=https://172.22.154.215:2380,etcd-2=https://172.22.154.216:2380,etcd-3=https://172.22.154.217:2380" \ --initial-cluster-token etcd-cluster \ --initial-advertise-peer-urls https://172.22.154.215:2380 \ --data-dir=/var/lib/etcd/default.etcd ETCDCTL_API=3 etcdctl snapshot restore /data/etcd_backup_dir/etcd-snapshot-20220328.db \ --name etcd-2 \ --initial-cluster "etcd-1=https://172.22.154.215:2380,etcd-2=https://172.22.154.216:2380,etcd-3=https://172.22.154.217:2380" \ --initial-cluster-token etcd-cluster \ --initial-advertise-peer-urls https://172.22.154.216:2380 \ --data-dir=/var/lib/etcd/default.etcd ETCDCTL_API=3 etcdctl snapshot restore /data/etcd_backup_dir/etcd-snapshot-20220328.db \ --name etcd-3 \ --initial-cluster "etcd-1=https://172.22.154.215:2380,etcd-2=https://172.22.154.216:2380,etcd-3=https://172.22.154.217:2380" \ --initial-cluster-token etcd-cluster \ --initial-advertise-peer-urls https://172.22.154.217:2380 \ --data-dir=/var/lib/etcd/default.etcd 启动etcd集群 systemctl start etcd 查看集群状态 systemctl status etcd 启动kube-apiserver systemctl start kube-apiserver systemctl status kube-apiserver