大佬教程收集整理的这篇文章主要介绍了Centos6.9 搭建rsync服务端与客户端 案例:全网备份项目,大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
rsync的企业工作场景说明
1)定时备份
1.1生产场景集群架构服务器备份方案项目
借助cron+rsync把所有客户服务器数据同步到备份服务器
2)实时复制
本地数据传输模式(local-only mode)
/oldboy/ 与/oldboy
/oldboy 表示oldboy目录及oldboy目录下面的内容
/oldboy/ 只表示oldboy目录下面的内容
通过远程sHell进行数据传输
[[email protected] ~]# scp -rP 22 /etc 172.16.1.31:/tmp #拷贝本机/etc目录到远程172.16.1.31的/tmp目录
[[email protected] ~]# rsync -avz /etc/sysconfig 172.16.1.31:/tmp #同步本机/etc/sysconfig目录到远程172.16.1.31的/tmp目录
全网备份项目
web01服务器
备份/var/www/html
生成web01-2018-01-01_1.tar.gz
推送当天的压缩包
删除7天前的压缩包
1.搭建rsync服务端与客户端
BACkup搭建rsync服务端
[[email protected] ~]# mkdir /BACkup
[[email protected] ~]# useradd -s /sbin/nologin -M rsync
[[email protected] ~]# chown -R rsync.rsync /BACkup
[[email protected] ~]# ls -ld /BACkup
drwxr-xr-x 2 rsync rsync 4096 Aug 1 06:45 /BACkup
[[email protected] ~]# echo ‘rsync_BACkup:123456‘ >/etc/rsync.password
[[email protected] ~]# cat /etc/rsync.password
[[email protected] ~]# chmod 600 /etc/rsync.password
[[email protected] ~]# ll /etc/rsync.password
-rw------- 1 root root 20 Jun 7 18:27 /etc/rsync.password
# vim /etc/rsyncd.conf
##rsyncd.conf start##
uid = rsync #指定rsync运行时候的用户
gid = rsync #指定rsync运行时候的用户
use chroot = no #安全相关
@H_290_17@max connections = 200 #最大的连接数
timeout = 300 #超时的时间
pid file = /var/run/rsyncd.pid #pid号码存放的文件
lock file = /var/run/rsync.lock #锁文件
log file = /var/log/rsyncd.log #rsync的日志
ignore errors #忽略错误
read only = false #是否只读
list = false
hosts allow = 172.16.1.0/24 #2选1
hosts deny = 0.0.0.0/32
auth users = rsync_BACkup #只用于验证的用户,看大门的用户
secrets file = /etc/rsync.password #存放密码的rsync_BACkup:123456
#rsync_config_______________end
[[email protected] ~]# ps -ef|grep rsync
root 1523 1 0 08:04 ? 00:00:00 rsync --daemon
root 1588 1547 0 08:14 pts/0 00:00:00 grep rsync
[[email protected] ~]# ss -lntup|grep rsync
tcp LISTEN 0 5 :::873 :::* users:(("rsync",1523,5))
tcp LISTEN 0 5 *:873 *:* users:(("rsync",3))
web01作为rsync客户端配置:
1.检查软件是否安装
[[email protected] ~]# rpm -qa rsync
rsync-3.0.6-12.el6.x86_64
[[email protected] ~]# echo ‘123456‘ > /etc/rsync.password
[[email protected] ~]# chmod 600 /etc/rsync.password
3.测试
[[email protected] ~]# rsync -avz /etc/hosts [email protected]::BACkup --password-file=/etc/rsync.password
2.书写客户端脚本
web01脚本:
#备份文件和配置
tar zchf /BACkup/web01-$(date +%F_%w).tar.gz /var/www/html /etc/rc.local /var/spool/cron/
#做md5sum
cd /BACkup
@H_290_17@md5sum web01-$(date +%F_%w).tar.gz>check.log
#推送备份数据
rsync -avz /BACkup/ [email protected]::BACkup --password-file=/etc/rsync.password
#删除七天以前
find /BACkup/ -type f -name "*.tar.gz" -mtime +7|xargs rm
3.写入web01定时任务
[[email protected] BACkup]# mkdir -p /server/scripts
[[email protected] BACkup]# vim /server/scripts/bak-web01.sh
#!/bin/bash
#desc:BACkup html && conf
date=$(date +%F_%w)
#备份文件和配置
tar zchf /BACkup/web01-${datE}.tar.gz /var/www/html /etc/rc.local /var/spool/cron/
#做md5sum
cd /BACkup
@H_290_17@md5sum web01-${datE}.tar.gz>check.log
#推送备份数据
rsync -avz /BACkup/ [email protected]::BACkup --password-file=/etc/rsync.password
#删除七天以前
find /BACkup/ -type f -name "*.tar.gz" -mtime +7|xargs rm
4.熟悉BACkup脚本
#执行脚本
[[email protected] BACkup]# sh /server/scripts/bak-web01.sh
5.写入定时任务
#crontab -e
#BACkup conf html hkping 2018-01-27
00 00 * * * /bin/sh /server/scripts/bak-web01.sh >/dev/null 2>&1
在BACkup上的要求:
保留每周六的压缩包
#BACkup上的脚本
#find /BACkup/ -type f -name "*.tar.gz" -mtime +180 ! -name "*_6.tar.gz"|xargs rm
#md5sum检查
cd /BACkup/ && md5sum -c check.log >/BACkup/result.log
if [ $? -eq 0 ];then
@H_290_17@mail -s "md5sum wrong" [email protected] </BACkup/result.log
fi
#需要打开postfix服务,
/etc/init.d/postfix start
chkconfig postfix on
@H_290_17@mail -s "md5sum wrong" [email protected] </etc/hosts
#开始写check.sh脚本
[[email protected] BACkup]# mkdir -p /server/scripts
[[email protected] BACkup]# vim /server/scripts/check.sh
#!/bin/bash
#BACkup上的脚本
find /BACkup/ -type f -name "*.tar.gz" -mtime +180 ! -name "*_6.tar.gz"|xargs rm
cd /BACkup/ && md5sum -c check.log >/BACkup/result.log
if [ $? -ne 0 ];then
@H_290_17@mail -s "md5sum wrong" [email protected] </BACkup/result.log
fi
#定时任务
# crontab -e
#check & send result at 20180801
00 03 * * * /bin/sh /server/scripts/check.sh >/dev/null 2>&1
以上是大佬教程为你收集整理的Centos6.9 搭建rsync服务端与客户端 案例:全网备份项目全部内容,希望文章能够帮你解决Centos6.9 搭建rsync服务端与客户端 案例:全网备份项目所遇到的程序开发问题。
如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。
本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。