lsyncd 是一个支持实时、双向、多机器的多模式文件同步工具。使用 Lua 语言封装了 inotify 和 rsync 工具,采用了 Linux 内核(2.6.13 及之后)里的 inotify 触发机制,而后经过 rsync 去差别同步,达到实时的效果。css
在源文件服务器上安装:linux
yum -y install lsyncd
lsyncd 主配置文件,假设放置在/etc/lsyncd.conf
:git
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
。github
.svn Runtime/** Uploads/**
为避免每次都须要手动输入密码,可设置为 SSH 免密登陆。web
lsyncd -log Exec /etc/lsyncd.conf
原文地址: https://shockerli.net/post/li...
更多文章请访问个人我的博客: https://shockerli.net