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
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 |
-- 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
1 2 |
chkconfig --add lsyncd chkconfig lsyncd on |
On CentoS7 use this:
1 |
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
1 2 3 4 5 6 7 8 9 10 |
/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:
1 2 3 4 5 6 7 8 9 10 |
/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:
1 |
logrotate -d /etc/logrotate.d/lsyncd |
For more advanced Lsyncd configuration, check this article 🙂