Introduction :- Lsyncd watches a local directory trees event monitor interface (inotify or fsevents). It aggregates and combines events for a few seconds and then spawns one (or more) process(es) to synchronize the changes. By default this is rsync. Lsyncd is thus a light-weight live mirror solution that is comparatively easy to install not requiring new filesystems or blockdevices and does not hamper local filesystem performance.
Install following dependencies:
yum install gcc-c+\+ yum install lua yum install lua-devel
Now proceed for lsyncd installation:
Login on server as a “root” user.
cd /usr/local/ wget http://lsyncd.googlecode.com/files/lsyncd-2.1.5.tar.gz tar \-xvzf lsyncd-2.1.5.tar.gz cd lsyncd-2.1.5 ./configure make make install
Create Linux daemon (say lsyncd) which call up our customized lsyncd config file. Daemon script would be like…
Place this file inside /etc/rc.d/init.d/
. /etc/rc.d/init.d/functions user=anj config="/lsyncd.lua" lsyncd="/usr/local/bin/lsyncd" lockfile="/lsyncd" prog="lsyncd" RETVAL=0 start() { if [ -f $lockfile ]; then echo -n $"$prog is already running: " echo else echo -n $"Starting $prog: " #su - $user -c "$lsyncd $config -insist" daemon --user $user $lsyncd $config -insist RETVAL=$? echo [ $RETVAL = 0 ] && su - $user -c "touch $lockfile" return $RETVAL fi } stop() { echo -n $"Stopping $prog: " killproc -d 60 lsyncd RETVAL=$? echo [ $RETVAL = 0 ] && rm -f $lockfile return $RETVAL } case "$1" in start) start ;; stop) stop ;; restart) stop start ;; status) status lsyncd ;; *) echo "Usage: lsyncd {start|stop|restart|status}" exit 1 esac exit $?
Now configure lsyncd config file (lsyncd.lua). In this file we have our sync configurations.
It should be something like
--SETTINGS settings { logfile = "/lsyncd.log", statusFile = "/lsyncd.stat", statusInterval = 300 } --ENDSETTINGS --SERVERS serverlist = {"SERVER1:DISTINATION", "SERVER2:DISTINATION"} --ENDSERVERS for _, server in ipairs(serverlist) do sync { default.rsync, source="", target=server, delay = 30, rsync = { protect_args = false } } end
How to start and stop
/etc/init.d/lsyncd start /etc/init.d/lsyncd stop
Note:-
There might be the issue during start of lsyncd, as some time list of files are more than max user watches. For fixing this we need to change from following file.
/proc/sys/fs/inotify/max_user_watches
Command
echo “819211” > /proc/sys/fs/inotify/max_user_watches