Lsyncd installation and directory sync between remote linux servers

lsyncd_logo

 

Lsyncd stands for “Live Syncing Daemon“, as the name suggests lsyncd is used to sync or replicate files & directories locally and remotely after a specific time of interval. It uses rsync & ssh.

Follow the steps below to install lsyncd and enable an auto-sync between remote servers by ssh handshake/password-less authentication:

1. Login to the server and goto root access by sudo -s

2. lsyncd is part of Extra Packages for Enterprise Linux (EPEL), to install epel run :

yum install epel-release

3. Installing lsyncd is as simple as running just one command :

 yum -y install lsyncd

4. Now, enable the Key based authentication between Source and Destination Server.

– Login to Source server & generate the public and private keys using the command   “ssh-keygen”.

 

lsyncd-ssh-keygen

As in the above image, after executing ssh-keygen, you will be asked 3-4 inputs, just enter and continue.

Now you can copy the generated ssh RSA key from the following command :

 cat ~/.ssh/id_rsa.pub

5. Now, go to the destination server and edit the file by vi ~/.ssh/authorized_keys  (Any editor can be used) paste the copied ssh key in destination’s server keys file.                 

6. Now, Set PermitRootLogin yes in vi /etc/ssh/sshd_config, this will allow lsyncd on the source server to login as root to the destination server to sync the files. 

7. Now to make the changed effective restart the sshd service on destination server by :

  systemctl restart sshd

8. Now to configure lsyncd file run :

vi /etc/lsyncd.conf

Add the following Lines to the config file.                          lsyncd_sync

-- User configuration file for lsyncd.
--
-- Simple example for default rsync.
--settings {
insist = true,
logfile = "/var/log/lsyncd/lsyncd.log",
statusFile = "/var/log/lsyncd/lsyncd.status",
statusInterval = 10
}
sync{
default.rsync,
 
source="/var/www/html",
target="192.168.1.16:/var/www/html",

rsync = {
archive = true,
compress = true,
checksum = true,
verbose = true,
acls = true,
rsh = "/usr/bin/ssh -F /root/.ssh -p 22 -o StrictHostKeyChecking=no"
}}

9. Start the Service and enable it at reboot

systemctl start lsyncd

systemctl enable lsyncd

10. To stop lsyncd : systemctl stop lsyncd

11. To restart lsyncd : systemctl restart lsyncd

HAPPY SYNCING!

Advertisements


Categories: Linux

Tags: , , , , , , ,

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: