Dec 21

Server Replication (the easy way)

Tags:

shell> yum -y install lua lua-devel pkgconfig gcc asciidoc
shell> sudo tar zxf lsyncd-2.1.4.tar.gz
shell> cd lsyncd-2.1.4
shell> export CFLAGS=”-march=native -O2″           #sudo wouldn’t work on this one…
shell> sudo ./configure && make && make install
shell> sudo mkdir /var/log/lsyncd
shell> sudo nano /etc/init.d/lsyncd
shell> sudo nano /etc/logrotate.d/lsyncd
shell> sudo logrotate -d /etc/logrotate.d/lsyncd
MESSAGE:
reading config file /etc/logrotate.d/lsyncd
reading config info for /var/log/lsyncd/*log 
Handling 1 logs
rotating pattern: /var/log/lsyncd/*log  1048576 bytes (no old logs will be kept)
empty log files are not rotated, old logs are removed
considering log /var/log/lsyncd/*log
  log /var/log/lsyncd/*log does not exist — skipping
not running postrotate script, since no logs were rotated
shell> sudo chmod 775 /etc/init.d/lsyncd
shell> sudo chown root:root /etc/init.d/lsyncd
shell> sudo nano /etc/lsyncd.lua
shell> sudo service lsyncd start
Starting lsyncd:      [  OK  ]
CHECK YOUR WORK:
shell> cat lsyncd.log
Sun Dec 1 20:30:42 2013 Error: Terminating since out of inotify watches.
Consider increasing /proc/sys/fs/inotify/max_user_watches

shell> sudo nano /etc/sysctl.conf
# add this to the file:
fs.inotify.max_user_watches=100000

PROBLEMS ENCOUNTERED:
shell> service lsyncd start
Starting lsyncd: Error: error loading /etc/lsyncd.lua: /etc/lsyncd.lua:6: unexpected symbol near ‘#’ [FAILED]

THE FIX:
delete the line containing ‘#FIRST SLAVE’

—————————————————

/etc/init.d/lsyncd

#!/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.lua”
lsyncd=”/usr/local/bin/lsyncd”
lockfile=”/var/lock/subsys/lsyncd”
pidfile=”/var/run/lsyncd.pid”
prog=”lsyncd”
RETVAL=0

start() {
if [ -f $lockfile ]; then
echo -n $”$prog is already running: “
echo
else
echo -n $”Starting $prog: “
daemon $lsyncd -pidfile $pidfile $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 $?

—————————————————

/etc/logrotate.d/lsyncd

/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
}

—————————————————

/etc/lsyncd.lua

settings {
logfile = “/var/log/lsyncd/lsyncd.log”,
statusFile = “/var/log/lsyncd/lsyncd-status.log”,
statusInterval = 20
}
sync {
default.rsync,
source=”/var/www/”,
target=”173.31.39.207:/var/www/”,
rsync = {
compress = true,
acls = true,
verbose = true,
rsh = “/usr/bin/ssh -p 10228 -o StrictHostKeyChecking=no”
}
}

—————————————————

THE REFERENCE
https://community.rackspace.com/products/f/18/t/158

THE GOOD INSTALL

[[email protected] lsyncd-2.1.4]# ./configure && make && make install
checking for a BSD-compatible install… /usr/bin/install -c
checking whether build environment is sane… yes
checking for a thread-safe mkdir -p… /bin/mkdir -p
checking for gawk… gawk
checking whether make sets $(MAKE)… yes
checking for gcc… gcc
checking whether the C compiler works… yes
checking for C compiler default output file name… a.out
checking for suffix of executables…
checking whether we are cross compiling… no
checking for suffix of object files… o
checking whether we are using the GNU C compiler… yes
checking whether gcc accepts -g… yes
checking for gcc option to accept ISO C89… none needed
checking for style of include used by make… GNU
checking dependency style of gcc… gcc3
checking whether make sets $(MAKE)… (cached) yes
checking for a2x… /usr/bin/a2x
checking for pkg-config… /usr/bin/pkg-config
checking pkg-config is at least version 0.9.0… yes
checking for LUA52… no
checking for LUA52… no
checking for LUA52… no
checking for lua5.2… no
checking for lua52… no
checking for luac5.2… no
checking for luac52… no
checking for LUA51… no
checking for LUA51… no
checking for LUA51… no
checking for lua5.1… no
checking for lua51… no
checking for luac5.1… no
checking for luac51… no
checking for LUA… yes
checking for lua… /usr/bin/lua
checking for luac… /usr/bin/luac
checking whether Lua library was compiled with compat support… yes
checking how to run the C preprocessor… gcc -E
checking for grep that handles long lines and -e… /bin/grep
checking for egrep… /bin/grep -E
checking for ANSI C header files… yes
checking for sys/types.h… yes
checking for sys/stat.h… yes
checking for stdlib.h… yes
checking for string.h… yes
checking for memory.h… yes
checking for strings.h… yes
checking for inttypes.h… yes
checking for stdint.h… yes
checking for unistd.h… yes
checking sys/inotify.h usability… yes
checking sys/inotify.h presence… yes
checking for sys/inotify.h… yes
compiling with inotify
configure: creating ./config.status
config.status: creating Makefile
config.status: creating config.h
config.status: config.h is unchanged
config.status: executing depfiles commands
configure:
Summary:
Using Lua (unknown version)

make all-am
make[1]: Entering directory `/root/lsync_src/lsyncd-2.1.4′
gcc -DHAVE_CONFIG_H -I. -march=native -O2 -Wall -MT lsyncd.o -MD -MP -MF .deps/lsyncd.Tpo -c -o lsyncd.o lsyncd.c
mv -f .deps/lsyncd.Tpo .deps/lsyncd.Po
gcc -DHAVE_CONFIG_H -I. -march=native -O2 -Wall -MT inotify.o -MD -MP -MF .deps/inotify.Tpo -c -o inotify.o inotify.c
mv -f .deps/inotify.Tpo .deps/inotify.Po
/usr/bin/luac -o runner.out lsyncd.lua
/usr/bin/lua ./bin2carray.lua runner.out runner runner.c
gcc -DHAVE_CONFIG_H -I. -march=native -O2 -Wall -MT runner.o -MD -MP -MF .deps/runner.Tpo -c -o runner.o runner.c
mv -f .deps/runner.Tpo .deps/runner.Po
/usr/bin/luac -o defaults.out default.lua default-rsync.lua default-rsyncssh.lua default-direct.lua
/usr/bin/lua ./bin2carray.lua defaults.out defaults defaults.c
gcc -DHAVE_CONFIG_H -I. -march=native -O2 -Wall -MT defaults.o -MD -MP -MF .deps/defaults.Tpo -c -o defaults.o defaults.c
mv -f .deps/defaults.Tpo .deps/defaults.Po
gcc -march=native -O2 -Wall -o lsyncd lsyncd.o inotify.o -llua -lm -ldl runner.o defaults.o
make[1]: Leaving directory `/root/lsync_src/lsyncd-2.1.4′
make[1]: Entering directory `/root/lsync_src/lsyncd-2.1.4′
/bin/mkdir -p ‘/usr/local/bin’
/usr/bin/install -c lsyncd ‘/usr/local/bin’
/bin/mkdir -p ‘/usr/local/share/doc/lsyncd/’
/usr/bin/install -c -m 644 examples/lbash.lua examples/lecho.lua examples/lgforce.lua examples/limagemagic.lua examples/lpostcmd.lua examples/lrsync.lua examples/lrsyncssh.lua ‘/usr/local/share/doc/lsyncd/’
/bin/mkdir -p ‘/usr/local/share/man/man1’
/usr/bin/install -c -m 644 doc/lsyncd.1 ‘/usr/local/share/man/man1’
make[1]: Leaving directory `/root/lsync_src/lsyncd-2.1.4′

FOLLOWING THE INSTRUCTIONS
[[email protected] lsyncd-2.1.4]# mkdir /var/log/lsyncd
[[email protected] lsyncd-2.1.4]# nano /etc/init.d/lsyncd
[[email protected] lsyncd-2.1.4]# nano /etc/logrotate.d/lsyncd
[[email protected] lsyncd-2.1.4]# logrotate -d /etc/logrotate.d/lsyncd
reading config file /etc/logrotate.d/lsyncd
reading config info for /var/log/lsyncd/*log

Handling 1 logs

rotating pattern: /var/log/lsyncd/*log 1048576 bytes (no old logs will be kept)
empty log files are not rotated, old logs are removed
considering log /var/log/lsyncd/*log
log /var/log/lsyncd/*log does not exist — skipping
not running postrotate script, since no logs were rotated
[[email protected] lsyncd-2.1.4]# chmod 775 /etc/init.d/lsyncd
[[email protected] lsyncd-2.1.4]# chown root:root /etc/init.d/lsyncd
[[email protected] lsyncd-2.1.4]# nano /etc/lsyncd.lua
[[email protected] lsyncd-2.1.4]# service lsyncd start
Starting lsyncd: Error: error loading /etc/lsyncd.lua: /etc/lsyncd.lua:6: unexpected symbol near ‘#’
[FAILED]
[[email protected] lsyncd-2.1.4]# nano /etc/lsyncd.lua
[[email protected] lsyncd-2.1.4]# service lsyncd start
Starting lsyncd: Error: error loading /etc/lsyncd.lua: /etc/lsyncd.lua:7: unexpected symbol near ‘#’
[FAILED]
[[email protected] lsyncd-2.1.4]# nano /etc/lsyncd.lua
[[email protected] lsyncd-2.1.4]# service lsyncd start
Starting lsyncd: Error: failure getting absolute path of [162.209.106.249:/var/www/]
Error: Cannot access source directory: 162.209.106.249:/var/www/