一、    在 web(web安装rsync就行不需要配置rsyncd.conf) 、web_bak 安装 rsync(web在/var/www/html/下更新信息,在wen_bak的/var/www/html/下跟着更新所有数据)

IP:192.168.1.80是源服务器就是服务端(yum安装rsync就行,不需要配置),192.168.1.81是目的服务器就是客户端(yum安装rsync,还要配置/etc/rsyncd.conf)。

[root@localhost ~]# yum -y install rsync

二、配置 web_bak rsync

[root@web_bak]# vim /etc/rsyncd.conf   ## 配置文件需手工创建
# rsync
uid = nobody
gid = nobody
use chroot = no
max connections = 10
pid file = /var/run/rsyncd.pid
lock file = /var/run/rsyncd.lock
log file = /var/run/rsyncd.log
[web1]
path = /var/www/html/(
客户端的路径不一样要和服务端一样,自己定)
comment = web_bak file
ignore errors
read only = no
write only = no

list = false
uid = root
gid = root
auth users = root
secrets file = /etc/rsyncd.pass

[root@web_bak]#
echo"root:123456" > /etc/rsyncd.pass
[root@web_bak]#
chown root.root/etc/rsyncd.pass
[root@web_bak]#
chmod 600/etc/rsyncd.pass

三、以守护进程启动 rsync ,并加入开机启动

[root@web_bak]# rsync --daemon
[root@web_bak]#
ps aux | greprsync
root      1344 0.1  0.0 107612   660 ?        Ss  19:17   0:00 rsync --daemon
root      1347  1.0  0.1 103240   864 pts/0    S+   19:17  0:00 grep rsync

[root@web_bak]#
which rsync
/usr/bin/rsync
[root@web_bak]# echo"/usr/bin/rsync --daemon" >> /etc/rc.d/rc.local
[root@web_bak]# iptables -I INPUT -p tcp--dport 873 -j ACCEPT
[root@web_bak]# service iptables save
[root@web_bak]# service iptables restart

[root@localhost ~]# echo"123456" > /etc/rsyncd.pass  # 注意这里的密码文件中只有用户密码没有用户,格式跟 web_bak 的不同
[root@localhost ~]#
chown root.root/etc/rsyncd.pass
[root@localhost ~]#
chmod 600 /etc/rsyncd.pass

在源服务器上,运行测试:  

从服务器端拉取(180)

/usr/bin/rsync -avz --progress --password-file=/etc/rsync.pass root@192.168.1.181::test /www/test

 

网服务器推送

/usr/bin/rsync -avz --progress --password-file=/etc/rsync.pass  /www/test root@192.168.1.181::test