Search Posts on Binpipe Blog

Installing Lsyncd to Create a Mirror Server on CentOS and Redhat

LSYNCD (Live SYNCing Daemon) is a flexible cross-platform synchronization tool. It uses rsync underneath it. lsync runs as a daemon and continuously runs a sync between the source and the mirror. No cron is required to maintain the sync.


Steps to deploy Lsyncd : (login as root and execute the following steps)

1. Create the password-less logging using ssh keys between the source(server1) & mirror(server2) servers.

# ssh-keygen

Press enter to create key without any passphrase.

A file /root/.ssh/id_rsa.pub will be created on server1

# cp /root/.ssh/id_rsa.pub /root/.ssh/authorized_keys


Run the same command on server2.

A file /root/.ssh/id_rsa.pub will be created on server2

# cp /root/.ssh/id_rsa.pub /root/.ssh/authorized_keys


Now open the authorized_keys file in server1 and append the contents in authorized_keys file of server2. Do the same from authorized_keys file in server2 to server1. (Now both the authorized_keys files should be the same with each others keys in them).

Login from both the servers so that the "known hosts" file is updated.

2. # yum install rsync

3. Install the lsyncd from dag wieers repository.   

Add a repo file dag.repo in the /etc/yum.repos.d/ directory with the following contents:

[dag]
name=Dag RPM Repository for Red Hat Enterprise Linux
baseurl=http://apt.sw.be/redhat/el5/en/i386/rpmforge     ## Change i386 to x86_64 if on a 64bit machine
gpgcheck=0
enabled=1

4. # yum --enablerepo=dag -y install lsyncd

5. Create a config file named /etc/lsyncd.conf and Put the following contents in it (change the target source directory & IP:/path according to your requirement):


 settings = {
   logfile    = "/var/log/lsyncd.log",
}

sync{default.rsync, source="/var/www/lsync", target="10.10.10.246:/var/www/lsync", rsyncOps="-rltvu"}


6. Create a log file :

# touch /var/log/lsyncd.log

7. Start the Services:
   # service lsyncd start
   # ckhconfig lsyncd on

That is it! You have got a live mirror server. Now if you want to mirror ''both-ways'' then you can install lsync in the server2 also and repeat the same steps.

Other Examples of lsyncd (Multiple Mirrors):

Below is the lsyncd.conf that duplicates /var/www/html on the master server to the 4 targets (mirrors) with the same path:

settings = {
   delay        = 1,
   maxProcesses = 5,
   statusFile   = "/tmp/lsyncd.status",
   logfile      = "/var/log/lsyncd.log",
}

targetlist = {
 "10.0.1.23:/var/www/html",
 "10.0.1.24:/var/www/html",
 "10.0.1.25:/var/www/html",
 "10.0.1.26:/var/www/html"
}

for _, server in ipairs(targetlist) do
  sync{ default.rsync,
    source="/var/www/html",
    rsyncOpts="-rltvupgo",
    target=server
  }
end
 
 
So use this powerful tool and leave comments if you liked it or need help. 
 

2 comments:

  1. It's very simple to find out any matter on web as compared to textbooks, as I found this article at this web page.

    ReplyDelete
  2. Hi, this weekend is fastidious in favor of me, for the reason that this
    point in time i am reading this great informative piece of writing here at my home.

    ReplyDelete

Hi, Leave a comment here and one of the binary piper's will reply soon :)