lsyncd live synchronization

Centos 6.5
yum -y install lua lua-devel pkgconfig gcc asciidoc

Important : Be sure to manually check the destination directory on the slave server. If you have NFS or CloudFuse mounts, these could end up wiped by the lsync process.

Note : Lsyncd version 2.0.4 has a known issue with permissions, see the following bug reports. Always make sure you install either 2.0.7 (stable) or 2.1.4+ (latest)

yum install lsyncd    --as of 2014/june it will install lsyncd 2.1.4

Check SELINUX and set to permissive
+++++++++++++++++++++++++++++++++++++++++++++++++
for yum installed
+++++++++++++++++++++++++++++++++++++++++++++++++++
# cat /etc/sysconfig/lsyncd 
# Keep the space there for systemd. Don't nest variables without
# changing the systemd service file to use: /usr/bin/sh -c 'eval XXXX'

LSYNCD_OPTIONS="-pidfile /var/run/lsyncd.pid /etc/lsyncd.conf"

#LSYNCD_OPTIONS=" "
 
                                                                             
 [root@www ~]#
cp /usr/share/doc/lsyncd-2.1.4/examples/lrsync.lua  /etc/lsyncd.conf

root@web02 [/etc]# cat /etc/lsyncd.conf 
settings = {
 statusFile = "/tmp/lsyncd.stat",
 statusInterval = 1,
}
sync{
 default.rsync,
 source="/home/",
 target="172.69.2.52:/home/",
 excludeFrom="/etc/excludelsync",
 rsync = {
compress = true,
acls = true,
verbose = true,
owner = true,
group = true,
perms = true,
rsh = "/usr/bin/ssh -p 22 -o StrictHostKeyChecking=no"
        }
}
sync{
        default.rsync,
        source="/etc/httpd/",
        target="172.69.2.52:/etc/httpd/",
        excludeFrom="/etc/excludelsync",
        rsync = {
compress = true,
acls = true,
verbose = true,
owner = true,
group = true,
perms = true,
rsh = "/usr/bin/ssh -p 22 -o StrictHostKeyChecking=no"
        }
}
 
cat /etc/excludelsync 
*.log
.cp*
logs
 
                                                                           
 
Ubuntu 
sudo apt-get update
sudo apt-get install lsyncd
 
ls /usr/share/doc/lsyncd/example  ...refer to some files for example
 
use file =>lrsync.lua
 
Local Transfer
 
sudo mkdir /var/log/lsyncd
touch /var/log/lsyncd/lsyncd.{log,status}
 
sudo mkdir /etc/lsyncd
 
sudo nano /etc/lsyncd/lsyncd.conf.lua 

settings = {
 logfile = "/var/log/lsyncd/lsyncd.log",
 statusFile = "/var/log/lsyncd/lsyncd.status"
}
sync {
 default.rsync,
 source = "/source/to/copy",
 target = "/dest",
 ##rsyncOpts = {"rsync option1", "rsync option2", "rsync option3"}
}

For remote(use public key passwordless login for master to slave)
=================
settings = {
        logfile = "/var/log/lsyncd/lsyncd.log",
        statusFile = "/var/log/lsyncd/lsyncd.status"
}

sync {
        default.rsyncssh,
        source = "/source/to/copy",
        host = "remote_mirror_ip_address",
        targetdir = "/remotesync"
}
==========================Example config=================================
settings{
 logfile = "/tmp/lsyncd.log",
 statusFile = "/tmp/lsyncd.stat",
 statusInterval = 2,
}
sync{
 default.rsync,
 source="/home/",
 target="172.69.2.52:/home/",
 rsync = {
binary = "/usr/bin/rsync",
compress = true,
acls = true,
verbose = true,
rsh = "/usr/bin/ssh -p 22 -o StrictHostKeyChecking=no"
        }
}
sync{
        default.rsync,
        source="/etc/httpd/",
        target="172.69.2.52:/etc/httpd/",
        rsync = {
binary = "/usr/bin/rsync",
compress = true,
acls = true,
rsh = "/usr/bin/ssh -p 22 -o StrictHostKeyChecking=no"        
 }
}
sync{
        default.rsync,
        source="/test11/",
        target = "root@172.69.2.52:/test11/",
        rsync = {
binary = "/usr/bin/rsync",
compress = true,
acls = true,
rsh = "/usr/bin/ssh -p 22 -o StrictHostKeyChecking=no"
}
}  

=============lsyncd Error: Terminating since out of inotify watches=============
 
# pwd
/proc/sys/fs/inotify
root@web01 [/proc/sys/fs/inotify]# ls
./  ../  max_queued_events  max_user_instances  max_user_watches 
#bydefault value in max_user_watches is = 8192 
#echo 65535 > /proc/sys/fs/inotify/max_user_watches
# cat /proc/sys/fs/inotify/max_user_watches          
65536 
To make the change permanent, edit the file /etc/sysctl.conf and add this line to the end of the file:
fs.inotify.max_user_watches=65535
If this server is a VPS and it is running in a OpenVZ container then you are NOT allowed to modify any kernel parameter of that container. and you will get below error
root@vps01 [/proc/sys/fs/inotify]# sysctl -w fs.inotify.max_user_watches=65535 
error: permission denied on key 'fs.inotify.max_user_watches'
change it from host

No comments:

Post a Comment