To meet the requirements, the previous rsync timed PUSH Service cannot meet the actual needs.
Environment Introduction:
The nginx cluster of a website is set up because the number of website content is updated frequently, but it takes a lot of time to update the data of one website. Therefore, rsync + inotify is used to push data to the cluster host in real time.
Remote website IP Address: 172.16.100.99/usr/html
Remote website IP Address: 172.16.100.97/usr/html
Local push IP Address: 172.16.100.98/web/Data
Environment:
Redhat5.9
Rsync-3.1.1.tar.gz
Inotify-tools-3.14.tar.gz
Remote ip99 installation:
1.compile and install rsync-3.1.1.tar.gz
Tar zxvf rsync-3.1.1.tar.gz
CD rsync-3.1.1
./Configre
Make
Make install
2. Compile the rsyncd. conf configuration file.
Uid = nobody
Gid = nobody
Max connections = 10
Use chroot = No
Strict mode = No
PID file =/var/run/rsyncd. PID
Lock file =/var/lock/rsync. Lock
Log File =/var/log/rsyncd. Log
[Web99]
Path =/usr/html
Comment = nginx's page comment
Read Only = No
Write only = No
Ignore errors
Uid = root
Gid = root
Host deny = *
Host allow = 172.16.100.98
List = false
Auth users = backup99
Secrets file =/etc/server. Pass
3. Compile a password file that can access the pushing host.
VI/etc/server. Pass
Backup99: 123456
4. Change Password File Permissions
Chmod 600/etc/server. Pass
Remote ip97 installation:
1.compile and install rsync-3.1.1.tar.gz
Tar zxvf rsync-3.1.1.tar.gz
CD rsync-3.1.1
./Configre
Make
Make install
2. Compile the rsyncd. conf configuration file.
Uid = nobody
Gid = nobody
Max connections = 10
Use chroot = No
Strict mode = No
PID file =/var/run/rsyncd. PID
Lock file =/var/lock/rsync. Lock
Log File =/var/log/rsyncd. Log
[Web97]
Path =/usr/html
Comment = nginx's page comment
Read Only = No
Write only = No
Ignore errors
Uid = root
Gid = root
Host deny = *
Host allow = 172.16.100.98
List = false
Auth users = backup97
Secrets file =/etc/server. Pass
3. Compile a password file that can access the pushing host.
VI/etc/server. Pass
Backup97: 123456
4. Change Password File Permissions
Chmod 600/etc/server. Pass
Remote ip98 Installation:
1.compile and install rsync-3.1.1.tar.gz
Tar zxvf rsync-3.1.1.tar.gz
CD rsync-3.1.1
./Configre
Make
Make install
2.compile and install inotify-tools-3.14.tar.gz
Tar zxvf inotify-tools-3.14.tar.gz
CD inotify-tools-3.14
./Configure
Make
Make intall
3. Compile the inotify synchronization script
VI inotify-sync.sh
#! /Bin/bash
Host1 = 172.16.100.99
Host2 = 172.16.100.97
Src = // web/data/
Dst1 = web99
Dst2 = web97
# Dst2 = Images
User1 = backup99
User2 = backup97
Inotifywait-mrq -- timefmt '% d/% m/% Y % H: % m' -- format' % T % w % F % e'-e modify, create, delete, attrib $ SRC | while read files
Do
Rsync-vzrtopg -- delete -- Progress -- exclude "* access *" -- exclude "* debug *" -- password-file =/etc/server. pass $ SRC [email protected] $ host1: $ dst1
Rsync-vzrtopg -- delete -- Progress -- exclude "* access *" -- exclude "* debug *" -- password-file =/etc/server. pass $ SRC [email protected] $ host2: $ dst2
Echo "$ {files} was rsyncd">/var/log/rsync. log 2> & 1
Done
This article is from the "frequently used documentation" blog, please be sure to keep this source http://yujianglei.blog.51cto.com/7215578/1568742
rsync + inotify deployment