有2种方法可以安装
1.yum安装,前提是安装了epel更新源。使用命令:
2.github下载,地址为:https://github.com/axkibe/lsyncd
安装lua软件包以及依赖软件
1
| yum install -y lua lua-devel cmake rsync
|
解压下载的压缩包
1
| unzip lsyncd-master.zip -d /usr/src/
|
进入目录
1
| cd /usr/src/lsyncd-master/
|
使用cmake编译,如果没有安装cmake,可以yum安装一下
1
| cmake -DCMAKE_INSTALL_PREFIX=/usr/local/lsyncd
|
进入安装目录
创建配置文件目录和日志目录
进入配置文件目录
编译配置文件
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35
| 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免密码登录
最后启动
1
| /usr/local/lsyncd/bin/lsyncd -log Exec /usr/local/lsyncd/etc/lsyncd.conf
|
关闭
1 2
| ps -aux | grep lsyncd kill id
|
编译启动脚本
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205
| #!/bin/bash
. /etc/init.d/functions
. /etc/sysconfig/network
[ "$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
|
设置权限
1
| chmod 755 /etc/init.d/lsyncd
|
添加到开机自启动文件中
1
| echo "/etc/init.d/lsyncd start" >> /etc/rc.local
|