一、 在 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)。
[[email protected] ~]# yum -y install rsync
二、配置 web_bak rsync
[[email protected]_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
[[email protected]_bak]# echo"root:123456" > /etc/rsyncd.pass
[[email protected]_bak]# chown root.root/etc/rsyncd.pass
[[email protected]_bak]# chmod 600/etc/rsyncd.pass
三、以守护进程启动 rsync ,并加入开机启动
[[email protected]_bak]# rsync --daemon
[[email protected]_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
[[email protected]_bak]# which rsync
/usr/bin/rsync
[[email protected]_bak]# echo"/usr/bin/rsync --daemon" >> /etc/rc.d/rc.local
[[email protected]_bak]# iptables -I INPUT -p tcp--dport 873 -j ACCEPT
[[email protected]_bak]# service iptables save
[[email protected]_bak]# service iptables restart
[[email protected] ~]# echo"123456" > /etc/rsyncd.pass # 注意这里的密码文件中只有用户密码没有用户,格式跟 web_bak 的不同
[[email protected] ~]# chown root.root/etc/rsyncd.pass
[[email protected] ~]# chmod 600 /etc/rsyncd.pass
在源服务器上,运行测试:
从服务器端拉取(180)
/usr/bin/rsync -avz --progress --password-file=/etc/rsync.pass [email protected]::test /www/test
网服务器推送
/usr/bin/rsync -avz --progress --password-file=/etc/rsync.pass /www/test [email protected]::test