Ubuntu uses Rsync+inotify-tools to implement file synchronization two

Source: Internet
Author: User
Tags file handling inotify rsync

In the previous article, I talked about how to use rsync and Inotify-tools in Ubuntu to sync files between two Ubuntu servers. Now more into

One step, false with A1,a2,a3,a4 four servers, their sync folder set to/data, when any one of the machines on the changes in the file, can automatically

Sync up to the other machines. This is the subject to be discussed in this article.

First you need to set up each machine to become an rsync server, and each machine will act as a rync from the machine and run Inotify-tools. So, every machine

The device must have an rsync two key files, one as the host set the username: password format of the secret key file, the other as a machine only secret

Code of the secret key file. The IP for four machines is:

a1:192.168.1.10       
a2:192.168.1.20     
a3:192.168.1.30     
a4:192.168.1.40  

A1 's/etc/rsyncd.conf file:

# sample rsyncd.conf configuration file # GLOBAL OPTIONS #motd FILE=/ETC/MOTD log file=/var/log/rsyncd # for PID file, D
o not use/var/run/rsync.pid If # and are going to run rsync out of the init.d script.
 # The INIT.D script does its own PID file handling, # So omit the ' PID file ' line completely in.
	PID file=/var/run/rsyncd.pid syslog facility=daemon #socket options= # MODULE options [FTP] comment = Public archive Path =/data Use chroot = no # max connections=10 lock file =/var/lock/rsyncd # "The default for Read only" is yes ... re  Ad only = no list = yes uid = root gid = root # exclude = # Exclude from = # include = # include from = Auth users = Lzj Secrets file =/etc/rsyncd.secrets Strict modes = yes hosts allow = 192.168.1.20 192.168.1.30 192.168.1.40 # Host s deny = ignore errors = yes ignore nonreadable = yes transfer logging = no # log format =%t:host%h (%a)%o%f (%l b Ytes).
	Total%b bytes.
Timeout = refuse options = Checksum Dry-run	Dont compress = *.gz *.tgz *.zip *.z *.rpm *.deb *.iso *.bz2
 

A1 's/etc/rsyncd.secrets file:

Lzj:123

A1 's/etc/rsync.pass file:

123

The configuration files of the other 3 machines are different from the A1 in the configuration file host allow to the corresponding other three machines IP.

A1 's rsyn.sh file:

Src=/data
dst[0]=lzj@192.168.1.20::ftp
dst[1]=lzj@192.168.1.30::ftp
dst[2]=lzj@19. 168.1.40::ftp
 
/usr/bin/inotifywait-mr--timefmt '%d/%m/%y%h:%m '--format '%T%w%f%e '-e modify,delete,create, attrib $src | While read files does for
       		i in ${dst[@]}
		do
		rsync-vzrtopg--delete  --progress--password-file=/etc/ Rsync.pass $src $i
		echo $i
		done
exit 0

Let the rsyn.sh script run in the background:

chmod +x rsync.sh
nohup bash rsyn.sh &




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.