lsyncd实时同步工具:

Lsyncd 实际上是lua语言封装了 inotify 和 rsync 工具,采用了 Linux 内核(2.6.13 及以后)里的 inotify 触发机制,然后通过rsync去差异同步,达到实时的效果。

安装:

apt-get install lsyncd

配置:

mkdir /etc/lsyncd

cp -rv /usr/share/doc/lsyncd/examples/lrsync.lua /etc/lsyncd/lrsync.conf.lua

vi /etc/lsyncd/lrsync.conf.lua


-- User configuration file for lsyncd.

-- Simple example for default rsync.

settings{
logfile="/var/log/lsyncd.log",
statusFile = "/tmp/lsyncd.stat",
statusInterval = 1,
maxProcesses=5,
}

sync{target="[email protected]:/home/ming",
br/>default.rsync,
source="/home/ming",
target="[email protected]:/home/ming",
excludeFrom="/etc/lsyncd/rsync_exclude.list",
delay=10,
}

:wq

vi /etc/lsyncd/rsync_exclude.list

/home/ming/aa
/home/ming/bb
:wq

启动服务:

lsyncd /etc/lsyncd/lrsync.conf.lua

杀服务是通过查找pid处理:

ps -ef | grep lsyncd

kill -9 pid