Linux rsync+inotify implementation of Web page automatic synchronization configuration

Source: Internet
Author: User
Tags inotify rsync


Load balancing with multiple Web servers to keep resources consistent on the front-end Web server can be synchronized to other from the server (read-only server) by rsync on the primary server (writable data), but not automatically for real-time synchronization. Real-time synchronization can be achieved using inotify
Home server: 192.168.6.205 inotify
From server: 192.168.6.36 rsync


1, on from the server to configure rsync, open Rsync services

Allow the primary service to synchronize 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

Creating a/etc/rsync.passwd Password configuration file

vim/etc/rsync.passwd
#用户: Password

Rsync:rsync

2, install the Inotify-tools on the main 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 server

vim/etc/rsync.passwd
#密码
Rsync

Creating scripts


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,delet e,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
Let the script execute in the background

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.