1.数据端(server)
#tar zxvf rsync-2.6.9.tar.gz
#cd rsync-2.6.9
#./configure --prefix=/usr/local/rsync
#make
#make install

#vi /etc/rsyncd.conf (手动生成,填写以下内容)
uid = root
gid = root
use chroot = no
max connections = 4
strict modes =yes
port = 873
pid file = /var/run/rsyncd.pid
lock file = /var/run/rsync.lock
log file = /var/log/rsyncd.log

[backup]
path = /home/backup/
comment = This is a test
ignore errors
read only = yes
list = no
auth users = lyd
secrets file = /etc/rsync.pas
hosts allow = 192.168.0.1,192.168.0.2
hosts deny = 0.0.0.0/0

配置rsync密码
#vim /etc/rsync.pas
lyd:123456
#cd /etc
#chown root.root rsync.pas
#chmod 600 rsync.pas

#vi /etc/xinetd.d/rsync
service rsync
{
disable = no #仅修改此处,表示启用这个服务
socket_type = stream
wait = no
user = root
server = /usr/bin/rsync
server_args = --daemon
log_on_failure += USERID
}

#chkconfig rsync on
#/usr/bin/rsync --daemon
#vi /etc/rc.local
加入一行/usr/bin/rsync --daemon


2.备份端(client)
#vi /etc/rsync.pas
123456
#cd /etc
#chown root.root rsync.pas
#chmod 600 rsync.pas

配置完成后
从server端取文件
/usr/bin/rsync -vzrtopg --progress --delete [email protected]::backup /home/backup --password-file=/etc/rsync.pas
向SERVER端传文档
/usr/bin/rsync -vzrtopg --progress --password-file=/etc/rsync.pas /home/www [email protected]::test

注意被同同步目录后边带“/”和不带“/”的区别?
同步的时候如果被同步的目录为/home/www 这样同步到cnweb003www这个模块定义的目录下的内容就是目录www
如果被同步的目录为/home/www/ 这样同步到cnweb003www这个模块定义的目录下得就是www下得所有内容

自动运行
1)vi /usr/local/rsync/time.sh
#!/bin/bash
/usr/bin/rsync -vzrtopg --progress --delete [email protected]::backup /home/backup --password-file=/etc/rsync.pass
2) crontab -e
加入* 1 * * * /usr/local/rsync/time.sh //每1小时运行一次time.sh脚本文档