Lsyncd for synchronizing web servers

If you have several web servers that are load balanced together, one option to synchronize them is to use rsync + cron. But this runs the process every minute at minimum to check for changes, the good thing about Lsyncd is it uses inotify which runs rsync only when changes are detected on the files that it is monitoring. NOTE: the servers are configured already for password less ssh access.

http://lsyncd.googlecode.com/files/lsyncd-2.0.5.tar.gz

sudo apt-get install lua5.1 liblua5.1-0-dev pkg-config

extract, compile, install

./configure
make
sudo make install

My config file

lysncd.lua
settings = {
logfile = "/var/log/lsyncd.log",
statusFile = "/tmp/lsyncd.status",
delay = 5,
}
sync{
default.rsyncssh,
source="/var/www/",
host="s4",
targetdir="/var/www/",
rsyncOpts="-ap"
}

delay = wait 5 seconds before starting replication
default.rysncssh = uses rsync with ssh
source = run lsyncd here
host = the targe where you want to sync your files
targetdir = destination dir in the host
rsyncOpts = you can pass custom options to rsync


Popular Posts