使用rsync+inotify同步两台服务器文件

目标功能:将B服务器文件同步到A服务器web

A服务器rsyncd.conf配置 权限600shell

A服务器rsyncd.pas文件配置  权限600服务器

同步文件路径 /data/wwwroot/shen/  权限755tcp

打开873端口:iptables -I INPUT 4 -p tcp -m state --state NEW -m tcp --dport 873 -j ACCEPT.net

保存设置:service iptables saverest

重启:service iptables restartorm

启动服务 rsync --daemon --config=/etc/rsyncd.confhtm

删除文件便可重启rsync rm -rf /var/run/rsyncd.pidblog

kill cat /var/run/rsyncd.pidip

 

B服务器

rsyncd.pas  权限600

将B服务器中/data/wwwroot/shen/内的全部文件同步到A服务器中

rsync -avH --progress --delete --password-file=/etc/rsyncd.pas /data/wwwroot/shen/ root@112.74.203.95::web

 

常见错误:http://www.jb51.net/article/31920.htm

 

查看是否支持inotify    ls -lsart /proc/sys/fs/inotify

下载 yum install inotify-tools --enablerepo=epel

检测是否成功安装 inotifywait -h

 

编写shell脚本

#etc/rc.d/inotify.sh

inotifywait -mrq --format '%Xe %w%f' -e modify,create,delete,attrib /data/wwwroot/shen/ | while read file
do
rsync -avH --progress --delete --password-file=/etc/rsyncd.pas /data/wwwroot/shen root@112.74.203.95::web
done

 

chmod +x /etc/rc.d/inotify.sh

执行脚本:/etc/rc.d/inotify.sh

相关文章
相关标签/搜索