大佬教程收集整理的这篇文章主要介绍了Rsync-远程同步(下)-企业案例,大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
已知3台服务器主机名分别为web01、BACkup 、nfs主机信息见下表:
角色 外网IP(NAT) 内网IP(LAN) 主机名 WEB eth0:10.0.0.7 eth1:172.16.1.7 web01 NFS eth0:10.0.0.31 eth1:172.16.1.31 nfs Rsync eth0:10.0.0.41 eth1:172.16.1.41 BACkup 客户端: web nfs 服务端: BACkup
==Client客户端需求:*
1.客户端提前准备存放的备份的目录,目录规则如下:/BACkup/nfs_172.16.1.31_2019-09-06
2.客户端在本地打包备份(系统配置文件、应用配置等)拷贝至/BACkup/nfs_172.16.1.31_2019-09-06
3.客户端最后将备份的数据进行推送至备份服务器
4.客户端服务器本地保留最近7天的数据,避免浪费磁盘空间
5.客户端每天凌晨1点定时执行该脚本
==Server服务端需求:*
1.服务端部署rsync,用于接收客户端推送过来的备份数据
2.服务端需要每天校验客户端推送过来的数据是否完整
3.服务端需要每天校验的结果通知给管理员
4.服务端仅保留6个月的备份数据,其余的全部删除
5.服务端每天定时校验结果
#1.安装 [[email protected] ~]# yum install rsync -y #2.配置 [[email protected] ~]# vim /etc/rsyncd.conf 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 = rsync_BACkup secrets file = /etc/rsync.passwd log file = /var/log/rsyncd.log ##################################### [BACkup] comment = welcome to oldboyedu BACkup path = /BACkup #3.根据配置创建一些环境 3.1创建rsync用户 [[email protected] ~]# groupadd rsync [[email protected] ~]# useradd rsync -M -s /sbin/nologin -g rsync [[email protected] ~]# id rsync uid=1000(rsynC) gid=1000(rsynC) groups=1000(rsynC) 3.2创建虚拟用户和密码 [[email protected] ~]# echo "rsync_BACkup:123456" > /etc/rsync.passwd [[email protected] ~]# chmod 600 /etc/rsync.passwd 3.3创建BACkup目录 [[email protected] ~]# mkdir /BACkup [[email protected] ~]# chown -R rsync.rsync /BACkup/ #4.启动服务 [[email protected] ~]# systemctl start rsyncd [[email protected] ~]# systemctl enable rsyncd #5.检查 [[email protected] ~]# netstat -lntup |grep rsync tcp 0 0 0.0.0.0:873 0.0.0.0:* LISTEN 1594/rsync tcP6 0 0 :::873 :::* LISTEN 1594/rsync
Client端操作:
思路:
1.你需要备份什么?
/etc/fstab /etc/hosts /etc/passwd /var/spool/cron/
2.你要备份到哪里?
/BACkup/nfs_172.16.1.31_2018-09-02
IP: ifcon@L_616_21@ eth1 | awk ‘NR==2 {print $2}‘
host: hostname
date: date +%F
3.你要推送到哪里?
172.16.1.41
==注意==:所有服务器的备份目录必须都为/BACkup
快递: 散货-------->打包--->标记------->装车-------------->运输------------->仓库 验货-------->评价 系统: 备份的文件-->打包--->校验值----->备份至本地目录---->网络-------->推送至备份服务器 管理员校验-->通知--->邮件
#创建存放脚本的位置: [[email protected] ~]# mkdir -p /server/scripts/ #根据要求遍写脚本: [[email protected] ~]# vim /server/scripts/push_data_server.sh #!/usr/bin/bash PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/root/bin Path=/BACkup Host=$(hostName) Addr=$(ifcon@L_616_21@ eth1 |awk 'NR==2 {print $2}') Date=$(date +%F) Dest=${Host}_${Addr}_${DatE} #1.创建存放备份的目录 [ -d $Path/$Dest ] || mkdir -p $Path/$Dest #2.打包本地文件至备份目录 cd / && [ -f $Path/$Dest/sys.tar.gz ] || tar czf $Path/$Dest/sys.tar.gz etc/fstab etc/hosts etc/passwd && [ -f $Path/$Dest/other.tar.gz ] || tar czf $Path/$Dest/other.tar.gz var/spool/cron/ && #3.增加标记 md5sum $Path/$Dest/*.tar.gz > $Path/$Dest/flag_${DatE} #4.将备份的数据推送至远程服务器 export RSYNC_password=123456 rsync -avz $Path/ [email protected]::BACkup #5.客户端服务器本地保留最近7天的数据 find $Path/ -type d -mtime +7 | xargs rm -rf ------------------------------------------------------------------------------------------------------ ##批量的模拟数据 [[email protected] ~]# for i in {1..30};do date -s "201909$i"; sh /scripts/clinet_push_data_server.sh ;
==Server端操作:==
------------------服务端配置邮件功能--------------------
1.安装 [[email protected] ~]# yum install mailx -y 2.配置 [[email protected] ~]# vim /etc/mail.rc //最后一行下边添加如下内容: set [email protected] //发件人QQ set smtp=smtps://smtp.qq.com:465 set [email protected] //发件人QQ set smtp-auth-password=xxxxxxxxxxx //QQ授权码 set smtp-auth=login set ssl-verify=ignore set nss-con@L_616_21@-dir=/etc/pki/nssdb/ 3.测试一下是否能发送成功 [[email protected] ~]# mail -s "Rsync BACkup" [email protected] < /etc/hosts 4.编写脚本 [[email protected] ~]# mkdir -p /server/scripts [[email protected] ~]# vim /server/scripts/check_data_notify.sh #!/usr/bin/bash PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/root/bin Path=/BACkup Date=$(date +%F) #1.校验客户端推送过来的数据 md5sum -c ${Path}/*_${DatE}/flag_${DatE} > ${Path}/result_${DatE} #2.将校验的结果通知给管理员 mail -s "Rsync BACkup ${DatE}" [email protected] < ${Path}/result_${DatE} #3.服务端保留最近180天的备份数据 find $Path/ -type d -mtime +180 | xargs rm -rf #定时任务: 客户端 [[email protected] ~]# crontab -l #客户端每天凌晨1点定时执行该脚本 */2 * * * * sh /server/scripts/push_data_server.sh &> /dev/null 服务端 [[email protected] ~]# crontab -l #定时校验备份的结果 */2 * * * * sh /server/scripts/check_data_notify.sh &> /dev/null 如何增加多台及上千台客户端服务器备份数据? [[email protected] ~]# rsync -avz [email protected]:/server / [[email protected] ~]# rsync -avz [email protected]:/server / [[email protected] ~]# rsync -avz [email protected]:/server / [[email protected] ~]# rsync -avz [email protected]:/server / [[email protected] ~]# rsync -avz [email protected]:/server /
......................................................
以上是大佬教程为你收集整理的Rsync-远程同步(下)-企业案例全部内容,希望文章能够帮你解决Rsync-远程同步(下)-企业案例所遇到的程序开发问题。
如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。
本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。