From 669334062e5886a6c0d7615231052648f29084ea Mon Sep 17 00:00:00 2001 From: gjmzj Date: Sun, 16 Apr 2023 09:35:53 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20etcd=E9=9B=86=E7=BE=A4=E6=81=A2=E5=A4=8D?= =?UTF-8?q?=E9=80=89=E4=B8=BB=E9=97=AE=E9=A2=98(#1193=20=E5=BC=95=E5=85=A5?= =?UTF-8?q?)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- docs/setup/02-install_etcd.md | 8 ++++++++ playbooks/94.backup.yml | 2 -- roles/cluster-restore/tasks/main.yml | 29 +++++++++++++++++----------- 3 files changed, 26 insertions(+), 13 deletions(-) diff --git a/docs/setup/02-install_etcd.md b/docs/setup/02-install_etcd.md index 2fb9257..1b43c25 100644 --- a/docs/setup/02-install_etcd.md +++ b/docs/setup/02-install_etcd.md @@ -102,6 +102,14 @@ for ip in ${NODE_IPS}; do --cert=/etc/kubernetes/ssl/etcd.pem \ --key=/etc/kubernetes/ssl/etcd-key.pem \ endpoint health; done + +for ip in ${NODE_IPS}; do + ETCDCTL_API=3 etcdctl \ + --endpoints=https://${ip}:2379 \ + --cacert=/etc/kubernetes/ssl/ca.pem \ + --cert=/etc/kubernetes/ssl/etcd.pem \ + --key=/etc/kubernetes/ssl/etcd-key.pem \ + --write-out=table endpoint status; done ``` 预期结果: diff --git a/playbooks/94.backup.yml b/playbooks/94.backup.yml index 10f7020..d63ffbf 100644 --- a/playbooks/94.backup.yml +++ b/playbooks/94.backup.yml @@ -43,8 +43,6 @@ --cert={{ cluster_dir }}/ssl/etcd.pem \ --key={{ cluster_dir }}/ssl/etcd-key.pem \ snapshot save snapshot_{{ timestamp.stdout }}.db" - args: - warn: false - name: update the latest backup shell: 'cd {{ cluster_dir }}/backup/ && /bin/cp -f snapshot_{{ timestamp.stdout }}.db snapshot.db' diff --git a/roles/cluster-restore/tasks/main.yml b/roles/cluster-restore/tasks/main.yml index 07aa4d8..9e50a55 100644 --- a/roles/cluster-restore/tasks/main.yml +++ b/roles/cluster-restore/tasks/main.yml @@ -4,20 +4,27 @@ - name: 清除etcd 数据目录 file: name={{ ETCD_DATA_DIR }}/member state=absent -- name: 清除 etcd 备份目录 - file: name={{ cluster_dir }}/backup/etcd-restore state=absent - delegate_to: 127.0.0.1 - run_once: true +- name: 清理上次备份恢复数据 + file: name=/etcd_backup state=absent + +- name: 生成备份目录 + file: name=/etcd_backup state=directory + +- name: 准备指定的备份etcd 数据 + copy: + src: "{{ cluster_dir }}/backup/{{ db_to_restore }}" + dest: "/etcd_backup/snapshot.db" - name: etcd 数据恢复 - shell: "cd {{ cluster_dir }}/backup && \ - ETCDCTL_API=3 {{ base_dir }}/bin/etcdctl snapshot restore snapshot.db \ - --data-dir={{ cluster_dir }}/backup/etcd-restore" - delegate_to: 127.0.0.1 - run_once: true + shell: "cd /etcd_backup && \ + ETCDCTL_API=3 {{ bin_dir }}/etcdctl snapshot restore snapshot.db \ + --name etcd-{{ inventory_hostname }} \ + --initial-cluster {{ ETCD_NODES }} \ + --initial-cluster-token etcd-cluster-0 \ + --initial-advertise-peer-urls https://{{ inventory_hostname }}:2380" -- name: 分发恢复文件到 etcd 各个节点 - copy: src={{ cluster_dir }}/backup/etcd-restore/member dest={{ ETCD_DATA_DIR }} +- name: 恢复数据至etcd 数据目录 + shell: "cp -rf /etcd_backup/etcd-{{ inventory_hostname }}.etcd/member {{ ETCD_DATA_DIR }}/" - name: 重启etcd 服务 service: name=etcd state=restarted