------------------rsync服务端配置----------------------------1、挂载系统自带光盘yum源安装:yum install rsync2、创建需要同步的文件夹/common/home : 表示将整个 /home 目录复制到目标目录/home/ : 表示将 /home 目录中的所有内容复制到目标目录3、在/etc/下创建rsyncd.conf文件添加以下内容:#/etc/rsyncd.confmotd file = /etc/rsyncd.motdtransfer logging = yeslog file = /var/log/rsyncd.logpid file = /var/run/rsyncd.pidlock file = /var/run/rsync.lockport = 873address = 192.168.17.130uid = nobodygid = nobodyuse chroot = noread only = yesmax connections = 10[common]comment = web contentpath = /commonignore errorsauth users = tom,jerrysecrets file = /etc/rsyncd.secretshosts allow = 192.168.17.0/255.255.255.0hosts deny = *list = false4、echo "tom:pass" > /etc/rsyncd.secretsecho "jerry:111" >> /etc/rsyncd.secrets5、chmod 600 /etc/rsyncd.secrets6、 echo "welcome to access" > /etc/rsyncd.motd7、rsync --daemon8、echo "/usr/bin/rsync --daemon" >> /etc/rc.local9、firewall-cmd --permanent --add-port=873/tcp---------------------客户端--------------------------------1、yum install rsycn2、访问:rsync -vzrtopg --progress tom@192.168.17.130::common /test3、echo "pass" > /etc/rsync.pass 把密码定义这里下面访问不用输入密码了(这个文件的权限一下要600不然报错)4、rsync -avz --delete --password-file=rsync.pass tom@192.168.17.130::common /dest所服务器上的common里的文件都弄过来test下面(以服务器common为准来变)5、写个脚本自动处理#!/bin/bashSRC=commonDEST=/dataServer=192.168.17.130User=tomPassfile=/root/rsync.pass[ ! -d $DEST ] && mkdir $DEST[ ! -d $Passfile ] && exit 2rsync -az --delete --password-file=$Passfile ${User}@${Server}::$SRC $DEST/$(date +%Y%m%d)-----------------------rsync+inotify双剑合并时时同步----------------------------------------------https://github.com/rvoicilas/inotify-tools.git 下载地址yum install rsyncyum install automake libtool下来解压文件完后进入文件夹,先bash autogen.sh运行出来configure文件再运行configure再make 再make installecho "pass" >/root/rsync.passchmod 600 rsync.pass写个脚本实时监控:#!/bin/bashSRC=/web_data/DESR=commonClient=192.168.17.130User=tomPassfile=/root/rsync.pass[ ! -e $Passfile ] && exit 2/local/src/inotifys/bin/inotifywait -mrq --timefmt '%y-%m-%d %H:%M' --format '%T %w%f %e' --event modify,create,move,delete,attrib \$SRC|while read linedoecho "$line" > /var/log/inotify_web 2>&1/usr/bin/rsync -avz --delete --progress --password-file=/root/rsync.pass $SRC \${User}@${Client}::$DESR >> /var/log/rsync_web 2>&1done &给脚 本755权限,并加入开机启动-----------------------------------------------------------------------------------被监控端(web前端)yum install rsyncmkdir -p /commonchmod 755 /commonchown nobody.nobody /commonvim /etc/rsyncd.conf#/etc/rsyncd.conftransfer logging = yeslog file = /var/log/rsyncd.logpid file = /var/run/rsyncd.pidlock file = /var/run/rsync.lockuid = nobodygid = nobodyuse chroot = noread only = noignore errors[common]comment = web contentpath = /commonauth users = tomsecrets file = /etc/rsyncd.secretshosts allow = 192.168.17.131hosts deny = *list = falseecho "tom:pass" > /etc/rsyncd.secretschmod 600 /etc/rsyncd.secretsrsync --daemon