How to Install and Configure LsyncD on AlmaLinux

Posted on by Mohammed Noufal | Updated:
Reading Time: 6 minutes

LsyncD (Live Syncing Daemon) is used to sync or replicate both files and directories locally and remotely after a specific interval of time. LsyncD uses rsync and ssh in the backend. 

LsyncD works on Master and Slave architecture. It will monitor the directory on the master server. If any changes or modifications occur on the Master server, LsyncD will replicate them on its slave servers after a specific interval of time. These frequent directory updates and synchronization actions ensure that the master and slave directories remain identical. 

In this article, we will discuss how to install and configure LsyncD on AlmaLinux servers.

Requirements 

  • Master server and Slave server.
  • Operating system and version: AlmaLinux OS 8.5.
  • Processor: 1.1 GHz.
  • RAM: Minimum 1 GB but recommended 2 GB.
  • Disk Space: Minimum 20 GB but recommended 40 GB.
  • Architecture: 64-bit.
  • Software: LsyncD and SSHD.
  • Root access to your Linux system or via the sudo command.

How to Install and Configure LsyncD on AlmaLinux

To proceed with the installation and configuration, you need two servers that have AlmaLinux installed - one server for Master Server (IP: 192.168.1.20 in this example) and one server for Slave Server (IP: 192.168.1.21 in this example).

Step 1: Enable Key-based Authentication Between Master and Slave Server.

From the Master server, generate the public and private keys using the ssh-keygen command.

Here is the output.

[root@noufserver-master ~]# ssh-keygen
Generating public/private rsa key pair.
Enter file in which to save the key (/root/.ssh/id_rsa): 
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:
SHA256:IU8Zc98zsgAVIlSCgchSavTv+kkUyC53LWo/LAOPV6c root@noufserver-master
The key's randomart image is:
+---[RSA 3072]----+
|.+...++.*.+.     |
|+o+ o  o B . .   |
|o. + .. + . o +  |
|. . . o+ . . o o |
| . o = .S   .    |
| .o =...         |
|  +oooo          |
| ..=+E.          |
|  ..++.          |
+----[SHA256]-----+
[root@noufserver-master ~]#

Copy the public key using the ssh-copy-id command to the slave server.

[root@noufserver-master ~]# ssh-copy-id -i /root/.ssh/id_rsa.pub root@192.168.1.21 
/usr/bin/ssh-copy-id: INFO: Source of key(s) to be installed: "/root/.ssh/id_rsa.pub"

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.

Step 2: Install LsyncD Package on the AlmaLinux Master Server

Install the lsyncd dependency packages in AlmaLinux using the following yum command.

[root@noufserver-master ~]# yum install lua pkgconfig gcc asciidoc

Here is the output.

[root@noufserver-master ~]# yum install lua pkgconfig gcc asciidoc
Last metadata expiration check: 0:02:29 ago on Sun 06 Mar 2022 04:37:19 AM UTC.
Dependencies resolved.
=========================================================================================================================================================================
 Package                                                Architecture             Version                                               Repository                   Size
=========================================================================================================================================================================
Installing:
 asciidoc                                               noarch                   8.6.10-0.5.20180627gitf7c2274.el8                     appstream                   216 k
 gcc                                                    x86_64                   8.5.0-4.el8_5.alma                                    appstream                    23 M
 lua                                                    x86_64                   5.3.4-12.el8                                          appstream                   191 k
 pkgconf-pkg-config                                     x86_64                   1.4.2-1.el8                                           baseos                       15 k

—----
—----

