目標功能:將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