In linux, automatic webpage synchronization is achieved through rsync + inotify

Source: Internet
Author: User
Tags inotify
This article describes how to use rsync + inotify to automatically synchronize webpages in linux. For more information, see how to use multiple web servers to achieve load balancing, to maintain resource consistency on the front-end web server, you can use rsync to synchronize updated files to other slave servers (read-only servers) on the master server (data can be written ), however, real-time synchronization cannot be performed automatically. inotify can be used for real-time synchronization.

Master server: 192.168.6.205 inotify
Slave server: 192.168.6.36 rsync

1. configure rsync on the slave server to enable rsync so that the master service can 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

Create the/etc/rsync. passwd password configuration file
Vim/etc/rsync. passwd
# User: password
Rsync: rsync

2. install inotify-tools on the master 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 master server to synchronize data to the slave server.
Vim/etc/rsync. passwd
# Password
Rsync

Create 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

For more articles about automatic webpage synchronization through rsync + inotify in linux, please follow PHP's Chinese network!

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.