Installed:
  adobe-mappings-cmap-20171205-3.el8.noarch              adobe-mappings-cmap-deprecated-20171205-3.el8.noarch        adobe-mappings-pdf-20180407-1.el8.noarch           
  asciidoc-8.6.10-0.5.20180627gitf7c2274.el8.noarch      atk-2.28.1-1.el8.x86_64                                     avahi-libs-0.7-20.el8.x86_64                       
  binutils-2.30-108.el8_5.1.x86_64                       boost-regex-1.66.0-10.el8.x86_64                            cairo-1.15.12-3.el8.x86_64                         
  cpp-8.5.0-4.el8_5.alma.x86_64                          ctags-5.8-22.el8.x86_64                                     cups-libs-1:2.2.6-40.el8.x86_64                    
  docbook-dtds-1.0-69.el8.noarch                         docbook-style-xsl-1.79.2-9.el8.noarch                       emacs-filesystem-1:26.1-7.el8.noarch               
  fontconfig-2.13.1-4.el8.x86_64                         fontpackages-filesystem-1.44-22.el8.noarch                  fribidi-1.0.4-8.el8.x86_64                         
  gcc-8.5.0-4.el8_5.alma.x86_64                          gd-2.2.5-7.el8.x86_64                                       gdk-pixbuf2-2.36.12-5.el8.x86_64                   
  gdk-pixbuf2-modules-2.36.12-5.el8.x86_64               glibc-devel-2.28-164.el8.x86_64                             glibc-headers-2.28-164.el8.x86_64                  
  google-droid-sans-fonts-20120715-13.el8.noarch         graphite2-1.3.10-10.el8.x86_64                              graphviz-2.40.1-43.el8.x86_64                      
  gtk-update-icon-cache-3.22.30-8.el8.x86_64             gtk2-2.24.32-5.el8.x86_64                                   harfbuzz-1.7.5-3.el8.x86_64                        
  hicolor-icon-theme-0.17-2.el8.noarch                   isl-0.16.1-6.el8.x86_64                                     jasper-libs-2.0.14-5.el8.x86_64                    
  jbig2dec-libs-0.16-1.el8.x86_64                        jbigkit-libs-2.1-14.el8.x86_64                              kernel-headers-4.18.0-348.12.2.el8_5.x86_64        
  lcms2-2.9-2.el8.x86_64                                 libICE-1.0.9-15.el8.x86_64                                  libSM-1.2.3-1.el8.x86_64                           
  libX11-1.6.8-5.el8.x86_64                              libX11-common-1.6.8-5.el8.noarch                            libXau-1.0.9-3.el8.x86_64                          
  libXaw-1.0.13-10.el8.x86_64                            libXcomposite-0.4.4-14.el8.x86_64                           libXcursor-1.1.15-3.el8.x86_64                     
  libXdamage-1.1.4-14.el8.x86_64                         libXext-1.3.4-1.el8.x86_64                                  libXfixes-5.0.3-7.el8.x86_64                       
  libXft-2.3.3-1.el8.x86_64                              libXi-1.7.10-1.el8.x86_64                                   libXinerama-1.1.4-1.el8.x86_64                     
  libXmu-1.1.3-1.el8.x86_64                              libXpm-3.5.12-8.el8.x86_64                                  libXrandr-1.5.2-1.el8.x86_64                       
  libXrender-0.9.10-7.el8.x86_64                         libXt-1.1.5-12.el8.x86_64                                   libXxf86misc-1.0.4-1.el8.x86_64                    
  libXxf86vm-1.1.4-9.el8.x86_64                          libdatrie-0.2.9-7.el8.x86_64                                libfontenc-1.1.3-8.el8.x86_64                      
  libgs-9.27-1.el8.x86_64                                libicu-60.3-2.el8_1.x86_64                                  libidn-1.34-5.el8.x86_64                           
  libijs-0.35-5.el8.x86_64                               libjpeg-turbo-1.5.3-12.el8.x86_64                           libmcpp-2.7.2-20.el8.x86_64                        
  libmpc-1.1.0-9.1.el8.x86_64                            libpaper-1.1.24-22.el8.x86_64                               libpkgconf-1.4.2-1.el8.x86_64                      
  librsvg2-2.42.7-4.el8.x86_64                           libthai-0.1.27-2.el8.x86_64                                 libtiff-4.0.9-20.el8.x86_64                        
  libtool-ltdl-2.4.6-25.el8.x86_64                       libwebp-1.0.0-5.el8.x86_64                                  libxcb-1.13.1-1.el8.x86_64                         
  libxcrypt-devel-4.1.1-6.el8.x86_64                     libxslt-1.1.32-6.el8.x86_64                                 lua-5.3.4-12.el8.x86_64                            
  mcpp-2.7.2-20.el8.x86_64                               openjpeg2-2.4.0-4.el8.x86_64                                pango-1.42.4-8.el8.x86_64                          
  pixman-0.38.4-1.el8.x86_64                             pkgconf-1.4.2-1.el8.x86_64                                  pkgconf-m4-1.4.2-1.el8.noarch                      
  pkgconf-pkg-config-1.4.2-1.el8.x86_64                  sgml-common-0.6.3-50.el8.noarch                             source-highlight-3.1.8-17.el8.x86_64               
  urw-base35-bookman-fonts-20170801-10.el8.noarch        urw-base35-c059-fonts-20170801-10.el8.noarch                urw-base35-d050000l-fonts-20170801-10.el8.noarch   
  urw-base35-fonts-20170801-10.el8.noarch                urw-base35-fonts-common-20170801-10.el8.noarch              urw-base35-gothic-fonts-20170801-10.el8.noarch     
  urw-base35-nimbus-mono-ps-fonts-20170801-10.el8.noarch urw-base35-nimbus-roman-fonts-20170801-10.el8.noarch        urw-base35-nimbus-sans-fonts-20170801-10.el8.noarch
  urw-base35-p052-fonts-20170801-10.el8.noarch           urw-base35-standard-symbols-ps-fonts-20170801-10.el8.noarch urw-base35-z003-fonts-20170801-10.el8.noarch       
  vim-filesystem-2:8.0.1763-16.el8_5.4.noarch            xml-common-0.6.3-50.el8.noarch                              xorg-x11-font-utils-1:7.5-41.el8.x86_64            
  xorg-x11-fonts-ISO8859-1-100dpi-7.5-19.el8.noarch      xorg-x11-server-utils-7.7-27.el8.x86_64                    

