1、系统光盘yum源安装:yum install rsync

2、创建需要同步的文件夹/common

/home : 表示将整个 /home 目录复制到目标目录
/home/ : 表示将 /home 目录中的所有内容复制到目标目录

2、在/etc/下创建rsyncd.conf文件
添加以下内容:
#/etc/rsyncd.conf
motd file = /etc/rsyncd.motd
transfer logging = yes
log file = /var/log/rsyncd.log
pid file = /var/run/rsyncd.pid
lock file = /var/run/rsync.lock
port = 873
address = 192.168.17.130
uid = nobody
gid = nobody
use chroot = no
read only = yes
max connections = 10
[common]
comment = web content
path = /common
ignore errors
auth users = tom,jerry
secrets file = /etc/rsyncd.secrets
hosts allow = 192.168.17.0/255.255.255.0
hosts deny = *
list = false

4、echo "tom:pass" > /etc/rsyncd.secrets
echo "jerry:111" >> /etc/rsyncd.secrets

5、chmod 600 /etc/rsyncd.secrets

6、 echo "welcome to access" > /etc/rsyncd.motd

7、rsync --daemon

8、echo "/usr/bin/rsync --daemon" >> /etc/rc.local

9、firewall-cmd --permanent --add-port=873/tcp

---------------------客户端--------------------------------
1、yum install rsycn

2、访问:rsync -vzrtopg --progress tom@192.168.17.130::common /test

3、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/bash
SRC=common
DEST=/data
Server=192.168.17.130
User=tom
Passfile=/root/rsync.pass
[ ! -d $DEST ] && mkdir $DEST
[ ! -d $Passfile ] && exit 2
rsync -az --delete --password-file=$Passfile ${User}@${Server}::$SRC $DEST/$(date +%Y%m%d)
-----------------------rsync+inotify双剑合并时时同步----------------------------------------------
https://github.com/rvoicilas/inotify-tools.git 下载地址
yum install rsync
yum install automake libtool
下来解压文件完后进入文件夹,先bash autogen.sh运行出来configure文件
再运行configure再make 再make install
echo "pass" >/root/rsync.pass
chmod 600 rsync.pass
写个脚本实时监控:
#!/bin/bash
SRC=/web_data/
DESR=common
Client=192.168.17.130
User=tom
Passfile=/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 line
do
echo "$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>&1
done &

给脚 本755权限,并加入开机启动
-----------------------------------------------------------------------------------
被监控端(web前端)
yum install rsync
mkdir -p /common
chmod 755 /common
chown nobody.nobody /common

vim /etc/rsyncd.conf

#/etc/rsyncd.conf
transfer logging = yes
log file = /var/log/rsyncd.log
pid file = /var/run/rsyncd.pid
lock file = /var/run/rsync.lock
uid = nobody
gid = nobody
use chroot = no
read only = no
ignore errors

[common]
comment = web content
path = /common
auth users = tom
secrets file = /etc/rsyncd.secrets
hosts allow = 192.168.17.131
hosts deny = *
list = false


echo "tom:pass" > /etc/rsyncd.secrets
chmod 600 /etc/rsyncd.secrets
rsync --daemon