================================Start 安装环境 Start================================
+------------------------------------+
1.安装环境
+------------------------------------+
推送端:192.168.8.11 (eth0-IP)
接受端:192.168.8.12 (eth0-IP)

+------------------------------------+
2.推送端和接受端安装
+------------------------------------+
yum -y install rsync xinetd

================================End 安装环境 End================================

================================Start 接受端配置 Start================================
+------------------------------------+
1.向系统添加xinetd
+------------------------------------+
chkconfig --add xinetd
chkconfig --list xinetd

+------------------------------------+
2.编辑rsync
+------------------------------------+
vim /etc/xinetd.d/rsync
rsync修改以下内容:
+------------
disable = yes => disable = no
------------+

+------------------------------------+
3.创建密码文件
+------------------------------------+
vim /etc/rsyncd.secrets
rsyncd.secrets输入以下内容:
+------------
iphper:123456
------------+

修改密码文件权限:
chown root.root /etc/rsyncd.secrets
chmod 600 /etc/rsyncd.secrets

+------------------------------------+
4.创建rsyncd.conf文件
+------------------------------------+
vim /etc/rsyncd.conf
rsyncd.conf输入以下内容:
+------------
max connections = 2
log file = /var/log/rsync.log
port = 873
timeout = 300

[wwwroot]
comment = shared data stored here
path = /lnmp/htdocs
read only = false
list = yes
uid = root
gid = root
auth users = iphper
secrets file = /etc/rsyncd.secrets
hosts allow = 192.168.8.11
hosts deny = *
ignore errors = yes
------------+

+------------------------------------+
5.配置生效
+------------------------------------+
service xinetd restart

+------------------------------------+
6.启动RSYNC服务
+------------------------------------+
/usr/bin/rsync rsyncd --daemon

查看是否有端口 873
================================End 接受端配置 End================================

================================Start 推送端配置 Start================================
+------------------------------------+
1.创建密码文件
+------------------------------------+
vim /etc/rsyncd.secrets
rsyncd.secrets输入以下内容:
+------------
123456
------------+

修改密码文件权限:
chown root.root /etc/rsyncd.secrets
chmod 600 /etc/rsyncd.secrets

+------------------------------------+
2.同步文件命令
+------------------------------------+
rsync -vzrtopg --progress --delete iphper@192.168.8.12::wwwroot /lamp/apache2/htdocs/ --password-file=/etc/rsyncd.secrets

rsync -vzrtopg --progress --password-file=/etc/rsyncd.secrets /lamp/apache2/htdocs/ iphper@192.168.8.12::wwwroot

RSYNC用法:
rsync [OPTION]... [USER@]HOST::SRC [DEST] #从RSYNC SERVER备份文件到本地机器
rsync [OPTION]... SRC [SRC]... [USER@]HOST::DEST #从本地机器备份文件到RSYNC SERVER

+------------------------------------+
3.启动rsync服务
+------------------------------------+
/usr/bin/rsync --daemon --config=/etc/rsyncd/rsyncd.conf

+------------------------------------+
4.编写可执行的Shell
+------------------------------------+
vim /tmp/rsync-pull.sh
rsync-pull.sh输入以下内容:
+------------
#!/bin/bash
rsync -vzrtopg --progress --delete iphper@192.168.8.12::wwwroot /lamp/apache2/htdocs/ --password-file=/etc/rsyncd.secrets
------------+

chmod +x /tmp/rsync-pull.sh

vim /tmp/rsync-push.sh
rsync-push.sh输入以下内容:
+------------
#!/bin/bash
rsync -vzrtopg --progress --password-file=/etc/rsyncd.secrets /lamp/apache2/htdocs/ iphper@192.168.8.12::wwwroot
------------+

chmod +x /tmp/rsync-push.sh

+------------------------------------+
5.rsync加入定时执行
+------------------------------------+
crontab -e

输入以下内容:
+------------
*/1 * * * * /tmp/rsync-push.sh
*/2 * * * * /tmp/rsync-pull.sh
------------+

================================End 推送端配置 End================================