Complete!

Before you install the lsyncd package using the yum command, you will need to first install the EPEL repository configuration package using the following command as the lsyncd package is not available in the default repository.

[root@noufserver-master ~]# yum install -y epel-release

Here is the output.

[root@noufserver-master ~]# yum install -y epel-release
Last metadata expiration check: 0:06:06 ago on Sun 06 Mar 2022 04:37:19 AM UTC.
Dependencies resolved.
=========================================================================================================================================================================
 Package                                     Architecture                          Version                                   Repository                             Size
=========================================================================================================================================================================
Installing:
 epel-release                                noarch                                8-10.el8                                  extras                                 22 k

Transaction Summary
=========================================================================================================================================================================
Install  1 Package

Total download size: 22 k
Installed size: 32 k
Downloading Packages:
epel-release-8-10.el8.noarch.rpm                                                                                                         269 kB/s |  22 kB     00:00    
-------------------------------------------------------------------------------------------------------------------------------------------------------------------------
Total                                                                                                                                    163 kB/s |  22 kB     00:00     
Running transaction check
Transaction check succeeded.
Running transaction test
Transaction test succeeded.
Running transaction
  Preparing        :                                                                                                                                                 1/1 
  Installing       : epel-release-8-10.el8.noarch                                                                                                                    1/1 
  Running scriptlet: epel-release-8-10.el8.noarch                                                                                                                    1/1 
  Verifying        : epel-release-8-10.el8.noarch                                                                                                                    1/1 
Installed:
  epel-release-8-10.el8.noarch    
                                                                                                                                       
Complete!

To install the lsyncd package, run the following command.

[root@noufserver-master ~]# yum install lsyncd

Here is the output.

[root@noufserver-master ~]# yum install lsyncd
Extra Packages for Enterprise Linux 8 - x86_64                                                                                            16 MB/s |  11 MB     00:00    
Extra Packages for Enterprise Linux Modular 8 - x86_64                                                                                   5.7 MB/s | 979 kB     00:00    
Dependencies resolved.
=========================================================================================================================================================================
 Package                                Architecture                           Version                                        Repository                            Size
=========================================================================================================================================================================
Installing:
 lsyncd                                 x86_64                                 2.2.2-9.el8                                    epel                                  86 k

Transaction Summary
=========================================================================================================================================================================
Install  1 Package

Total download size: 86 k
Installed size: 205 k
Is this ok [y/N]: y
Downloading Packages:
lsyncd-2.2.2-9.el8.x86_64.rpm                                                                                                            1.4 MB/s |  86 kB     00:00    
-------------------------------------------------------------------------------------------------------------------------------------------------------------------------
Total                                                                                                                                    691 kB/s |  86 kB     00:00     
Extra Packages for Enterprise Linux 8 - x86_64                                                                                           1.6 MB/s | 1.6 kB     00:00    
Importing GPG key 0x2F86D6A1:
 Userid     : "Fedora EPEL (8) <epel@fedoraproject.org>"
 Fingerprint: 94E2 79EB 8D8F 25B2 1810 ADF1 21EA 45AB 2F86 D6A1
 From       : /etc/pki/rpm-gpg/RPM-GPG-KEY-EPEL-8
