Lsyncd stands for “Live Syncing Daemon“, lsyncd is used to sync or replicate files and directories locally and remotely after a specific time of interval. Lsyncd uses Rsync and ssh in the the backend.
In this quick tutorial we are going to install and configure Lsyncd on CentOS 7 to to sync a directory remotly to another server.
Enviroment:
– Server01.yallalabs.com: 192.168.1.13
– Server02.yallalabs.com: 192.168.1.14
– Directory to be Sync : “/var/www/html”
2.Step Key based authentication Configuration
-Login to Master server & generate the public and Private keys using the following command:
[root@server01 ~]# ssh-keygen -t rsa
– Copy the public key using ssh-copy-id command to the slave server:
[root@server01 ~]# ssh-copy-id -i /root/.ssh/id_rsa.pub [email protected]
2.Step Installation Lsyncd
[root@server01 ~]# yum install epel-release [root@server01 ~]# yum install lsyncd -y
3.Step Lsyncd Configuration
-Open the /etc/lsyncd.conf file and modify it like this:
---- -- User configuration file for lsyncd. -- -- Simple example for default rsync. -- settings { statusFile = "/tmp/lsyncd.stat", statusInterval = 1, } sync { default.rsync, source="/var/www/html", target="192.168.1.14:/var/www/html", rsync={rsh ="/usr/bin/ssh -l root -i /root/.ssh/id_rsa",} }
– Start and enable the lsyncd service using the following commands:
[root@server01 ~]# systemctl enable lsyncd [root@server01 ~]# systemctl start lsyncd
– Finally check the lsyncd status Report to control the synchronization and the replication of the directoy
[root@server01 ~]# tail -f 10 /var/log/lsyncd.stat tail: cannot open ‘10’ for reading: No such file or directory ==> /var/log/lsyncd.stat <== Excluding: nothing. Inotify watching 5 directories 1: /var/www/html/ 2: /var/www/html/yallalabs.com/ 3: /var/www/html/yallalabs.com/public_html/ 4: /var/www/html/yallalabs.info/ 5: /var/www/html/yallalabs.info/public_html/
We hope this tutorial was enough Helpful. If you need more information, or have any questions, just comment below and we will be glad to assist you!
PS. If you like this post please share it with your friends on the social networks using the buttons below.Thanks.
4 comments
thank you it works perfectelly like you explained
Hi Samty,
We are so glad that worked properly. We will appreciate a lot if you subscribe on our YouTube channel . Thanks in advance.
thank a lot of it works perfectelly like you have explained
Normal: recursive startup rsync: /var/www/xyz/ -> 13.21.25.22:/root/test/
Mon Sep 24 18:09:05 2018 Normal: Retrying startup of /var/www/xyz/ -> 13.21.25.22:/root/test/: 255