lsyncd 是一個支持實時、雙向、多機器的多模式文件同步工具。 ...
lsyncd 是一個支持實時、雙向、多機器的多模式文件同步工具。
使用 Lua 語言封裝了 inotify 和 rsync 工具,採用了 Linux 內核(2.6.13 及以後)里的 inotify 觸發機制,然後通過 rsync 去差異同步,達到實時的效果。
安裝
在源文件伺服器上安裝:
yum -y install lsyncd
配置
lsyncd 主配置文件,假設放置在/etc/lsyncd.conf
:
settings {
nodaemon = false,
logfile = "/var/log/lsyncd.log",
statusFile = "/var/log/lsyncd.status",
inotifyMode = "CloseWrite",
maxProcesses = 8
}
-- 可以有多個sync,各自的source,各自的target,各自的模式,互不影響。
sync {
default.rsyncssh,
source = "/home/wwwroot/web1/",
host = "111.222.333.444",
targetdir = "/home/wwwroot/web1/",
-- 忽略文件路徑規則,可用table也可用外部配置文件
-- excludeFrom = "/etc/lsyncd_exclude.lst",
exclude = {
".svn",
"Runtime/**",
"Uploads/**",
},
-- maxDelays = 5,
delay = 0,
-- init = false,
rsync = {
binary = "/usr/bin/rsync",
archive = true,
compress = true,
verbose = true,
_extra = {"--bwlimit=2000"},
},
}
忽略規則
需要忽略同步的文件或文件夾,excludeFrom 選項才配置該文件,exclude 類型的配置不用該配置文件。假設配置文件放在/etc/lsyncd_exclude.lst
。
.svn
Runtime/**
Uploads/**
免密登錄
為避免每次都需要手動輸入密碼,可設置為 SSH 免密登錄。
啟動
lsyncd -log Exec /etc/lsyncd.conf