Is this ok [y/N]: y
Key imported successfully
Running transaction check
Transaction check succeeded.
Running transaction test
Transaction test succeeded.
Running transaction
  Preparing        :                                                                                                                                                 1/1 
  Installing       : lsyncd-2.2.2-9.el8.x86_64                                                                                                                       1/1 
  Running scriptlet: lsyncd-2.2.2-9.el8.x86_64                                                                                                                       1/1 
  Verifying        : lsyncd-2.2.2-9.el8.x86_64                                                                                                                       1/1 

Installed:
  lsyncd-2.2.2-9.el8.x86_64                                                                                                                                              

Complete!

Step 3: Synchronize Local Directories with Remote Using LsyncD

Create a source directory on the master server with this command.

[root@noufserver-master ~]# mkdir master-lsyncd

You can add some files to the source directory using the following command.

[root@noufserver-master ~]# sudo touch master-lsyncd/file{1..25}

Here is the output.

[root@noufserver-master master-lsyncd]# ll
total 0
-rw-r--r--. 1 root root 0 Mar  6 05:07 file1
-rw-r--r--. 1 root root 0 Mar  6 05:07 file10
-rw-r--r--. 1 root root 0 Mar  6 05:07 file11
-rw-r--r--. 1 root root 0 Mar  6 05:07 file12
-rw-r--r--. 1 root root 0 Mar  6 05:07 file13
-rw-r--r--. 1 root root 0 Mar  6 05:07 file14
-rw-r--r--. 1 root root 0 Mar  6 05:07 file15
-rw-r--r--. 1 root root 0 Mar  6 05:07 file16
-rw-r--r--. 1 root root 0 Mar  6 05:07 file17
-rw-r--r--. 1 root root 0 Mar  6 05:07 file18
-rw-r--r--. 1 root root 0 Mar  6 05:07 file19
-rw-r--r--. 1 root root 0 Mar  6 05:07 file2
-rw-r--r--. 1 root root 0 Mar  6 05:07 file20
-rw-r--r--. 1 root root 0 Mar  6 05:07 file21
-rw-r--r--. 1 root root 0 Mar  6 05:07 file22
-rw-r--r--. 1 root root 0 Mar  6 05:07 file23
-rw-r--r--. 1 root root 0 Mar  6 05:07 file24
-rw-r--r--. 1 root root 0 Mar  6 05:07 file25
-rw-r--r--. 1 root root 0 Mar  6 05:07 file3
-rw-r--r--. 1 root root 0 Mar  6 05:07 file4
-rw-r--r--. 1 root root 0 Mar  6 05:07 file5
-rw-r--r--. 1 root root 0 Mar  6 05:07 file6
-rw-r--r--. 1 root root 0 Mar  6 05:07 file7
-rw-r--r--. 1 root root 0 Mar  6 05:07 file8
-rw-r--r--. 1 root root 0 Mar  6 05:07 file9

Create a target directory on the slave server.

[root@noufserver-slave ~]# mkdir slave-lsyncd

To set up the LsyncD configuration file,copy the sample configuration to /etc/lsyncd.conf.

[root@noufserver-master ~]# cp /usr/share/doc/lsyncd/examples/lrsync.lua /etc/lsyncd.conf

Add the following lines to the configuration file /etc/lsyncd.conf.

[root@noufserver-master master-lsyncd]# 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="/root/master-lsyncd",
 target="192.168.1.21:/root/slave-lsyncd",
 rsync={rsh ="/usr/bin/ssh -l root -i /root/.ssh/id_rsa",}
}

Step 4: Start the LsyncD Service and Enable at Reboot

To start the LsyncD service, you can run the following command.

[root@noufserver-master ~]# systemctl start lsyncd

To enable LsyncD at reboot, you can run the following command.

[root@noufserver-master ~]# systemctl enable lsyncd

Here is the output.

