How to configure nginx+rsync+inotify to realize load balancing
This article mainly introduces how to configure nginx+rsync+inotify to achieve Load Balancer related knowledge, the content is detailed and easy to understand, the operation is simple and fast, and has certain reference value. I believe everyone will gain something after reading this article on how to configure nginx+rsync+inotify to achieve Load Balancer. Let's take a look at it together.
experimental environment
Front-end nginx: ip 192.168.6.242, reverse proxy for back-end wordpress websites to achieve complex balance
Backend nginx: ip 192.168.6.36, 192.168.6.205 both deploy WordPress and use the same database
1. Configure rsync+inotify on the two wordpress servers on the backend. Both servers turn on rsync service and synchronize data to each other through inotify.
The following configuration 192.168.6.205 server
vim /etc/rsyncd.conf
uid = nginx
gid = nginx
port = 873
host all = 192.168.6.36 #another wordpress using 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 password of the account, which is used to provide another node to access its own account
vim /etc/rsync_server.passwd
rsync:rsync
vim /etc/rsync_client.passwd
rsync #is used to access another password file used by wordpress
Configure inotify sync 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 to http section
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, modify the settings in wordpress, you must change the site address to the IP address or domain name of the front-end nginx
About "nginx+rsync+inotify how to configure to achieve Load Balancer" The content of this article is introduced here, thank you for reading! I believe everyone has a certain understanding of "nginx+rsync+inotify how to configure to achieve Load Balancer." If you still want to learn more knowledge, please pay attention to the industry information channel.