etcd 单节点部署备份与恢复
Posted lixinliang
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了etcd 单节点部署备份与恢复相关的知识,希望对你有一定的参考价值。
etcd 部署 wget https://github.com/etcd-io/etcd/releases/download/v3.3.13/etcd-v3.3.13-linux-amd64.tar.gz tar -zxvf etcd-v3.3.13-linux-amd64.tar.gz cd etcd-v3.3.13-linux-amd64 目录下有两个可执行文件etcd 和 etcdctl cp etcd /usr/bin/ cp etcdctl /usr/bin/ 添加以下内容: $ cat /usr/lib/systemd/system/etcd.service [Unit] Description=Etcd Server After=network.target [Service] Type=simple WorkingDirectory=/data/etcd EnvironmentFile=-/etc/etcd/etcd.conf ExecStart=/usr/bin/etcd [Install] WantedBy=multi-user.target mkdir -p /data/etcd mkdir -p /etc/etcd/ 添加以下内容: $ cat /etc/etcd/etcd.conf ETCD_NAME=default ETCD_DATA_DIR="/data/etcd/default.etcd/" ETCD_LISTEN_CLIENT_URLS="http://0.0.0.0:2379" ETCD_ADVERTISE_CLIENT_URLS="http://0.0.0.0:2379" systemctl start etcd.service
备份操作: [root@xy-test05 ~]# cat /opt/etcdbak.sh #!/bin/bash local_ip=`ip a | grep 172.24 | awk -F/ ‘{print $1}‘ | awk ‘{print $2}‘` date=$(date +%Y-%m-%d) backup_path="/data/dataetcd_back" mkdir -p /data/dataetcd_back cd $backup_path 备份如果出错的话执行以下操作: export ETCDCTL_API=3 etcdctl --endpoints localhost:2379 snapshot save $local_ip-snapshot-$date.db if [ $? -eq 0 ];then /usr/bin/rsync -av $local_ip-snapshot-$date.db 172.24.119.35::yunwei_etcd_backup/${local_ip}/$date rm -rf $local_ip-snapshot-$date.db fi
etcd 恢复操作: etcd 恢复之前配置文件: $ cat /etc/etcd/etcd.conf ETCD_NAME=default ETCD_DATA_DIR="/data/etcd/default.etcd/" ETCD_LISTEN_CLIENT_URLS="http://0.0.0.0:2379" ETCD_ADVERTISE_CLIENT_URLS="http://0.0.0.0:2379" 操作: export ETCDCTL_API=3 cd /data/etcd/ etcdctl snapshot restore /data/etcdnew/172.24.119.41-snapshot-2019-08-30.db --data-dir=./data/etcd/default.etcd 此时会在/data/etcd/ 下新建立 data目录,因此会改变存储路径,此时需要进行数据目录的修改 mv default.etcd default.etcd_bak mv /data/etcd/data/etcd/default.etcd /data/etcd/ rm -rf /data/etcd/data 保持配置文件不变: $ cat /etc/etcd/etcd.conf ETCD_NAME=default ETCD_DATA_DIR="/data/etcd/default.etcd/" ETCD_LISTEN_CLIENT_URLS="http://0.0.0.0:2379" ETCD_ADVERTISE_CLIENT_URLS="http://0.0.0.0:2379" $ systemctl restart etcd
以上是关于etcd 单节点部署备份与恢复的主要内容,如果未能解决你的问题,请参考以下文章