Rsync+inotify for data synchronization

Source: Internet
Author: User
Tags inotify

RSYNCD is used to synchronize the operation of 2 machines to ensure the consistency of the data,inotify to detect changes in the system, using rsync+inotify to achieve real-time synchronization

s:192.168.1.234 Path:/usr/local/nginx-1.6.3/html/home/paixian/root

c:192.168.1.136 Path:/data/paixian/root


1. operations on the server

Yum Install rsync xinetd-y// download software

vi/etc/rsyncd.conf///Create RSYNCD configuration file manually

#Global Settings

UID = nobody

GID = Nobody

Use chroot = yes

Max connections = 10

Timeout = 300

Strict modes = yes

PID file =/var/run/rsync/rsyncd.pid

#lock file =/var/run/rsync/rsyncd.lock

Log file =/var/log/rsync/rsyncd.log

[Data]

#path =/usr/local/nginx-1.6.3/html/home/paixian/root

Path =/usr/local/nginx-1.6.3/html/home/paixian/root

Ignore errors = yes

Read Only = no

Write only = no

Hosts allow = 192.168.1.0/24

Hosts deny = *

List = False

UID = root

GID = root

Auth users = min

Secrets file =/etc/rsyncd.passwd

VI/ETC/RSYNCD.PASSWD// Create a password file

Min:min

chmod 600/rsyncd.passwd

Service xinetd Start ///Start xinetd services (including RSYNCD service)

2. Client Configuration

Test RYSNC First

echo "passwd" >/etc/rsync.passwd // Create a password file

[Email protected] root]# rsync--list-only--password-file=/etc/rsyncd.passwd [email protected]::d ATA

drwxrwxrwx 4096 2015/09/10 17:46:58.

-rwxr-xr-x 404 2015/09/10 14:58:26 admin.php

-rwxr-xr-x 244 2015/09/10 14:50:04 config.php

-rwxr-xr-x 299 2015/09/10 14:50:04 index.php

-rwxr-xr-x 2015/09/10 14:58:26 phpinfo.php

-rwxr-xr-x 1414 2015/09/10 14:50:02product_list.phtml

-rwxr-xr-x 1998 2015/09/10 14:58:26 test.php

-rw-r--r--2015/09/10 14:46:31 test1.php

drwxrwxrwx 4096 2015/09/10 14:59:05. Cache

drwxrwxrwx 4096 2015/09/10 14:58:28 admin

drwxrwxrwx 4096 2015/09/10 14:50:02 data

drwxrwxrwx 4096 2015/09/10 14:58:26 Demo

drwxrwxrwx 4096 2015/09/10 14:50:02 Demo2

drwxrwxrwx 4096 2015/09/10 14:46:31phpdemo_boxcontroler

drwxrwxrwx 4096 2015/09/10 14:46:34 statics

drwxrwxrwx 4096 2015/09/10 14:58:26 test

drwxrwxrwx 4096 2015/09/10 14:50:41 web

change of monitoring system using inotify

wget http://github.com/downloads/rvoicilas/in Otify-tools/inotify-tools-3.14.tar.gz

MV inotify-tools-3.14.tar.gz /usr/local

Cd/usr/local

Tar XF inotify-tools-3.14.tar.gz

MV inotify-3.14 INotify

./configure

Make&&make Install

Write Scripts for synchronization

[Email protected] root]# cat/usr/local/inotify/backup.sh

Inotifywait-mrq--timefmt '%y/%m/%d-%h:%m:%s '--format '%T%w%f%e '-e modify,attrib,move,create,delete/data/paixian/ Root|while Read files

Do

RSYNC-VZRTOPG--delete--progress--password-file=/etc/rsyncd.passwd/data/paixian/root/[email protected]::d ATA && echo "${files} was rsynced" >>/tmp/rsync.log2>&1

echo "--------------------------------------------------------"

Done

Run the script

Bash/usr/local/inotify/backup.sh &

[Email protected] root]# Ps-ef |grep Backup

Root 1670 1 0 16:16? 00:00:00 bash/usr/local/inotify/backup.sh

Root 1672 1670 0 16:16? 00:00:00 bash/usr/local/inotify/backup.sh

Root 1782 1729 0 18:32 pts/1 00:00:00 grep backup

Test

Server

[Email protected] root]# pwd

/usr/local/nginx-1.6.3/html/home/paixian/root

[[email protected] root]# ls

Total 72

Drwxrwxrwx. Root root 4096 Sep 10 18:36.

Drwxr-xr-x. 4 root root 4096 Sep 7 06:34..

Drwxrwxrwx. 8 root root 4096 Sep 14:58 admin

-rwxr-xr-x 1 root root 404 Sep 14:58admin.php

Drwxrwxrwx. 2 root root 4096 Sep 14:59. Cache

-rwxr-xr-x 1 root root 244 Sep 14:50config.php

Drwxrwxrwx. 6 root root 4096 Sep 14:50 data

Drwxrwxrwx. 4 root root 4096 Sep 14:58 Demo

Drwxrwxrwx. 3 root root 4096 Sep 14:50 Demo2

-rwxr-xr-x 1 root root 299 Sep 14:50index.php

Drwxrwxrwx. 3 root root 4096 Sep 14:46 Phpdemo_boxcontroler

-rwxr-xr-x 1 root root Sep 14:58phpinfo.php

-rwxr-xr-x 1 root root 1414 Sep 14:50 product_list.phtml

Drwxrwxrwx. 7 root root 4096 Sep 14:46 statics

Drwxrwxrwx. 2 root root 4096 Sep 14:58 test

-rw-r--r--1 root root and Sep 14:46test1.php

-rwxr-xr-x 1 root root 1998 SEP 14:58 test.php

Drwxrwxrwx. Root root 4096 Sep 14:50web

[Email protected] root]#

Client

[Email protected] root]# pwd

/data/paixian/root

[Email protected] root]# mkdir min

[Email protected] ~]# tail-f/tmp/rsync.log

2015/09/10-18:35:27/data/paixian/root/mincreate,isdir was rsynced

http://debris.blog.51cto.com/1614432/1683627

http://ljbaby.blog.51cto.com/10002758/1675870


This article is from the "innovation sharing gallop inside and out" blog, please be sure to keep this source http://10554846.blog.51cto.com/10544846/1693630

Rsync+inotify for data 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.