How to auto sync file to another server using Lsyncd on Centos 7

How to Install and Configure Lsyncd on CentOSHow to Install and Configure Lsyncd on CentOS

How to Install and Configure Lsyncd on CentOS

Lsyncd watches a local directory trees event monitor interface (inotify or fsevents).

It aggregates and combines events for a few seconds and then spawns one (or more) process(es) to synchronize the changes.

By default this is rsync.

Lsyncd is thus a light-weight live mirror solution that is comparatively easy to install not requiring new filesystems or block devices and does not hamper local filesystem performance.

Rsync+ssh is an advanced action configuration that uses a SSH to act file and directory moves directly on the target instead of re-transmitting the move destination over the wire.

Fine-grained customization can be achieved through the config file.

Custom action configs can even be written from scratch in cascading layers ranging from shell scripts to code written in the Lua language.

This way simple, powerful and flexible configurations can be achieved.

Lsyncd is open source and you can view all feature and contribute on

How to install and auto sync using Lsyncd

To install Lsyncd on Centos 7, first you need to enable EPEL Repository On CentOS 7 / RHEL 7

For CentOS/RHEL 7 Only
[root@serverdiary ~]# yum install epel-release

If command above does not work or CentOS 6 / RHEL 6 you can manually install with:

For CentOS/RHEL 7
[root@serverdiary ~]# yum install -y

For CentOS/RHEL 6
[root@serverdiary ~]# yum install -y

Then install Remi repository with command:

[root@serverdiary ~]# yum install lua lua-devel pkgconfig gcc asciidoc
[root@serverdiary ~]# yum install lsyncd

Configuration file is on /etc/lsyncd.conf

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

Master Server's IP =
Slave Server’s IP =
Directory to be sync = /var/www/html/

Enable Key based authentication between Master and Slave Server.

Login to Master server & generate the public and Private keys using ssh-keygen command.

[root@serverdiary ~]# ssh-keygen

Then the public key from Master to Slave using ssh-copy-id command

[root@linuxtechi ~]# ssh-copy-id -i /root/.ssh/ root@

First you must login from Master server to Slave server before start lsyncd, or you will get error below on lsyncd

Error: Temporary or permanent failure on startup of /var/www/html/ -> Terminating since "insist" is not set.

Example configuration of /etc/lsyncd.conf

-- User configuration file for lsyncd.
-- Simple example for default rsync, but executing moves through on the target.
-- For more examples, see /usr/share/doc/lsyncd*/examples/
 logfile = "/var/log/lsyncd/lsyncd.log",
 statusFile = "/var/log/lsyncd/lsyncd.stat",
 statusInterval = 2,
  compress = true,
  verbose = true,
  update = true,
  perms = true,
  owner = true,
  group = true,
  rsh ="/usr/bin/ssh -l root -i /root/.ssh/id_rsa",

Enable lsyncd service and start lsyncd service

[root@serverdiary ~]# systemctl enable lsyncd
[root@serverdiary ~]# systemctl start lsyncd

Check status on /var/log/lsyncd/lsyncd.log with command

[root@serverdiary ~]# tail -f /var/log/lsyncd/lsyncd.log

Example output

Sat May 30 19:22:51 2020 Normal: --- Startup ---
Sat May 30 19:22:51 2020 Normal: recursive startup rsync: /var/www/html/ ->
Sat May 30 19:22:51 2020 Normal: Startup of /var/www/html/ -> finished.
Sat May 30 19:22:53 2020 Normal: Calling rsync with filter-list of new/modified files/dirs
Sat May 30 19:22:56 2020 Normal: Finished a list after exitcode: 0