Having lunch at the Gristmill in Gruene. I hope this is what heaven is like.
This just landed on my desk. It floated, then came at me suddenly.
Having a delicious Shiner Bock beer, waiting on the "New Orleans" cooking class to start at County Line. Great way to start a Friday.
This should be required reading before you buy a domain, with a quiz afterward.
This post describes how to use lsyncd as a syncing mechanism for multiple web servers’ document roots. It’s assumed you are working on CentOS 5 servers.
What is lsyncd?
From the site: Lsyncd watches a local directory trees event monitor interface (inotify). It aggregates and combines events for a few seconds and then spawns one (or more) process(es) to synchronize the changes.
Step One: Set up the file systems for syncing
Let’s say we have two web servers - web-admin and web2. The web-admin server will be the master server that pushes updates to web2. Any update to web2 will be wiped. We want to sync /var/www/html from web-admin to web2.
Step Two: Set up SSH keys between the servers
Here’s a step-by-step on this.
Step Three: Install packages
# yum install lua lua-devel rsync pkgconfig
These are needed for lsyncd. Once you have the prerequisites in place, go get lsyncd from the Google Code page and ./configure && make && make install. Fun times.
Step Four: Configure lsyncd to start on boot
Here’s an init script:
#!/bin/bash
#
# lsyncd: Starts the lsync Daemon
#
# chkconfig: 345 99 90
# description: Lsyncd uses rsync to synchronize local directories with a remote
# machine running rsyncd. Lsyncd watches multiple directories
# trees through inotify. The first step after adding the watches
# is to, rsync all directories with the remote host, and then sync
# single file buy collecting the inotify events.
# processname: lsyncd
. /etc/rc.d/init.d/functions
config="/etc/lsyncd.lau"
lsyncd="/usr/local/bin/lsyncd"
lockfile="/var/lock/subsys/lsyncd"
prog="lsyncd"
RETVAL=0
start() {
if [ -f $lockfile ]; then
echo -n $"$prog is already running: "
echo
else
echo -n $"Starting $prog: "
daemon $lsyncd $config
RETVAL=$?
echo
[ $RETVAL = 0 ] && touch $lockfile
return $RETVAL
fi
}
stop() {
echo -n $"Stopping $prog: "
killproc $lsyncd
RETVAL=$?
echo
[ $RETVAL = 0 ] && rm -f $lockfile
return $RETVAL
}
case "$1" in
start)
start
;;
stop)
stop
;;
restart)
stop
start
;;
status)
status $lsyncd
;;
*)
echo "Usage: lsyncd {start|stop|restart|status}"
exit 1
esac
exit $?
The configuration file is set to /etc/lsyncd.lau, replacing the 10.x.x.x address with your remote host IP:
settings = {
logfile = "/var/log/lsyncd/lsyncd.log",
statusFile = "/var/log/lsyncd/lsyncd-status.log",
statusInterval = 20
}
sync{
default.rsyncssh,
source="/var/www/html",
host="10.x.x.x",
targetdir="/var/www/html",
rsyncOps="-avz"
}
Next, start the service and away you go! You may want to add the lsyncd logs to logrotate. Happy syncing!