/var/www/html。uname -a # 核心需 ≥ 2.6 支援 inotify
rpm -qa | grep rsync # 未安裝則 yum -y install rsync
/etc/rsyncd.confuid = root
gid = root
max connections = 36000
use chroot = no
log file = /var/log/rsyncd.log
pid file = /var/run/rsyncd.pid
lock file = /var/run/rsyncd.lock
timeout = 300
[tongbu]
path = /var/www/html
list = yes
comment = web sync module
ignore errors = yes
read only = no
hosts allow = 10.80.11.245
hosts deny = *
auth users = backup
secrets file = /etc/rsyncd.secrets
useradd backup
passwd backup # 設定系統密碼(可不同於 rsync 密碼)
echo "backup:123456" > /etc/rsyncd.secrets
chmod 600 /etc/rsyncd.secrets
/usr/bin/rsync --daemon --config=/etc/rsyncd.conf
# 加入 /etc/rc.local 開機自啟
cd /usr/local
wget https://sersync.googlecode.com/files/sersync2.5RC1_32bit_binary.tar.gz
tar zxvf sersync2.5RC1_32bit_binary.tar.gz
cd GNU-Linux-x86
confxml.xml 關鍵區段<localpath watch="/var/www/html">
<remote ip="10.80.11.243" name="tongbu"/>
<remote ip="10.80.11.244" name="tongbu"/>
</localpath>
<rsync>
<auth start="true" users="backup" passwordfile="/etc/rsync.pas"/>
<userDefinedPort start="false" port="873"/>
<timeout start="false" time="100"/>
</rsync>
echo "123456#" > /etc/rsync.pas # 密碼以 # 結尾
chmod 600 /etc/rsync.pas
./sersync2 -d -r # 常駐進程模式,-r 先執行一次全量同步
# 加入 /etc/rc.local 開機自啟
/var/www/html 建立/修改/刪除檔案,觀察 Web 端是否即時同步。tail -f /var/log/rsyncd.log(Web 端)、tail -f /tmp/rsync_fail_log.sh(發布端失敗重試日誌)。<crontab> 區段定期執行完整同步。| 參數 | 說明 |
|---|---|
| uid/gid | 守護進程運行身分 |
| use chroot | no 可讀取符號連結外的檔案 |
| max connections | 最大並發連線數 |
| read only | no 允許上傳(推送端視角) |
| auth users | 虛擬用戶名,非系統用戶 |
| secrets file | 密碼檔路徑,格式 user:pass |
| hosts allow/deny | IP 白/黑名單 |
Rsync 提供高效增量傳輸,Sersync 基於 inotify 觸發即時同步,兩者結合構建出低延遲、高可靠的多伺服器檔案同步方案。生產環境建議加入監控告警(如同步延遲、失敗重試次數),確保資料一致性。