On Ubuntu 14 (version 2.1.x)
Create configuration files
apt-get install lsyncd grep "CONFIG=" /etc/init.d/lsyncd
-> it should be /etc/lsyncd/lsyncd.conf.lua
mkdir -p /etc/lsyncd/conf.d/
Backup the original file and create a new conf file
mv /etc/lsyncd/lsyncd.conf.lua{,.ORIG}
cat <<'EOF' > /etc/lsyncd/lsyncd.conf.lua
-- DO NOT EDIT THIS FILE
settings {
logfile = "/var/log/lsyncd.log",
statusFile = "/var/log/lsyncd-status.log",
statusInterval = 5
}
-- conf.d style configs
package.path = "/etc/lsyncd/conf.d/?.lua;" .. package.path
local f = io.popen("ls /etc/lsyncd/conf.d/*.lua|xargs -n1 basename|sed 's/.lua//'") for mod in f:lines() do require(mod) end
-- // DO NOT EDIT THIS FILE
EOF
Create the config file for 2 web nodes called w01 and w02.
These 2 nodes have the following IPs:
10.180.3.201 w01
10.180.3.322 w02
cat <<'EOF' > /etc/lsyncd/conf.d/w0x.lua
-- w01 and w02
servers = {
"10.180.3.201",
"10.180.3.322",
}
for _, server in ipairs(servers) do
sync {
default.rsync,
source="/var/www/vhosts/",
target=server..":/var/www/vhosts/",
rsync = {
compress = true,
archive = true,
verbose = true,
rsh = "/usr/bin/ssh -p 22 -o StrictHostKeyChecking=no"
},
excludeFrom = "/etc/lsyncd/conf.d/w0x.exclusions"
}
end
EOF
Now let’s create the exclusions file. This will be the list of paths that won’t be sync’d.
cat <<'EOF' > /etc/lsyncd/conf.d/w0x.exclusions www.mytestsite.com/ EOF
NOTE! For exclusions, please remember to put the relative path, NOT the full path. In this case, it excludes www.mytestsite.com/ from /var/www/vhosts
Set up a logrotate conf file
cat > /etc/logrotate.d/lsyncd << EOF
/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
}
EOF
Troubleshoot
Test Lsyncd
$ lsyncd --nodaemon -log Exec /etc/lsyncd/lsyncd.conf.lua
Error log – inotify issue
ERROR: Terminating since out of inotify watches//Consider increasing /proc/sys/fs/inotify/max_user_watches
Temporary fix:
# echo 100000 > /proc/sys/fs/inotify/max_user_watches
Permanent fix (ALSO write sysctl.conf):
# echo 100000 > /proc/sys/fs/inotify/max_user_watches # echo "fs.inotify.max_user_watches = 100000" >> /etc/sysctl.conf