Quote:
Originally Posted by vasile002
right, anyway nothing bad can happen
|
hmmmm .... ok.
here's what i've done. keep in mind that i'm still testing, and i'm completely unsure of its robustness.
i have 3 servers. one in Jakarta, one in Bali, and one in Batam. they are all connected to the internet on flaky, consumer-grade 3Mbps connections.
i'm assuming use of an Ubuntu server here; you rpm heads should be smart enough to make the relevant adjustments.
also, if you want to use lsyncd -ryncssh, then you will need version 2 or higher, not the 1.x provided on the ubuntu repository. this means getting source code and compiling it yourself. don't panic. this is fairly painless if you have installed all the required dependencies, and this is done within the installation script below.
as root, install the following on each of the servers. (i put this in a file called installlsync.sh.)
Code:
#!/bin/bash
# make sure you have all the files required to compile from source
apt-get -y install build-essential gcc lua5.1 liblua5.1-dev liblua5.1-0 checkinstall
# make sure you have inotify installed.
apt-get -y install inotify-tools
# this is the standard place for compiling programs from source.
mkdir /usr/local/src/lsyncd
cd /usr/local/src/lsyncd
# download newest lsyncd from lsyncd.googlecode.com (lsyncd-2.0.5.tar.gz)
# you may wish to check for newer versions. i'm assuming 2.0.5 here.
wget http://lsyncd.googlecode.com/files/lsyncd-2.0.5.tar.gz
# unpack the code
tar xzvf lsyncd-2.0.5.tar.gz
cd lsyncd-2.0.5
./configure
make
make install
checkinstall -y
# note: if you are not using a 64bit server, then deb file
# below may have a different name
dpkg -i lsyncd_2.0.5-1_amd64.deb
# remember copy the executable to somewhere useful!
cp lsyncd /usr/bin
once successfully installed, you then need to get lsyncd running on all three servers.
the FIRST thing you MUST do is to manually synchronise all the folders on each of the servers. if you don't do this first, you WILL lose files. trust me. i know these things.
so do something like this from your "master" serverJakarta:
Code:
cd /myfolder
rsync -avz . root@serverBali:/myfolder
rsync -avz . root@serverBatam:/myfolder
once everything is 100% in sync, i install this little script on each of the servers to automate/standardise the lsync setup on each machine: (call this script lsyncdgen.sh)
Code:
#!/bin/bash
# get rid of any instances of lsyncd currently running
# (this assumes there is no activity on your system when you run this!)
killall lsyncd
# nominate a working directory where you are going to put this script
# and the config file this script generates
wdir=/root/syncfile
# get the hostname of the server this script is running on
thishost=$(cat /etc/hostname)
# now we want to figure out which server we wish to synchronise...
# we have to go around in a circle to avoid deadly embraces ...
if [[ "$thishost" == "serverJakarta" ]]; then
dst=serverBali
elif [[ "$thishost" == "serverBali" ]]; then
dst=serverBatam
elif [[ "$thishost" == "serverBatam" ]]; then
dst=serverJakarta
else
# you messed up!
echo "$thishost not on my list!"
exit 1
fi
# let's make the lua config file for this server ...
echo "-- lsyncd config file for this server ($thishost)" > $wdir/myconfig.lua
# i'm setting up the log files for somewhere where i can find them
echo 'settings = {
logfile="/tmp/lsyncd.log", statusFile="/tmp/lsyncd.status",
}' >> $wdir/myconfig.lua
# these are the rsync options you probably need:
opts="-aluz"
dir=/myfolder/
echo "sync{default.rsyncssh, source=\"$dir\", host=\"$dst\", targetdir=\"$dir\", rsyncOpts=\"$opts\", excludeFrom=\"$wdir/exclude\"}" >> $wdir
echo "" >> $wdir/myconfig.lua
#for each additional folder you want synchronised, do this code:
#---
dir=/myfolder2/
echo "sync{default.rsyncssh, source=\"$dir\", host=\"$dst\", targetdir=\"$dir\", rsyncOpts=\"$opts\", excludeFrom=\"$wdir/exclude\"}" >> $wdir
echo "" >> $wdir/myconfig.lua
#---
# run lsyncd!
lsyncd $wdir/myconfig.lua &
now you almost certainly want to exclude certain files from being synchronised. make a file called "exclude" and place in the same directory as the above script:
that's it. keep an eye on the log files to see what is going on. i've only been using this a few hours, so have not fully tested it. i would be grateful for any input from anyone who has more experience using lsyncd!
NB: remember to ensure that your system can autologin to the destination server using ssh. use this script if this stuff confuses you. press Enter when/if you are presented with a passphrase prompt:
Code:
#!/bin/bash
# sshautologin.sh
if [ -z $1 ]; then
echo "require destination username and servername"
exit 1
fi
if [ -z $2 ]; then
echo "require destination servername"
exit 1
fi
cd ~
# if you already have a key then don't generate it again
if [ ! -f ~/.ssh/id_dsa.pub ]; then
# no key! generate one!
ssh-keygen -t dsa
chmod 700 ~/.ssh
fi
cat ~/.ssh/id_dsa.pub | ssh -l $1 $2 'cat >> ~/.ssh/authorized_keys'