Home  >  Article  >  Backend Development  >  Automatic synchronization of web pages through rsync+inotify in Linux system

Automatic synchronization of web pages through rsync+inotify in Linux system

高洛峰
高洛峰Original
2017-02-07 16:43:531125browse

Use multiple web servers to achieve load balancing. In order to maintain the consistency of resources on the front-end web server, updated files can be synchronized to other slave servers (read-only servers) through rsync on the master server (data can be written). , but it cannot automatically perform real-time synchronization. Real-time synchronization can be achieved using inotify.

Master server: 192.168.6.205 inotify
Slave server: 192.168.6.36 rsync

1. On the slave server Configure rsync and enable the rsync service so that the main 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 /etc/rsync.passwd password configuration file
vim /etc/rsync.passwd
#User: password
rsync:rsync

2. Install 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 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

Update For related articles on automatic web page synchronization through rsync+inotify in multiple Linux systems, please pay attention to the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn