LSYNCD instead of Inotify+rsync configuration

Source: Internet
Author: User
Tags inotify syslog rsync



1. Introduction of LSYNCD



2, LSYNCD installation



3, LSYNCD configuration instructions



4, LSYNCD synchronous test






1.LSYNCD Introduction



LSYNCD monitors the local directory tree Event monitor interface (INotify or fsevents). Through the second-level event aggregation, and then generate one (or more) processes to synchronize the changes. By default, the combination of rsync. LSYNCD Light weight mirror solution, installation does not require a new file system or block device is relatively easy, and does not hinder the performance of the local file system.



LYSNCD is actually the LUA language that encapsulates the inotify and rsync tools, uses the INotify trigger mechanism in the Linux kernel (2.6.13 and later), and then synchronizes the differences via rsync to achieve real-time results. I think its most commendable feature is the perfect solution to the problem of frequently sending file lists of files sent by inotify + rsync massive file synchronization through time delays or cumulative triggering events. In addition, its configuration is simple, LUA itself is a configuration language, readability is very strong. LSYNCD also has a variety of operating modes to choose from, local directory CP, local directory rsync, remote directory rsyncssh.





2.LSYNCD Installation



Installing LUA


# Yum Install Lua Lua-devel





Installing LSYNCD



Download: HTTPS://GITHUB.COM/AXKIBE/LSYNCD


# unzip lsyncd-master.zip 
# cd lsyncd-master
# cmake -DCMAKE_INSTALL_PREFIX=/usr/local/lsyncd
# make
# make insatll





3. Configuration file Description


settings configuration parameter description:
logfile = FILENAME // The log file
pidfile = FILENAME // logs process pid file
nodaemon = true // non-independent process runs
statusFile = FILENAME // Run status file
statusInterval = NUMBER // Interval for writing status, default is 10s
logfacility = STRING // syslog device, default user
logident = STRING // syslog identification (tag), default "lsyncd"
inotifyMode = STRING // System inotify specifies the changes to be monitored, which can be "Modify", "CloseWrite" (default) or "CloseWrite or Modify".
maxProcesses = NUMBER // The maximum number of processes that lsyncd will spawn
maxDelays = NUMBER // How many monitored events have been accumulated to activate a synchronization, even if the delay time of the delay has not yet arrived

sync Description:
lsyncd synchronization mode three modes
default.rsync
   #Use rsync synchronization to synchronize local directories and files
default.rsyncssh:
   #For ssh, the target host needs to start sshd and verify by key.
default.direct:
   # default.direct can be used directly to maintain two local directories with better performance than using default.rsync.
   Used directly at startup (like default.rsync) rsync initially synchronizes the source and target directories. The operation default.direct uses / bin / cp, / bin / rm and / bin / mv to keep incremental synchronization.
   
Exclusions:
   excludeFrom = FILENAME // Load the exclusion rule file.
   Any part of the monitoring path that matches a text will be excluded, for example / bin / foo / bar can match the rule foo
   If the rule starts with a slash /, then match all from the beginning
   If the rule ends with /, match the end of the monitoring path
   ? Matches any character, excluding /
   * Matches 0 or more characters, excluding /
   ** matches 0 or more characters and can be /
   
   exclude = LIST // load the exclusion list
   Such as:
     sync {
    default.rsync,
    source = "/ home / user / src /",
    targetdir = "/ home / user / dst /",
    exclude = {‘.bak’, ‘.tmp’}
   }
   
source: synchronization source address, use absolute path
targetdir: target address for synchronization, using absolute path
host: destination IP address
port: port, default 22, no need to add ssh
Such as: 
   sync {
   default.rsyncssh,
   source = "/ srcdir",
   host = "remotehost",
   excludeFrom = "/ etc / lsyncd.exclude",
   targetdir = "/ dstdir",
   rsync = {
     archive = true,
     compress = false,
     whole_file = false
   },
   ssh = {
     port = 1234
   }
 }





4. Configure synchronization


Ln-s/usr/local/lsyncd/etc/lsyncd.conf/etc/lsyncd.conf


To add a startup script


chmod +X/ECT/INIT.D/LSYNCD


Start:


/etc/init.d/lsyncd start
Starting lsyncd:                                           [  OK  ]


To view a process:


# ps -ef | grep lsync
root     17571     1  0 15:22 ?        00:00:00 /usr/local/lsyncd/bin/lsyncd -pidfile /var/run/lsyncd.pid /etc/lsyncd.conf
root     17577 16692  0 15:22 pts/1    00:00:00 grep lsync



Test synchronization:



192.168.1.87


192.168.1.87
# cd /data/ckl/
# mkdir list.1
vim spring
chuntian hua hui kai
ll spring 
-rw-r--r-- 1 root root 21 Jun 12 15:33 spring


View 192.168.1.88


# cd / data / ckl /
# ls -la
total 12
drwxr-xr-x 3 root root 4096 Jun 12 15:32.
drwxr-xr-x 4 root root 4096 Jun 12 15:22 ...
drwxr-xr-x 2 root root 4096 Jun 12 15:33 list.1
Filtered directories are not synchronized
# cd list.1 /
# cat spring
chuntian hua hui kai
# ll spring
-rw-r--r-- 1 root root 21 Jun 12 15:33 spring


Modify file Permissions:



192.168.1.87


chmod 755 spring 
# ll spring 
-rwxr-xr-x 1 root root 21 Jun 12 15:33 spring


192.168.1.88


# ll spring
-rw-r--r-- 1 root root 21 Jun 12 15:33 spring
The file is not synchronized because the monitoring changes set are: Modify



To view logs:


 tailf /tmp/lsyncd.log 
Sun Jun 12 15:22:05 2016 Normal: recursive startup rsync: /data/ckl/ -> 192.168.1.88:/data/ckl/ excluding
.bak
kk
Sun Jun 12 15:22:05 2016 Normal: Startup of "/data/ckl/" finished: 0
Sun Jun 12 15:32:34 2016 Normal: Rsyncing list
/list.1
Sun Jun 12 15:32:34 2016 Normal: Finished (list): 0
Sun Jun 12 15:33:04 2016 Normal: Rsyncing list
/list.1/.spring.swp
Sun Jun 12 15:33:04 2016 Normal: Deleting list
/data/ckl//list.1/.spring.swpx
Sun Jun 12 15:33:04 2016 Normal: Finished (list): 0
Sun Jun 12 15:33:04 2016 Normal: Finished (list): 0
Sun Jun 12 15:33:10 2016 Normal: Rsyncing list
/list.1/spring
Sun Jun 12 15:33:10 2016 Normal: Deleting list
/data/ckl//list.1/.spring.swp
Sun Jun 12 15:33:10 2016 Normal: Finished (list): 0
Sun Jun 12 15:33:10 2016 Normal: Finished (list): 0
Sun Jun 12 15:37:11 2016 Normal: Rsyncing list
/list.1/spring
Sun Jun 12 15:37:11 2016 Normal: Finished (list): 0





This article is from the "take a deep Breath again" blog, make sure to keep this source http://ckl893.blog.51cto.com/8827818/1788292



LSYNCD instead of Inotify+rsync configuration


Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.