Using multiple Web servers for load balancing, in order to maintain consistency of resources on the front-end Web servers, you can synchronize updated files to other slave servers (read-only servers) via rsync on the primary server (writable data), but not automatically in real-time synchronization. Real-time synchronization is possible with inotify
Primary server: 192.168.6.205 inotify
From server: 192.168.6.36 rsync
1, configure rsync from the server, turn on the rsync service, let the master service can synchronize the 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 a/etc/rsync.passwd password configuration file
vim/etc/rsync.passwd
#用户: Password
Rsync:rsync
2. Install Inotify-tools on the primary 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 slave server
vim/etc/rsync.passwd
#密码
Rsync
Create a 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