Rsync+inotify-tool of multiple Web server code synchronization

Source: Internet
Author: User
Tags inotify rsync

Rsync+inotify

Enterprise Web site synchronization methods have multiple, can be used to mount the shared hard disk, but can also be used Rsync+inotify-tool way.

Rsync: Responsible for pushing data to the server.

INotify: Responsible for monitoring code or file changes in the client, triggering the push.

Environment Description:

centos-6.5

A Server-side (192.168.10.2) B client (192.168.10.1)

650) this.width=650; "title=" QQ picture 20141015125455.jpg "Src=" http://s3.51cto.com/wyfs02/M01/4C/77/wKiom1Q9_kKiUdu_ Aablwnntq0w567.jpg "alt=" Wkiom1q9_kkiudu_aablwnntq0w567.jpg "/>

2: Configure file synchronization

The rsync service is installed first, and rsync plus inotify-tools is installed on master node A .

Yum-y Install Rsync

Download and install Inotify-tools

wget https://github.com/downloads/rvoicilas/inotify-tools/inotify-tools-3.14.tar.gz

Tar zxvf inotify-tools-3.14.tar.gz

CD Inotify-tools

./configure && make && make install

Do link ln-sv/usr/local/lib/libinotify*/usr/lib/ If it is a system ln-sv/usr/local/ lib/libinotify*/usr/lib64

Otherwise the launch will report the error "/usr/local/bin/inotifywait:error while loading shared libraries:libinotifytools.so.0"

Configuring rsync on host B

Establishing a rsyncd.conf configuration file

Cat/etc/rsyncd.conf

uid = Root # Specifies the uid that the daemon should have when the module transfers files

gid = Root # Specifies the GID that the daemon should have when the module transfers files

Use chroot = no

hosts allow =192.168.1 0.1 192.168.10.2 # allows any host connection

Max connections = number of client maximum Connections , default 0 ( No Limit )

PID file =/var/run/rsyncd.pid # where is the ID of the running process written to

Lock file =/var/run/rsync.lock #lock record file

Log file =/var/log/rsyncd.log # logging Files

[web] # Here is the name of the authentication module, which needs to be specified on the client side

Path =/ # You need to make a backup directory . ( preferably the current directory of the backup directory, because he will back up the entire folder, and repeat the long.) )

Comment = dwg file

Ignore errors # can ignore some unrelated IO Errors

Read Only = no #no client can upload file , yes Read only

List = False

Auth users = User1 # Authenticated user name, if not this line, indicates is anonymous

Secrets file =/etc/server.pas # Specifies the location of authentication password files

Establish the Authentication password file

Cat/etc/server.pas

User1 : 123456

chmod 600/etc/server.pas

Start service rsync--daemon

Then build the password file on host A

Cat/etc/server.pas

123456

chmod 600/etc/server.pas

Then create a monitoring script on the primary contact A

Monitor the modify,delete,create,attrib of the /usr/local/nginx/html/ directory and push it directly to B Server up

cat/root/rsync.sh

#!/bin/bash

src=/ Web

/usr/local/bin/inotifywait-mrq--timefmt '%d/%m/%y/%h:%m '--format '%T%w%f '-E modify,delete,create,attrib $src | While read file

do

rsync  -vzrtopg --delete --progress --password-file=/etc/server.pas  $src   user1 @192.168.1 0.1 ::               #A watch yourself change. to b push, if you add arguments to the back, such as   192.168.10.1::web /web test push yourself.

Done

Watching

-M is to keep listening

-R is a recursive view directory

-Q is the print out event

--TIMEFMT is the output format for the specified time

--format Specify details of file changes

-e create,move,delete,modify,attrib refers to the " listen for Create mobile delete Write permission " event

And then run

Nohup./rsync.sh &

This article is from the "Little Luo" blog, please be sure to keep this source http://xiaoluoge.blog.51cto.com/9141967/1564307

Rsync+inotify-tool of multiple Web server code synchronization

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.