Automatic synchronization of Web pages via rsync+inotify in Linux system

Source: Internet
Author: User
Tags inotify
Using multiple Web servers for load balancing, in order to maintain consistency of resources on the front-end Web servers, you can synchronize updated files to other slave servers (read-only servers) via rsync on the primary server (writable data), but not automatically in real-time synchronization. Real-time synchronization is possible with inotify

Primary server: 192.168.6.205 inotify
From server: 192.168.6.36 rsync

1, configure rsync from the server, turn on the rsync service, let the master service can synchronize the resources to the server

Vim/etc/rsyncd.conf
UID = Nginx
GID = Nginx
Port = 873
Host all = 192.168.6.205
Use chroot = On
Max connections = 4
Timeout = yes
[WordPress]
Path =/usr/local/nginx/html/wordpress
Comment = rsync files
Ignore errors
Read Only = no
List = yes
Auth users = rsync
Secrets file =/etc/rsync.passwd

Create a/etc/rsync.passwd password configuration file
vim/etc/rsync.passwd
#用户: Password
Rsync:rsync

2. Install Inotify-tools on the primary server

TAR-ZXVF inotify-tools-3.14.tar.gz
CD inotify-tools-3.14
./configure–prefix=/usr/local/inotify
Make && make install

Configure the rsync password file on the primary server to synchronize data to the slave server
vim/etc/rsync.passwd
#密码
Rsync

Create a script
Vim inotifyrsync.sh

#!/bin/bash
host=192.168.6.36
src=/usr/local/nginx/html/wordpress/
Dst=wordpress
User=rsync
Inotifywait=/usr/local/inotify/bin/inotifywait
Rsync=/usr/bin/rsync
$inotifywait-mrq–timefmt '%d/%m/%y%h:%m ' –format '%T%w%f '-E modify,delete,create,attrib $src | While read files
Do
$rsync-vzrtopg–delete–progress–password-file=/etc/rsync.passwd $src $user @ $host:: $DST
echo "${files} was rsynced" >>/tmp/rsync.log 2>&1
Done

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.