[root@noufserver-master ~]# systemctl start lsyncd
[root@noufserver-master ~]# systemctl enable lsyncd
Created symlink /etc/systemd/system/multi-user.target.wants/lsyncd.service → /usr/lib/systemd/system/lsyncd.service.
[root@noufserver-master ~]# systemctl status lsyncd
● lsyncd.service - Live Syncing (Mirror) Daemon
   Loaded: loaded (/usr/lib/systemd/system/lsyncd.service; enabled; vendor preset: disabled)
   Active: active (running) since Sun 2022-03-06 04:58:17 UTC; 3s ago
 Main PID: 10950 (lsyncd)
    Tasks: 1 (limit: 5834)
   Memory: 1.8M
   CGroup: /system.slice/lsyncd.service
           └─10950 /usr/bin/lsyncd -nodaemon /etc/lsyncd.conf

Mar 06 04:58:17 noufserver-master systemd[1]: Started Live Syncing (Mirror) Daemon.

Step 5: Analyze the Replication and Logs Report

In this article, we used the root user for syncing data. You can change the user name per your requirement. 

Using the LsyncD log file /var/log/lsyncd.log, you can find whether the replication is completed or not.

[root@noufserver-master ~]# tail -50 /var/log/lsyncd.log

Here is the output.

[root@noufserver-master ~]# tail -50 /var/log/lsyncd.log
Sun Mar  6 04:58:17 2022 Normal: --- Startup ---
Sun Mar  6 04:58:17 2022 Normal: recursive startup rsync: /root/master-lsyncd/ -> 192.168.1.21:/root/slave-lsyncd/
Sun Mar  6 04:58:17 2022 Normal: Startup of /root/master-lsyncd/ -> 192.168.1.21:/root/slave-lsyncd/ finished.
Sun Mar  6 05:08:01 2022 Normal: Calling rsync with filter-list of new/modified files/dirs
/file1
/file2
/file3
/file4
/file5
/file6
/file7
/file8
/file9
/file10
/file11
/file12
/file13
/file14
/file15
/file16
/file17
/file18
/file19
/file20
/file21
/file22
/file23
/file24
/file25
Sun Mar  6 05:08:01 2022 Normal: Finished a list after exitcode: 23
Sun Mar  6 05:09:09 2022 Normal: --- TERM signal, fading ---
Sun Mar  6 05:09:09 2022 Normal: --- Startup ---
Sun Mar  6 05:09:09 2022 Normal: recursive startup rsync: /root/master-lsyncd/ -> 192.168.1.21:/root/slave-lsyncd/
Sun Mar  6 05:09:09 2022 Normal: Startup of /root/master-lsyncd/ -> 192.168.1.21:/root/slave-lsyncd/ finished.

You can view the LsyncD status report using the stat file /var/log/lsyncd.stat.

[root@noufserver-master lsyncd]# cat /var/log/lsyncd.stat

Here is the output.

[root@noufserver-master ~]# cat /var/log/lsyncd.stat
Lsyncd status report at Sun Mar  6 05:09:11 2022

Sync1 source=/root/master-lsyncd/
There are 0 delays
Excluding:
  nothing.

Inotify watching 1 directories
  1: /root/master-lsyncd/

Wrapping Up

If you are looking for a server to install and configure LsyncD on Almalinux or if you are uncomfortable with performing any of the steps outlined above, Liquid Web has what you need. Our Support Teams are filled with experienced Linux technicians and talented system administrators who have intimate knowledge of multiple web hosting technologies, especially those discussed in this article.

We offer Dedicated Server and VPS Hosting options. In addition, our skilled team provides 24/7/365 support and monitoring services so that you can focus on your websites. Contact our team today to learn more.

Avatar for Mohammed Noufal

About the Author: Mohammed Noufal

Mohammed Noufal is a B.Tech graduate with a decade of experience in server administration and web hosting. He is a father to two daughters and finds fulfillment in their growth. In his free time, he enjoys blogging, sharing experiences, and listening to music. With a strong technical background, family commitment, and creative outlets, he represents a well-rounded life journey.

Latest Articles

How to use kill commands in Linux

Read Article

Change cPanel password from WebHost Manager (WHM)

Read Article

Change cPanel password from WebHost Manager (WHM)

Read Article

Change cPanel password from WebHost Manager (WHM)

Read Article

Change the root password in WebHost Manager (WHM)

Read Article