E-mail: 1226032602@qq.com
Official documents
https://axkibe.github.io/lsyncd/
https://github.com/axkibe/lsyncd
brief introduction
Lsyncd uses file system event interfaces (inotify or fsevents) to monitor changes to local files and directories. Lsyncd organizes these events for a few seconds and then generates one or more processes to synchronize changes to the remote file system. The default synchronization method is rsync
Lsyncd is a lightweight real-time mirror solution. Lsyncd is relatively easy to install and does not require new file systems or block devices. Lysncd does not interfere with local file system performance
Fine-grained customization can be achieved through configuration files. Custom operation configurations can even be written from scratch, from shell scripts to code written in Lua
Version requirements
Lsyncd 2.2.1 requires Rsync > = 3.1 on all source and target computers
install
lsyncd in epel source
yum install lsyncd
To configure
Configuration file description/etc/lsyncd.conf
lsyncd configuration files are written in lua grammar
settings settings { logfile log file pidfile pid file nodaemon Indicates that daemon mode is not enabled by default statusFile Running status file statusInterval take lsyncd The state of the statusFile Interval, default 10 seconds inotifyMode Appoint inotify Monitored events, default is CloseWrite,It can also be Modify or CloseWrite or Modify maxProcesses Maximum number of processes maxDelays How many monitoring events are synchronized once,even if delay Time is synchronized before it arrives }
Three modes of sync
default.rsync
sync { default.rsync, source = "/tmp/src", target = "172.29.88.223:/tmp/dest", maxDelays = 5, delay = 30, -- init = true, rsync = { binary = "/usr/bin/rsync", archive = true, compress = true, bwlimit = 2000 rsh = "/usr/bin/ssh -p 22 -o StrictHostKeyChecking=no" } }
rsync daemon
sync { default.rsync, source = "/tmp/src", target = "rsync_backup@172.16.1.41::backup", delete="running", exclude = { ".*", ".tmp" }, delay = 3, init = false, rsync = { binary = "/usr/bin/rsync", archive = true, compress = true, verbose = true, password_file = "/etc/rsync.pwd", _extra = {"--bwlimit=200"} } }
default.rsyncssh
sync { default.rsyncssh, source="/srcdir", host="remotehost", excludeFrom="/etc/lsyncd.exclude", targetdir="/dstdir", rsync = { archive = true, compress = false, whole_file = false }, ssh = { port = 1234 } }
default.direct
sync { default.direct, source = "/home/user/src/", target = "/home/user/trg/" }
/etc/lsyncd.conf
settings { logfile = "/var/log/lsyncd/lsyncd.log", statusFile = "/var/log/lsyncd/lsyncd.status", inotifyMode = "CloseWrite", maxProcesses = 8, } sync { default.rsync, source = "/tmp/src", target = "rsync_backup@172.16.1.41::backup", delete="running", exclude = { ".*", ".tmp" }, delay = 3, init = false, rsync = { binary = "/usr/bin/rsync", archive = true, compress = true, verbose = true, password_file = "/etc/rsync.pwd", _extra = {"--bwlimit=200"} } } sync { default.rsync, source = "/tmp/src", target = "rsync_backup@172.16.1.41::wuxing", delete="running", exclude = { ".*", ".tmp" }, delay = 3, init = false, rsync = { binary = "/usr/bin/rsync", archive = true, compress = true, verbose = true, password_file = "/etc/rsync.pwd", _extra = {"--bwlimit=200"} } }
delete
delete = true #Delete content that is not in the source on the target. Contents deleted at startup and during normal operation delete = false #No files on the target will be deleted. Not on startup or normal operation delete = 'startup' # Lsyncd will delete files on the target at startup, but not during normal operation delete = 'running' # Lsyncd does not delete files on the target at startup, but deletes files deleted during normal operation
settings { logfile = "/var/log/lsyncd/lsyncd.log", statusFile = "/var/log/lsyncd/lsyncd.status", inotifyMode = "CloseWrite", maxProcesses = 8, } sync { default.rsync, source = "/data", target = "rsync_backup@backup::backup", delete= true, exclude = { ".*" }, delay = 1, rsync = { binary = "/usr/bin/rsync", archive = true, compress = true, verbose = true, password_file = "/etc/rsync.pwd", _extra = {"--bwlimit=200"} } }