Linux Sync server+inotify 1 for multi-sync instances

Source: Internet
Author: User
Tags inotify rsync

Linux Sync server 1 for multi-sync instances

Demand:

Online also business requirements, meaning that n machines need to maintain a directory on their respective machines, and they are all the same drops. So, after two days of thinking about it, I decided to use rsync server+inotify to solve the problem. Of course, some people will use automated tools to push, but I here this file may only change the inside of 1 small points each time, push a bedrooms trillion of things (this sentence is wrong to spray the Pro =). I decided to use rsync anyway for a variety of reasons.


Working environment:

CentOS 6.3

Rsync version 3.0.6 (for the system comes with version = = Of course compiled below will say)

Inotify-tools 3.14

-------------------

First, explain:

In fact, rsync and inotify-tools use Yum or the system comes with the can.

INotify need to be aware of whether the kernel supports: (ls/proc/sys/fs/inotify max_queued_events max_user_instances max_user_watches three files)

Rsync's compilation and installation is more than described, tar XF * * * && CD * * * &&./configure && make && make install

-------------------

Scenario Description:

I am here 1 servers (rsync+inotify) to proactively push files to n machines (rsync daemon), and I have the same n machine configuration file configuration (call password Authentication file).

-------------------

Server-side configuration:

mkdir /data/sync-servercd /data/sync-serveryum -y install inotify-tools rsync# Then write the Inotify-tools script vim sync.sh#!/bin/bash#source /etc/profile &>/dev/nullbasedir=$ (CD   ' dirname $0 ';p wd) log= "$basedir/sync.log" synclog= "$basedir/result.log" file= "$basedir/iplist"/usr/bin /inotifywait -mrq --timefmt  '%d/%m/%y %h:%m '  --format   '%t %w%f '    -e modify,delete,create,attrib,move /data/karaf-sync/ccms-build/ |while read  file dowhile read linedoecho  "$line  sync start ..."     /usr/ bin/rsync -vzrtopg --delete --progress /data/karaf-sync/ccms-build/ [email  Protected] $line::ccms --password-file=/data/karaf-sync/scripts/pwd &>>  $log      if [ $? -eq 0 ];then         echo  "' date +%f-%h:%m '   $line  was rsynced Success !!! "  &>>  $synclog         echo  "------------------ -----------------------------------------" &>>  $synclog          echo  ""  &>>  $synclog     else         echo  "' date +%f-%h:%m '   $line  was rsynced failed  !!! "  &>>  $synclog         echo  "------------------ -----------------------------------------" &>>  $synclog          echo  ""  &>>  $synclog     fi  done  <  $basedir/iplist             # I've got the relevant timing sync iplist out of the operation done
inotifywait:-r, --recursive recursive query directory. -q, --quiet, print out the monitoring event. -e, --event, specify the events to monitor, common events are move, modify, delete, create, attrib, and so on. Full Amount: (Access, modify,  attrib,  close_write,  close_nowrite, close, open,  moved_to,  moved_ From, move,  move_self,  create, delete, delete_self, unmount)--TIMEFMT: Output format of time--format: Specify details of the change file------------------------------------------------------inotify File system events that can be monitored by   include: In_access, where files are accessed in_modify, files are  writein_attrib, file attributes are modified, such as  chmod, Chown, touch  such as In_close_write, writable files are  closein_close_nowrite, non-writable files are  closein_open, files are  openin_moved_from, files are removed, such as  mvin_moved_to, files are moved, such as &NBSP;MV, Cpin_create, create new files in_delete, files are deleted, such as  rmin_delete_self, self-deletion, That is, an executable file in the execution of the deletion of its own in_move_self, self-moving, that is, an executable file in the execution of the move itself In_unmount, the host file system is  umountin_close, the file is closed, equivalent to (in_close_ Write | in_close_nowrite) In_move, the file is moved, equivalent to (in_moved_from | in_moved_to) Note: The above mentioned file also includes the directory. rsync command please search separately. 


Client Side configuration:

vim /etc/rsyncd.confuid = root        # Users running the rsync daemon gid = root         #运行RSYNC守护进程的组port  =  873           #监听端口use  chroot = no       #不使用chrootmax  connections = 100    #最大连接数, 0 is not limited to timeout  = 600        # This option allows you to override the client-specified IP timeout. This option ensures that the rsync server does not wait forever for a crashed client. The timeout unit is seconds, and 0 means there is no timeout definition, which is also the default. An ideal number for an anonymous rsync server is 600.pid  file = /var/run/rsyncd.pidlock file = /var/run/rsyncd.locklog file =  /var/log/rsyncd.log#log format --- google[ccms]path = /data/ccms-build/         #需要同步的路径comment  =  ccms dir             #名称ignore  errors                 #可以忽略一些无关的IO错误read  only =  no              list =  no                        #不允许列文件hosts  allow = 192.168.***.***/255.255.255.0         #允许的客户端auth  users = ccms                     #认证用户secrets  file = / etc/rsync.pwd        #密码文件:600vim /etc/rsync.pwdccms:********      #同server端相同chmod  600 /etc/rsync.pwd

Start process

/usr/bin/rsync--daemonecho "/usr/bin/rsync--daemon" >>/etc/init.d/rc.local


It's almost there, I'm using the script of the server before screen starts, and then I can write the files on both sides to test it.

Some other commands of the specific use, you can search, as a reference, here is no longer detailed explanation, sorry!

This article is from the "Tofu Blog" blog, make sure to keep this source http://407711169.blog.51cto.com/6616996/1536503

Related Article

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.