Lab environment
Front-end nginx: ip address 192.168.6.242, reverse proxy for the back-end wordpress website to achieve load balancing
Backend nginx: wordpress is deployed at ip 192.168.6.36 and 192.168.6.205, and the same database is used.
1. Install rsync and inotify
Configure rsync + inotify on two backend wordpress servers. Both servers enable rsync and use inotify to synchronize data to each other.
Configure 192.168.6.205 as the server below
Vim/etc/rsyncd. conf
Uid = nginx
Gid = nginx
Port = 873
<Span style = "background-color: # (color);"> <span style = "color: # f00; "> host all = 192.168.6.36 # Another wordpress uses 192.168.6.205 </span>
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 = <span style = "color: # f00;">/etc/rsync_server.passwd # specifies the account password, which is used to provide another node to access its own account
</Span>
Vim/etc/rsync_server.passwd
Rsync: rsync
Vim/etc/rsync_client.passwd
Rsync # used to access the password file used by another wordpress
Configure inotify synchronization script
Vim/root/inotify. sh
#! /Bin/bash
Host = 192.168.6.36 # Another wordpress
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_client.passwd $ src $ user @ $ host: $ dst
Echo "$ {files} was rsynced">/tmp/rsync. log 2> & 1
Done
Run the script in the background
Nohup/root/inotify. sh &
2. Configure the front-end nginx to implement reverse proxy
Vim/usr/local/nginx/conf/nginx. conf
# Adding an http segment
Include vhost/wordpress. conf;
Mkdir/usr/local/nginx/confi/vhost
Vim/usr/local/nginx/confi/vhost/wordpress. conf
Upstream wordpress {
Server 192.168.6.205 weight = 1;
Server 192.168.6.36 weight = 1;
}
Server {
Location /{
Proxy_pass http: // wordpress;
Proxy_redirect off;
Proxy_set_header Host $ host;
Proxy_set_header X-Real-IP $ remote_addr;
}
}
3. To modify the settings in wordpress, you must change the site address to the IP address or domain name of the front-end nginx.