有2种方法可以安装
1.yum安装,前提是安装了epel更新源。使用命令:
yum install -y lsyncd
2.github下载,地址为:https://github.com/axkibe/lsyncd
安装lua软件包以及依赖软件
yum install -y lua lua-devel cmake rsync
解压下载的压缩包
unzip lsyncd-master.zip -d /usr/src/
进入目录
cd /usr/src/lsyncd-master/
使用cmake编译,如果没有安装cmake,可以yum安装一下
cmake -DCMAKE_INSTALL_PREFIX=/usr/local/lsyncd
make && make install
进入安装目录
cd /usr/local/lsyncd/
创建配置文件目录和日志目录
mkdir etc var
进入配置文件目录
cd etc/
编译配置文件
vim lsyncd.conf
settings {
--pid文件
logfile = "/usr/local/lsyncd/var/lsyncd.log",
--状态文件
statusFile = "/usr/local/lsyncd/var/lsyncd.status",
--同步模式,意思就是有更新就同步
inotifyMode = "CloseWrite or Modify",
--最大8个进程
maxProcesses = 8,
}
sync {
default.rsync,
source = "/www",
target = "root@192.168.10.50:/www",
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"
}
}
在远端被同步的服务器上开启ssh无密码登录,请注意用户身份:(用root还是最吼的!!!)
链接:ssh免密码登录
最后启动
/usr/local/lsyncd/bin/lsyncd -log Exec /usr/local/lsyncd/etc/lsyncd.conf
关闭
ps -aux | grep lsyncd
kill id
编译启动脚本
vim /etc/init.d/lsyncd
#!/bin/bash
#
# chkconfig: - 85 15
# description: Lightweight inotify based sync daemon
#
# processname: lsyncd
# config: /usr/local/lsyncd/etc/lsyncd.conf
# config: /etc/sysconfig/lsyncd
# pidfile: /var/run/lsyncd.pid
# Source function library
. /etc/init.d/functions
# Source networking configuration.
. /etc/sysconfig/network
# Check that networking is up.
[ "$NETWORKING" = "no" ] && exit 0
LSYNCD_OPTIONS="-pidfile /var/run/lsyncd.pid /usr/local/lsyncd/etc/lsyncd.conf"
if [ -e /etc/sysconfig/lsyncd ]; then
. /etc/sysconfig/lsyncd
fi
RETVAL=0
prog="lsyncd"
thelock=/var/lock/subsys/lsyncd
start() {
[ -f /usr/local/lsyncd/etc/lsyncd.conf ] || exit 6
echo -n $"Starting $prog: "
if [ $UID -ne 0 ]; then
RETVAL=1
failure
else
daemon ${LSYNCD_USER:+--user ${LSYNCD_USER}} /usr/local/lsyncd/bin/lsyncd $LSYNCD_OPTIONS
RETVAL=$?
[ $RETVAL -eq 0 ] && touch $thelock
fi;
echo
return $RETVAL
}
stop() {
echo -n $"Stopping $prog: "
if [ $UID -ne 0 ]; then
RETVAL=1
failure
else
killproc lsyncd
RETVAL=$?
[ $RETVAL -eq 0 ] && rm -f $thelock
fi;
echo
return $RETVAL
}
reload(){
echo -n $"Reloading $prog: "
killproc lsyncd -HUP
RETVAL=$?
echo
return $RETVAL
}
restart(){
stop
start
}
condrestart(){
[ -e $thelock ] && restart
return 0
}
case "$1" in
start)
start
;;
stop)
stop
;;
restart)
restart
;;
reload)
reload
;;
condrestart)
condrestart
;;
status)
status lsyncd
RETVAL=$?
;;
*)
echo $"Usage: $0 {start|stop|status|restart|condrestart|reload}"
RETVAL=1
esac
exit $RETVAL
设置权限
chmod 755 /etc/init.d/lsyncd
添加到开机自启动文件中
echo "/etc/init.d/lsyncd start" >> /etc/rc.local