lsyncd is a handy little program that syncs data from one server to another. Using the RSYNC protocol lsyncd monitors for changes to a specific location. When changes are noticed lsyncd syncs those changes to the target server. If you have been following our guide on how to create a high availability network, lsyncd is being used instead of network-attached storage. We’re going to install lsyncd and configure lsyncd to keep our files in sync over our cluster.
SSH Keys
Your servers need to be able to ssh into each other without a password. You need to generate an SSH Key and add the key to the slave server. Decide which server to use as a master. This will be the server that syncs changes to the slave server. On the master, Create SSH Keys and add them to the slave.
Install lsyncd
We’re using Ubuntu 20.04 for the purpose of our guide. This command is run on the server that you want to send changes from. Your master. If your following our guide on H/A this would be one of our VPS servers. Install lsyncd;
apt install lsyncd
Now we want to create the required files for lsyncd to function.
mkdir /var/log/lsyncd
mkdir /etc/lsyncd
touch /var/log/lsyncd/lsyncd.log
touch /var/log/lsyncd/lsyncdstatus
Configure lsyncd
After installing lsyncd we are now going to configure it to sync data from our master to our slave. So, when any information is added to our master, this will be synced to the slave. Our master and slave will both have WordPress on them. They will connect to our Remote MySQL Database. Open up or create the /etc/lsyncd/lsyncd.conf.lua file
nano /etc/lsyncd/lsyncd.conf.lua
Inside the file specify the files we just created for logs and also specify the location of the files you want to sync. We are syncing the whole /var/www/blog.f2h.cloud folder.
settings {
logfile = "/var/log/lsyncd/lsyncd.log",
statusFile = "/var/log/lsyncd/lsyncd.status",
statusInterval = 1,
}
serverList = {
"10.10.10.1:/var/www/blog.f2h.cloud/public_html",
"10.10.10.2:/var/www/blog.f2h.cloud/public_html",
}
sourceList =
{
"/var/www/blog.f2h.cloud/public_html",
}
for _, server in ipairs( serverList ) do
for _, source in ipairs( sourceList ) do
sync{
default.rsync,
delete = 'running',
source=source,
target=server,
delay = 1,
}
end
end
So you need to edit the serverlist =, host = and sourcelist = sections. Now restart the service. As soon as you do this lsyncd will start syncing the data. Test this by adding a file to your master and that should be synced to the slave.
service lsyncd restart
service lsyncd status
So if you are following the guide on how to get High Availability using NVMe VPS Servers. You now have two backend servers, one is syncing to the other. You can install lsyncd to sync back to the master if required. In the next guide, we will set up HAProxy to load balance and active High Availability.
You might also like
More from Linux VPS Servers
How To Install phpIPAM Ubuntu and Debian Servers
phpIPAM is a great tool for managing IP address space. It's a free bit of software that will manage IPv4 …
How to configure additional IPs in a Debian 11 VPS
On Debian 11 instances, we removed the /etc/network/interfaces file and now configure interfaces using Cloud-init on boot. Discovery will send …
2 Comments
[…] How To Install Lsyncd Sync and sync data […]
[…] on how to create a High Availability network that will host websites or applications, we used lsync. It’s a quick and dirty way to sync files between multiple hosts. In this guide, we are going […]