Load balancing configuration with nginx + rsync + inotify in Centos

Source: Internet
Author: User


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.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.