nginx+rsync+inotify實(shí)現(xiàn)負(fù)載均衡配置方法
實(shí)驗(yàn)環(huán)境
前端nginx:ip 192.168.6.242,對(duì)后端的wordpress網(wǎng)站做反向代理實(shí)現(xiàn)復(fù)雜均衡
后端nginx:ip 192.168.6.36,192.168.6.205都部署wordpress,并使用相同的數(shù)據(jù)庫(kù)
1、在后端的兩個(gè)wordpress上配置rsync+inotify,兩服務(wù)器都開(kāi)啟rsync服務(wù),并且通過(guò)inotify分別向?qū)Ψ酵綌?shù)據(jù)
下面配置192.168.6.205這臺(tái)服務(wù)器
vim /etc/rsyncd.conf
uid = nginx
gid = nginx
port = 873
host all = 192.168.6.36 #另外一臺(tái)wordpress使用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 #指定帳號(hào)密碼,用于提供另外一個(gè)節(jié)點(diǎn)訪問(wèn)自身的帳號(hào)
vim /etc/rsync_server.passwd
rsync:rsync
vim /etc/rsync_client.passwd
rsync #用于訪問(wèn)另外一個(gè)wordpress使用的密碼文件
配置inotify同步腳本
#!/bin/bash
host=192.168.6.36 #另外一個(gè)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、配置前端nginx實(shí)現(xiàn)反向代理
vim /usr/local/nginx/conf/nginx.conf
#在http段中加入
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、修改wordpress中的設(shè)置,必須將這個(gè)了的站點(diǎn)地址改為前端nginx的ip地址或者域名
- linux下Nginx+Tomcat負(fù)載均衡配置方法
- 詳解Nginx中的geo模塊與利用其配置負(fù)載均衡的示例
- 在Nginx服務(wù)器中配置針對(duì)TCP的負(fù)載均衡的方法
- Nginx做NodeJS應(yīng)用負(fù)載均衡配置實(shí)例
- 5種nginx負(fù)載均衡配置方法分享
- Nginx+Windows負(fù)載均衡配置方法
- 使用nginx來(lái)負(fù)載均衡 本文在window與linux下配置nginx實(shí)現(xiàn)負(fù)載
- Nginx 簡(jiǎn)單的負(fù)載均衡配置示例
- Nginx負(fù)載均衡配置簡(jiǎn)單配置方法
相關(guān)文章
Nginx http運(yùn)行狀況健康檢查配置過(guò)程解析
這篇文章主要介紹了Nginx http運(yùn)行狀況健康檢查配置過(guò)程解析,文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友可以參考下2019-08-08Nginx出現(xiàn)The plain HTTP request was sent to HTTPS port問(wèn)題解決方法
這篇文章主要介紹了Nginx出現(xiàn)The plain HTTP request was sent to HTTPS port問(wèn)題解決方法,需要的朋友可以參考下2015-04-04nginx 如何實(shí)現(xiàn)讀寫(xiě)限流的方法
這篇文章主要介紹了nginx 如何實(shí)現(xiàn)讀寫(xiě)限流的方法的相關(guān)資料,這里提供實(shí)例代碼及如何配置,需要的朋友可以參考下2016-12-12