「lsyncd」- 文件实时同步工具

认识

官网:https://github.com/axkibe/lsyncd
文档:https://lsyncd.github.io/lsyncd/
仓库:https://github.com/lsyncd/lsyncd

Lsyncd uses a filesystem event interface (inotify or fsevents) to watch for changes to local files and directories. Lsyncd collates these events for several seconds and then spawns one or more processes to synchronize the changes to a remote filesystem. 简而言之,lsyncd = rsync + inotify,实现变更文件自动增量同步。

构建

epel-release
yum -y install lua lua-devel pkgconfig gcc asciidoc lsyncd

/etc/lsyncd.conf

settings {
  logfile = "/var/log/lsyncd/lsyncd.log",
  delay = 1
}
sync {
  default.rsync,
  source="/home/test/public_html/",
  target="server2:/home/test/public_html/",
  rsync = {
    compress = true,
    acls = true,
    verbose = true,
    owner = true,
    group = true,
    perms = true,
    rsh = "/usr/bin/ssh -p 22 -o StrictHostKeyChecking=no"
  }
}

参考

Real-time file synchronization