一、服務器性能:rsync只能實現定時更新,不管網站有無文件更新,rsync都會按着定時任務去檢查文件是否有更新,當數據文件較大時會使服務器性能降低;而rsync+inotify 爲觸發式更新,也就是說只有當某個文件發生改動時纔會更新,這樣一來對服務器性能影響較小。 二、數據實時性:若是選擇rsync,每隔多長時間同步一次數據是個問題,時間越短,對性能影響就越大。時間太長,用戶/編輯沒法接受。採用rsync+inotify可實現實時更新, 當A服務器文件有更新時,其它服務器當即更新
A:192.168.1.101 B:192.168.1.102 C:192.168.1.103 D:192.168.1.104 注:數據源服務器爲A,目標服務器爲B、C、D
cd /data/software wget https://rsync.samba.org/ftp/rsync/rsync-3.0.9.tar.gz tar zxvf rsync-3.0.9.tar.gz cd rsync-3.0.9 ./configure make make install
mkdir -p /usr/local/bin /usr/bin/install -c -m 755 rsync /usr/local/bin mkdir -p /usr/local/share/man/man1 mkdir -p /usr/local/share/man/man5 if test -f rsync.1; then /usr/bin/install -c -m 644 rsync.1 /usr/local/share/man/man1; fi if test -f rsyncd.conf.5; then /usr/bin/install -c -m 644 rsyncd.conf.5 /usr/local/share/man/man5; fi
uid = root gid = root use chroot = no max connections = 20 strict modes = yes log file = /data/logs/rsyncd/rsyncd.log pid file = /data/logs/rsyncd/rsyncd.pid lock file = /data/logs/rsyncd/rsync.lock log format = %t %a %m %f %b [web] path = /data/vhosts/it121net/ auth users = username read only = no hosts allow = 192.168.1.0/24 #能夠是IP段,也能夠是IP地址 list = no uid = root gid = root secrets file = /etc/rsync.passwd ignore errors = yes
mkdir /data/logs/rsyncd
username:passwd
# rsync --daemon --config=/etc/rsync.conf
# echo "rsync --daemon --config=/etc/rsync.conf" >>/etc/rc.local
killall rsync
cd /data/software wget https://rsync.samba.org/ftp/rsync/rsync-3.0.9.tar.gz tar zxvf rsync-3.0.9.tar.gz cd rsync-3.0.9 ./configure make make install
cd /data/software wget http://cloud.github.com/downloads/rvoicilas/inotify-tools/inotify-tools-3.14.tar.gz tar zxvf inotify-tools-3.14.tar.gz cd inotify-tools-3.14 ./configure make make install
#!/bin/sh SRC=/data/vhosts/it121net/ DES=web WEB2=192.168.1.102 WEB3=192.168.1.103 WEB4=192.168.1.104 USER=username /usr/local/bin/inotifywait -mrq -e create,move,delete,modify $SRC | while read D E F do rsync -ahqzt --password-file=/etc/rsync-client.passwd --delete $SRC $USER@$WEB2::$DES rsync -ahqzt --password-file=/etc/rsync-client.passwd --delete $SRC $USER@$WEB3::$DES rsync -ahqzt --password-file=/etc/rsync-client.passwd --delete $SRC $USER@$WEB4::$DES done #注意:網絡上面大部分都是顯示一箇中槓,多是編碼的事情,實際是應該是兩個槓。
#chmod +x /etc/rsync-web.sh
#nohup /etc/rsync-web.sh & //必須使用nohup放入後臺執行,不然關閉終端後此腳本進程會自動結束 /etc/rsync-web.sh &
sudo pkill rsync sudo pkill inotifywait
setsebool -P rsync_disable_trans on
/usr/bin/rsync /usr/local/bin/rsync /etc/xinetd.d/rsync