安装lua关联包:
yum install lua lua-static lua-devel
安装lsyncd:
wget https://lsyncd.googlecode.com/files/lsyncd-2.1.5.tar.gz
tar -xzvf lsyncd-2.1.5.tar.gz
cd lsyncd-2.1.5
./configure -prefix=/usr/local/lsyncd
make&&make install
ln -s /usr/local/lsyncd/bin/lsyncd /usr/bin/lsyncd
配置lsyncd:
本地模式:
mkdir /usr/local/lsyncd/etc
cd /usr/local/lsyncd/etc
vim lsyncd.conf.lua
settings{
logfile ="/var/log/lsyncd.log",
statusFile ="/var/log/lsyncd-status.log",
pidfile ="/var/run/lsyncd.pid",
statusInterval =20,
nodaemon =false, --测试可以开启
inotifyMode ="CloseWrite",
maxProcesses =4,
maxDelays =1,
}
sync{
default.rsync,
source ="/data/test1",
target ="/data/test2",
maxDelays = 5,
delay = 30,
rsync ={
binary ="/usr/bin/rsync",
archive =true,
compress =true,
owner =true,
perms =true,
_extra ={"--include=*-G.jpg","--exclude=*"},
},
}
参数说明:
--//表示注释。
nodaemon=true//表示不启用守护模式。默认是启用。
sync里面是定义同步参数,指定默认以直接模式direct运行。
Lsyncd支持rsync、rsyncssh、direct三种模式。
maxDelays 累计到多少所监控的事件激活一次同步,即使后面的delay延迟时间还未到
delay 累计事件,等待rsync同步延时时间,默认15秒(最大累计到1000个不可合并的事件)。
详细参数说明:
启动:
lsyncd /usr/local/lsyncd/etc/lsyncd.conf.lua
同步远程服务器目录:
远程目录有两种模式,rsync模式和rsyncssh模式。
Rsync模式配置:
settings{
logfile ="/var/log/lsyncd.log",
statusFile ="/var/log/lsyncd-status.log",
pidfile ="/var/run/lsyncd.pid",
statusInterval =20,
nodaemon =false, --测试可以开启
maxProcesses =4,
maxDelays =1,
}
sync{
default.rsync,
source ="/data/test1",
target ="[email protected]:/data/test2",
rsync ={
binary ="/usr/bin/rsync",
archive =true,
compress =true,
owner =true,
perms =true,
password_file="/etc/rsyncd/rsyncd.password",
_extra ={"--include=*-G.jpg","--exclude=*"},
},
}