lsyncd 運用到 inotify , rsync , daemon
inotify 是檔案系統的附加功能,可監控系統檔案變動,kernel 2.6.13 以上被納入核心,類似 Windows 的 Desktop search
rsync 就不用多說了,是 linux 上同步用的好工具
lsyncd 可以背景執行,並定義多久同步不同的、變動過的,也可以用 ssh,反正 rsync 有的,基本上 lsyncd 也有吧!
lsyncd 需要 lua 套件
lsyncd 用了 inotify 機制,我想當資料量大、多時,就不會像只用 rsync 時會很慢的情況,不過要注意 inotify 可使用的數量 ( /proc/sys/fs/inotify/max_user_watches 依需求調整)
參考 : https://code.google.com/p/lsyncd/
使用的版本
lsyncd-2.1.4-4.el6.x86_64
README: https://github.com/axkibe/lsyncd/wiki/Manual-to-Lsyncd-2.1.x
要使用 lsyncd 前提是 目的端要能被來源端可以使用 ssh public key 登入
而 /etc/lsyncd.conf 設定如下
settings {
logfile = "/var/log/lsyncd/lsyncd.log",
statusFile = "/var/log/lsyncd/lsyncd-status.log",
-- 預設 10 秒更新狀態檔
statusInterval = 10,
}
sync {
default.rsync,
source="/usr/www/discuz",
target="10.10.10.135:/var/www/vhosts/xfastest.com/httpdocs/discuz",
-- source 端沒此檔, target 端會被刪除
delete = true,
rsync = {
compress = true,
verbose = true,
rsh = "/usr/bin/ssh -p 22 -o StrictHostKeyChecking=no",
-- 保留權限
acls = true,
perms = true,
owner = true,
group = true,
},
-- 同步週期,每 20 同步一次
delay = 20
}
再啟動 lsyncd 即馬上同步
並且要隨時要觀查 /var/log/lsyncd/lsyncd-status.log 的
Inotify watching 322 directories
這個 322 的數值假如有一天快達到
/proc/sys/fs/inotify/max_user_watches
就要加大 max_user_watches 值
留言