Home >Operation and Maintenance >Nginx >How to configure nginx+rsync+inotify to achieve load balancing

How to configure nginx+rsync+inotify to achieve load balancing

PHPz
PHPzforward
2023-05-11 15:37:061576browse

Experimental environment

Front-end nginx: ip 192.168.6.242, reverse proxy for the back-end wordpress website to achieve complex balance
Back-end nginx: ip 192.168.6.36, 192.168 .6.205 Deploy WordPress and use the same database

1. Configure rsync inotify on the two WordPress backends. Both servers enable the rsync service and synchronize data to each other through inotify.
Configuration below 192.168.6.205This server
vim /etc/rsyncd.conf
uid = nginx
gid = nginx
port = 873
host all = 192.168.6.36 #Another wordpress uses 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_server.passwd #Specify the account password to provide another node with access to itself Account

vim /etc/rsync_server.passwd
rsync:rsync

vim /etc/rsync_client.passwd
rsync                                                                used by wordpress Password file

Configure inotify synchronization script
#!/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

2. Configure front-end nginx to implement reverse proxy
vim /usr/local/nginx/conf/nginx.conf
#Add
include vhost/wordpress in the http segment. 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. Modify the settings in wordpress. You must change the site address to The IP address or domain name of the front-end nginx

How to configure nginx+rsync+inotify to achieve load balancing

The above is the detailed content of How to configure nginx+rsync+inotify to achieve load balancing. For more information, please follow other related articles on the PHP Chinese website!

Statement:
This article is reproduced at:yisu.com. If there is any infringement, please contact admin@php.cn delete