This is an example where you install Lsyncd on a CentOS master server and you sync the folder ‘data’ on a slave server with IP 10.0.0.3
First of all, your master server needs an SSH key setup AND the slave has to have it configured, to allow passwordless SSH connection
Here an article that tells you how to do it.
Configure Lsyncd
/etc/lsyncd.conf
-- comments with "--"
settings {
logfile = "/var/log/lsyncd/lsyncd.log",
statusFile = "/var/log/lsyncd/lsyncd-status.log",
statusInterval = 20
}
sync {
default.rsync,
source="/data/",
target="10.0.0.3:/data/",
rsync = {
compress = true,
archive = true,
verbose = true,
rsh = "/usr/bin/ssh -p 22 -o StrictHostKeyChecking=no"
},
-- excludeFrom = "/etc/lsyncd.exclusions"
}
Add the service and enable it
chkconfig --add lsyncd
chkconfig lsyncd on
On CentoS7 use this:
systemctl enable lsyncd.service
Logrotate
Once installed, you also need to be sure that Lsyncd logs are managed by Logrotate.
Create/update this file: /etc/logrotate.d/lsyncd
/var/log/lsyncd/*log {
missingok
notifempty
sharedscripts
postrotate
if [ -f /var/lock/lsyncd ]; then
/sbin/service lsyncd restart > /dev/null 2>/dev/null || true
fi
endscript
}
On CentOS7, you need to use sistemctl instead service command:
/var/log/lsyncd/*log {
missingok
notifempty
sharedscripts
postrotate
if [ -f /var/lock/lsyncd ]; then
/bin/systemctl restart lsyncd.service > /dev/null 2>/dev/null || true
fi
endscript
}
Test the logrotate config
You can test this using the command:
logrotate -d /etc/logrotate.d/lsyncd
For more advanced Lsyncd configuration, check this article 🙂