nginx+rsync+inotify实现负载均衡
实验环境
前端nginx:ip 192.168.6.242,对后端的wordpress网站做反向代理实现负载均衡
后端nginx:ip 192.168.6.36,192.168.6.205都部署wordpress,并使用相同的数据库
安装rsync和inotify
在后端的两个wordpress上配置rsync+inotify,两服务器都开启rsync服务,并且通过inotify分别向对方同步数据, 下面配置192.168.6.205这台服务器
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
|
vim
/
etc
/
rsyncd
.
conf
uid
=
nginx
gid
=
nginx
port
=
873
host
all
=
192.168.6.36
#另外一台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
#指定帐号密码,用于提供另外一个节点访问自身的帐号
|
账号密码
1
2
3
4
5
6
7
8
|
服务端
vim
/
etc
/
rsync_server
.
passwd
rsync
:
rsync
客户端
vim
/
etc
/
rsync_client
.
passwd
rsync
#用于访问另外一个wordpress使用的密码文件
|
配置inotify同步脚本
1
2
3
4
5
6
7
8
9
10
11
12
13
|
vim
/
root
/
inotify
.
sh
#!/bin/bash
host
=
192.168.6.36
#另外一个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
|
让该脚本在后台运行
1
|
nohup
/
root
/
inotify
.
sh
&
|
配置前端nginx实现反向代理
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
|
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
;
}
}
|
修改wordpress中的设置
必须将这个了的站点地址改为前端nginx的ip地址或者域名

nginx-inotify-load
本文转自:http://www.zhengdazhi.com/archives/877
收 藏
成长的对话版权声明:以上内容作者已申请原创保护,未经允许不得转载,侵权必究!授权事宜、对本内容有异议或投诉,敬请联系网站管理员,我们将尽快回复您,谢谢合作!