April 2024
M T W T F S S
1234567
891011121314
15161718192021
22232425262728
2930  

Categories

April 2024
M T W T F S S
1234567
891011121314
15161718192021
22232425262728
2930  

Lsyncd on CentOS 7 & RHEL 7

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

Lsyncd works on Master and Slave architecture where it monitors the directory on the master server, if any changes or modification are done then lsyncd will replicate the same on its slave servers after specific interval of time.

In this article we will discuss how to install and use lsyncd on CentOS 7 & RHEL 7.

Scenario : Suppose want to sync the folder “/var/www/html” from Master server to Slave server

Master clusterserver1 IP = 192.168.1.20
Slave clusterserver2 IP = 192.168.1.21
Directory to be Sync = /var/www/html
First Enable Key based authentication between Master and Slave Server.

Login to Master server & generate the public and Private keys using ssh-keygen command.
[root@clusterserver1 html]# ssh-keygen
Generating public/private rsa key pair.
Enter file in which to save the key (/root/.ssh/id_rsa):
Created directory ‘/root/.ssh’.
Enter passphrase (empty for no passphrase):
Enter same passphrase again:
Your identification has been saved in /root/.ssh/id_rsa.
Your public key has been saved in /root/.ssh/id_rsa.pub.
The key fingerprint is:
a6:6e:8f:e8:2b:62:0c:a7:25:1f:c3:2b:74:eb:5a:33 root@clusterserver1.rmohan.com
The key’s randomart image is:
+–[ RSA 2048]—-+
| |
| |
| |
| |
| . S |
|o.*. o |
|+*.E. . |
|+o=.oo.. |
|.+o++oo.. |
+—————–+
[root@clusterserver1 html]#
ssh-copy-id -i /root/.ssh/id_rsa.pub root@192.168.1.21

root@clusterserver1 html]# ssh-keygen
Generating public/private rsa key pair.
Enter file in which to save the key (/root/.ssh/id_rsa):
Created directory ‘/root/.ssh’.
Enter passphrase (empty for no passphrase):
Enter same passphrase again:
Your identification has been saved in /root/.ssh/id_rsa.
Your public key has been saved in /root/.ssh/id_rsa.pub.
The key fingerprint is:
a6:6e:8f:e8:2b:62:0c:a7:25:1f:c3:2b:74:eb:5a:33 root@clusterserver1.rmohan.com
The key’s randomart image is:
+–[ RSA 2048]—-+
| |
| |
| |
| |
| . S |
|o.*. o |
|+*.E. . |
|+o=.oo.. |
|.+o++oo.. |
+—————–+
[root@clusterserver1 html]# ssh-copy-id -i /root/.ssh/id_rsa.pub root@192.168.1.21
The authenticity of host ‘192.168.1.21 (192.168.1.21)’ can’t be established.
ECDSA key fingerprint is 43:25:9c:32:53:18:33:a9:25:f7:cd:bb:b0:64:80:fd.
Are you sure you want to continue connecting (yes/no)? yes
/usr/bin/ssh-copy-id: INFO: attempting to log in with the new key(s), to filter out any that are already installed
/usr/bin/ssh-copy-id: INFO: 1 key(s) remain to be installed — if you are prompted now it is to install the new keys
root@192.168.1.21’s password:

Number of key(s) added: 1

Now try logging into the machine, with: “ssh ‘root@192.168.1.21′”
and check to make sure that only the key(s) you wanted were added.

[root@clusterserver1 html]# ssh 192.168.1.21
Last login: Sun Jul 10 16:26:31 2016 from 192.168.1.1
[root@clusterserver2 ~]# logout
Connection to 192.168.1.21 closed.
[root@clusterserver1 html]#
[root@clusterserver1 html]# rpm -iUvh http://dl.fedoraproject.org/pub/epel/7/x86_64/e/epel-release-7-8.noarch.rpm
Retrieving http://dl.fedoraproject.org/pub/epel/7/x86_64/e/epel-release-7-8.noarch.rpm
Preparing… ################################# [100%]
package epel-release-7-8.noarch is already installed
[root@clusterserver1 html]#

[root@clusterserver1 html]# yum install lsyncd

[root@clusterserver1 html]# cp /usr/share/doc/lsyncd-2.1.5/examples/lrsync.lua /etc/lsyncd.conf
cp: overwrite ‘/etc/lsyncd.conf’? y
[root@clusterserver1 html]#
[root@clusterserver1 html]# cat /etc/lsyncd.conf
—-
— User configuration file for lsyncd.

— Simple example for default rsync.

settings = {
logfile = “/var/log/lsyncd.log”,
statusFile = “/var/log/lsyncd.stat”,
statusInterval = 2,
}
sync{
default.rsync,
source=”/var/www/html”,
target=”192.168.1.21:/var/www/html”,
rsync={rsh =”/usr/bin/ssh -l root -i /root/.ssh/id_rsa”,}
}
[root@clusterserver1 html]#

Leave a Reply

You can use these HTML tags

<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>