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