Trace: lsyncd

Lsyncd

Install required libraries:

apt-get install lsyncd
echo 'fs.inotify.max_user_watches=400000' > /etc/sysctl.d/99-lsyncd.conf
sysctl -p  /etc/sysctl.d/99-lsyncd.conf

Create the sync directories on both servers:

mkdir /home/moodle
mkdir /home/moodledata
chmod 775 /home/moodle
chmod 775 /home/moodledata

Create the user:

useradd lsyncd
mkdir /home/lsyncd
chown lsyncd:lsyncd /home/lsyncd 
usermod -aG www-data lsyncd

On server1:

su - lsyncd
ssh-keygen

On server2:

su - lsyncd
mkdir /home/lsyncd/.ssh
chmod 700 /home/lsyncd/.ssh
touch /home/lsyncd/.ssh/authorized_keys
chmod 600 /home/lsyncd/.ssh/authorized_keys

Copy key from server1 /home/lsyncd/.ssh/id_rsa.pub to server2 /home/lsyncd/.ssh/authorized_keys.

Create Lsyncd configuration on server1:

touch /etc/lsyncd.conf
touch /etc/lsyncd.exclude
chown lsyncd:lsyncd /etc/lsyncd.conf
chown lsyncd:lsyncd /etc/lsyncd.exclude
touch /var/log/lsyncd.log
touch /var/log/lsyncd-status.log
chown lsyncd:lsyncd /var/log/lsyncd.log
chown lsyncd:lsyncd /var/log/lsyncd-status.log

Content of /etc/lsyncd.conf:

settings {
   logfile = "/var/log/lsyncd.log",
   statusFile = "/var/log/lsyncd-status.log",
   statusInterval = 20,
   maxProcesses = 1
}

sync {
   default.rsyncssh,
   source="/home/moodle",
   host="[email protected]",
   excludeFrom="/etc/lsyncd.exclude",
   targetdir="/home/moodle",
   rsync = {
     archive = true,
     compress = false,
     whole_file = false
   },
   ssh = {
     port = 22
   }
}

Create a systemd unit to start automatically with the following name /etc/systemd/system/lsyncd-moodle.service

[Unit]
Description=Live Syncing (Mirror) Daemon
After=network.target

[Service]
User=lsyncd
Group=lsyncd
Restart=always
Type=simple
Nice=19
ExecStart=/usr/bin/lsyncd -nodaemon -pidfile /run/lsyncd.pid /etc/lsyncd.conf
ExecReload=/bin/kill -HUP $MAINPID
PIDFile=/run/lsyncd.pid

[Install]
WantedBy=multi-user.target

Reload systemd and enable lsyncd-moodle:

systemctl daemon-reload
systemctl enable lsyncd-moodle
systemctl start lsyncd-moodle

References

lsyncd.txt · Last modified: 2024/06/10 22:11
Public Domain Except where otherwise noted, content on this wiki is licensed under the following license: Public Domain