Skip to content

Commit 6693340

Browse files
committed
fix: etcd集群恢复选主问题(#1193 引入)
1 parent 608b0bc commit 6693340

File tree

3 files changed

+27
-14
lines changed

3 files changed

+27
-14
lines changed

docs/setup/02-install_etcd.md

+8
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,14 @@ for ip in ${NODE_IPS}; do
102102
--cert=/etc/kubernetes/ssl/etcd.pem \
103103
--key=/etc/kubernetes/ssl/etcd-key.pem \
104104
endpoint health; done
105+
106+
for ip in ${NODE_IPS}; do
107+
ETCDCTL_API=3 etcdctl \
108+
--endpoints=https://${ip}:2379 \
109+
--cacert=/etc/kubernetes/ssl/ca.pem \
110+
--cert=/etc/kubernetes/ssl/etcd.pem \
111+
--key=/etc/kubernetes/ssl/etcd-key.pem \
112+
--write-out=table endpoint status; done
105113
```
106114
预期结果:
107115

playbooks/94.backup.yml

-2
Original file line numberDiff line numberDiff line change
@@ -43,8 +43,6 @@
4343
--cert={{ cluster_dir }}/ssl/etcd.pem \
4444
--key={{ cluster_dir }}/ssl/etcd-key.pem \
4545
snapshot save snapshot_{{ timestamp.stdout }}.db"
46-
args:
47-
warn: false
4846

4947
- name: update the latest backup
5048
shell: 'cd {{ cluster_dir }}/backup/ && /bin/cp -f snapshot_{{ timestamp.stdout }}.db snapshot.db'

roles/cluster-restore/tasks/main.yml

+19-12
Original file line numberDiff line numberDiff line change
@@ -4,20 +4,27 @@
44
- name: 清除etcd 数据目录
55
file: name={{ ETCD_DATA_DIR }}/member state=absent
66

7-
- name: 清除 etcd 备份目录
8-
file: name={{ cluster_dir }}/backup/etcd-restore state=absent
9-
delegate_to: 127.0.0.1
10-
run_once: true
7+
- name: 清理上次备份恢复数据
8+
file: name=/etcd_backup state=absent
9+
10+
- name: 生成备份目录
11+
file: name=/etcd_backup state=directory
12+
13+
- name: 准备指定的备份etcd 数据
14+
copy:
15+
src: "{{ cluster_dir }}/backup/{{ db_to_restore }}"
16+
dest: "/etcd_backup/snapshot.db"
1117

1218
- name: etcd 数据恢复
13-
shell: "cd {{ cluster_dir }}/backup && \
14-
ETCDCTL_API=3 {{ base_dir }}/bin/etcdctl snapshot restore snapshot.db \
15-
--data-dir={{ cluster_dir }}/backup/etcd-restore"
16-
delegate_to: 127.0.0.1
17-
run_once: true
18-
19-
- name: 分发恢复文件到 etcd 各个节点
20-
copy: src={{ cluster_dir }}/backup/etcd-restore/member dest={{ ETCD_DATA_DIR }}
19+
shell: "cd /etcd_backup && \
20+
ETCDCTL_API=3 {{ bin_dir }}/etcdctl snapshot restore snapshot.db \
21+
--name etcd-{{ inventory_hostname }} \
22+
--initial-cluster {{ ETCD_NODES }} \
23+
--initial-cluster-token etcd-cluster-0 \
24+
--initial-advertise-peer-urls https://{{ inventory_hostname }}:2380"
25+
26+
- name: 恢复数据至etcd 数据目录
27+
shell: "cp -rf /etcd_backup/etcd-{{ inventory_hostname }}.etcd/member {{ ETCD_DATA_DIR }}/"
2128

2229
- name: 重启etcd 服务
2330
service: name=etcd state=restarted

0 commit comments

Comments
 (0)