###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= 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= snapshot s**e /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="$" --cert="$" --key="$" \
--endpoints=$ \
snapshot s**e /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=" \
--initial-cluster-token etcd-cluster \
--initial-advertise-peer-urls \
--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=" \
--initial-cluster-token etcd-cluster \
--initial-advertise-peer-urls \
--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=" \
--initial-cluster-token etcd-cluster \
--initial-advertise-peer-urls \
--data-dir=/var/lib/etcd/default.etcd
啟動etcd集群
systemctl start etcd
檢視集群狀態
systemctl status etcd
啟動kube-apiserver
systemctl start kube-apiserver
systemctl status kube-apiserver
etcd與mysql etcd資料庫備份與還原
1.1 手動備份資料 etcdctl backup data dir var lib etcd default.etcd backup dir 備份目錄 1.2 指令碼備份資料 使用etcd自帶命令etcdctl進行etc備份,指令碼如下 bin bash date time date y m d ...
閒談etcd(三)etcd的使用
type client structimport fmt go.etcd.io etcd clientv3 time 連線 func main dialtimeout 5 time.second,建立連線 if client,err clientv3.new config err nil fmt.p...
etcd3 5 0版本集群部署及備份
etcd版本 etcd v3.5.0 集群ip etcd 1 192.168.44.218 etcd 2 192.168.6.166 etcd 3 192.168.44.210 wget tar zxvf etcd v3.5.0 linux amd64.tar.gz c beta etcd cd b...