Home > Article > Operation and Maintenance > How to realize automatic synchronization of web pages in Linux
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 real-time synchronization cannot be performed automatically. Real-time synchronization can be achieved using inotify
Master server: 192.168.6.205 inotify
Slave server: 192.168.6.36 rsync
1. Configure rsync from the server 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
The above is the detailed content of How to realize automatic synchronization of web pages in Linux. For more information, please follow other related articles on the PHP Chinese website!