5.1环境说明
主机 |
IP地址 |
备注 |
NFS+Redis |
192.168.1.16 |
sersync实时同步文件到备份主机 |
Backup |
192.168.1.17 |
rsync接收备份及xtraback备份 |
5.2 配置NFS文件实时同步备份
5.2.1 配置rsync守护进程
执行主机Backup
创建rsync进程用户
useradd -M -s /sbin/nologin
创建用户认证文件并授权,内容格式为“用户名:密码”
echo "wordpress:123456" > /etc/rsync.password chmod 600 /etc/rsync.password
编缉rsync配置文件,修改进程用户,添加同步模块、同步用户及认证文件
cat > /tmp/rsyncd.conf << EOF uid = rsync gid = rsync port = 873 fake super = yes use chroot = no max connections = 200 timeout = 600 ignore errors read only = false list = false auth users = wordpress secrets file = /etc/rsync.password log file = /var/log/rsyncd.log [wordpress] path = /data/wordpress EOF
启动rsync守护进程服务
systemctl enable rsyncd && systemctl start rsyncd
5.2.2 配置NFS文件实时同步
执行主机NFS+Redis
下载sersync
wget https://raw.githubusercontent.com/wsgzao/sersync/master/sersync2.5.4_64bit_binary_stable_final.tar.gz
解压
tar zxf sersync2.5.4_64bit_binary_stable_final.tar.gz -C /usr/local
重命名
mv /usr/local/{GNU-Linux-x86,sersync}
添加到环境变量
echo "/usr/local/sersync/" > /etc/profile.d/sersync.sh source /etc/profile
创建同步用户的密码文件
echo "123456" > /etc/rsync.pas chmod 600 /etc/rsync.pas
编缉sersync配置文件,修改需监控的目录、同步用户及密码文件
vim /usr/local/sersync/confxml.xml …… <localpath watch="/data/wordpress"> <remote ip="192.168.1.17" name="wordpress"/> </localpath> <rsync> <commonParams params="-avz"/> <auth start="true" users="wordpress" passwordfile="/etc/rsync.pas"/> …… </rsync> ……
启动
sersync2 -dro /usr/local/sersync/confxml.xml
5.3 配置数据库定时备份
使用xtrabackup定时备份数据库,执行主机Backup
安装mysql环境
略(详见 1.2.1 Msql安装章节)
下载安装xtrabackup工具
wget https://downloads.percona.com/downloads/Percona-XtraBackup-2.4/Percona-XtraBackup-2.4.27/binary/redhat/7/x86_64/percona-xtrabackup-24-2.4.27-1.el7.x86_64.rpm yum localinstall percona-xtrabackup-24-2.4.27-1.el7.x86_64.rpm
配置邮箱,根据实际修改以下信息
vim /etc/mail.rc …… set [email protected] set smtp=smtp.exmail.qq.com set [email protected] set smtp-auth-password=xxxxxxxxxxxx set smtp-auth=login ……
编写备份脚本
mkdir /etc/scripts vim /etc/scripts/dbbackup.sh #!/bin/bash Host="192.168.1.15" User="root" Pwd="123456" Pth="/data/mysql/full_$(date +%F)" /usr/bin/innobackupex --host=$Host --user=$User --password=$Pwd $Pth 2>/var/log/dbbackup_error.log if [ $? -eq 0 ];then mail -s "数据库备份成功!" [email protected] < echo "备份成功" else mail -s "数据库备份失败!" [email protected] < echo "备份失败" fi
添加到定时作业
crontab -e 0 23 * * * /bin/bash /etc/scripts/dbbackup.sh
标签:rsync,sersync,备份,etc,xtrabackup,com From: https://www.cnblogs.com/isxiefeng/p/17264984.html