ViReR.NeT  

  Home  -  Infos/Docs  -  Tools/Outils Code  -  Links/Liens  -  News  -  Download  -  Others/Autres Site map

 

lsyncd and csync2 on SL/Centos 6.x

 




This page is inspired by: a axivo tuto,
but I need to fix some commands because I have more than 1200000 files and my csync2 sqlite db is 1Gb
and the linked tuto use "csync2 -x" with no file argument after which cause to sync all the file system on any new file or modification!
this is not very efficient :( I just need to sync one time the entire filesystem and after just syncing modifications.
I also have a different setup since I have one master and one slave for the moment.


So with epel repo installed on your Scientific Linux or CentOS 6.x you can just run as root :
# yum install csync2 lsyncd


On the slave host you may start csync2 and enable his service *OR* use xinetd
if you choose, like me, to use xinetd:
- open the tcp port 30865 in your firewall
so edit this file: /etc/sysconfig/iptables
and add the following line in your config
-A INPUT -m state --state NEW -m tcp -p tcp --dport 30865 -j ACCEPT


if you use xinetd edit the following file /etc/xinetd.d/csync2
and change the "disable" line value to "no" like this:
service csync2
{
	flags		= REUSE
	socket_type	= stream
	wait		= no
	user		= root
	group		= root
	server		= /usr/sbin/csync2
	server_args	= -i
	port		= 30865
	type		= UNLISTED
	#log_on_failure	+= USERID
	disable		= no
	#only_from	= 192.168.199.3 192.168.199.4
}




The current lsyncd rpm package is not complete,
so you will need to create your init script and configuration directory...
Here is the init script I use :

#!/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/lsyncd.conf"
lsyncd="/usr/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 nice $lsyncd $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 $?

And here is my configuration file /etc/lsyncd/lsyncd.conf

settings = {
        logident        = "lsyncd",
        logfacility     = "user",
        logfile         = "/var/log/lsyncd.log",
        statusFile      = "/var/log/lsyncd.status",
        statusInterval  = 10
}
MySync = {
    delay = 1,
    maxProcesses = 1,
    onCreate = "nice /usr/sbin/csync2 -x ^sourcePathname ",
    onModify = "nice /usr/sbin/csync2 -x ^sourcePathname ",
    onDelete = "nice /usr/sbin/csync2 -x ^sourcePathname ",
    onStartup = "nice /usr/sbin/csync2 -x",
}

sync {
        MySync,
        host   = "hostname.fqdn.tld",
        source = "/home",
        target = "/home",
}

I did'nt find a proper way to fix this
so I use to apply sync every ~20 sec you may want change this and once a day check the sync between hosts
echo "*  *  *  *  *  root  nice /usr/sbin/csync2 -u 2> /dev/null; sleep 15 ; nice /usr/sbin/csync2 -u 2> /dev/null ; sleep 15 ; nice /usr/sbin/csync2 -u" >> /etc/crontab
echo "1  3  *  *  *  root  nice /usr/sbin/csync2 -x" >> /etc/crontab