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. Configure rsync from the server and turn on rsync services 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
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,delete,create,attrib $src | While read files
Todo
$rsync-vzrtopg–delete–progress–password-file=/etc/rsync.passwd $src $user @ $host:: $DST
echo "${files} was rsynced" >>/tmp/rsync.log 2>&1
Done