Home   >>   Lsyncd   >>   Automatic Remote Server Synchronization With Lsyncd
Automatic Remote Server Synchronization With Lsyncd PDF Print E-mail
( 1 Vote )
How To - Lsyncd
Written by Christian Foronda   
Thursday, 02 September 2010 12:15

Lsyncd (Live Syncing Daemon) is a program that uses rsync to synchronize local directories with a or several remote machine(s) running rsyncd. Lsyncd watches multiple directory trees through inotify. On startup it will rsync all directories with the remote host(s), and then sync single directories by collecting the inotify events. This tool is a lightx-weight live mirror solution.

Install the latest lsyncd on RHEL / CentOS Linux:

# yum -y install libxml2-devel zlib-devel readline-devel
# wget http://lsyncd.googlecode.com/files/lsyncd-1.38.tar.gz
# tar -xzvf lsyncd-1.38.tar.gz
# cd lsyncd-1.38
# ./configure
# make
# make install

 

Configure:

# cp lsyncd.conf.xml /etc/lsyncd.conf.xml
# cd ..
# rm -rf lsyncd-1.38
# vi /etc/lsyncd.conf.xml

 

At line 62: change to directory you'd like to mirror

<source path="/var/www/html"/>

 

At line 63: change to destination remote directory

<target path="server2:/var/www/html"/>

 

Create init script:

# vi /etc/rc.d/init.d/lsyncd

 

#!/bin/bash
#
# lsyncd: Starts the lsync Daemon
#
# chkconfig: 345 99 90
# description: Lsyncd uses rsync to synchronize local directories with a remote
# machine running rsyncd. Lsyncd watches multiple directories
# trees through inotify. The first step after adding the watches
# is to, rsync all directories with the remote host, and then sync
# single file buy collecting the inotify events.
# processname: lsyncd

. /etc/rc.d/init.d/functions

config="/etc/lsyncd.conf.xml"
lsyncd="/usr/local/bin/lsyncd"
lockfile="/var/lock/subsys/lsyncd"
prog="lsyncd"
RETVAL=0

start() {
	if [ -f $lockfile ]; then
	echo -n $"$prog is already running: "
	echo
	else
	echo -n $"Starting $prog: "
	daemon $lsyncd --conf=$config
	RETVAL=$?
	echo
	[ $RETVAL = 0 ] && touch $lockfile
	return $RETVAL
	fi

stop() {
	echo -n $"Stopping $prog: "
	killproc $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 $?

 

# chmod 755 /etc/rc.d/init.d/lsyncd
# /etc/rc.d/init.d/lsyncd start
Starting lsyncd: [  OK  ]
# chkconfig --add lsyncd
# chkconfig lsyncd on

 

Configure logs to rotate:

# vi /etc/logrotate.d/lsyncd

 

/var/log/lsyncd {
	daily
	copytruncate
	ompress
	notifempty
	missingok
	postrotate
	/etc/rc.d/init.d/lsyncd restart 2>&1 > /dev/null || true
	endscript
	}

 

Reference:
http://code.google.com/p/lsyncd/
http://www.server-world.info/en/CentOS_5/lsync/1.html




blog comments powered by Disqus
Last Updated on Tuesday, 01 March 2011 09:58