nginx_upstream_check_module

来源:互联网 发布:如何安装ubuntu双系统 编辑:程序博客网 时间:2024/05/22 08:29

nginx 负载均衡web查看状态nginx_upstream_check_module


最近在做nginx负载均衡的时候发现nginx本身没有界面的管理工具,也没有发现其他的文本的管理工具。希望知道的朋友可以留言告诉我. 发现taobao在开源了自己的nginx 定制版本里面,有一个模块(nginx_upstream_check_module),这个模块就是用来查看nginx 负载均衡时候的realserver的状态的. 经过实验已经成功加入nginx 再此做个记录和分享。


lnmp 环境的安装请参照我的生产环境的lnmp 的安装,在安装nginx的时候参照下面的安装:

http://renzhenxing.blog.51cto.com/blog/728846/1321572


下载nginx_upstream_check_module:

1
2
3
cd /usr/local/src/
wget https://github.com/yaoweibin/nginx_upstream_check_module/archive/master.zip
unzip master.zip


安装nginx的支持:pcre

1
2
3
tar-zxvf pcre-8.21.tar.gz
cd pcre-8.21
./configure && make && makeinstall



安装nginx-1.3.0

1
2
tar -zxvf nginx-1.3.0.tar.gz
cd nginx-1.3.0


给nginx打上nginx_upstream_check_module-master的包

(注:因nginx版本更新,1.2以上版本的nginx,补丁为check_1.2.1+.patch)

1
patch -p1 < /usr/local/src/nginx_upstream_check_module-master/check_1.2.1.patch


开始编译安装nginx:

### 注意下面的--with-pcre=pcre的安装包路径千万不要搞错了。

1
./configure --user=www --group=www --prefix=/usr/local/nginx --sbin-path=/usr/local/nginx/sbin/nginx --conf-path=/usr/local/nginx/conf/nginx.conf --with-http_stub_status_module --with-http_ssl_module --with-pcre=/usr/local/src/pcre-8.21 --lock-path=/var/run/nginx.lock --pid-path=/var/run/nginx.pid --add-module=/usr/local/src/nginx_upstream_check_module-master
1
make && make install



添加nginx配置:

因为篇幅大小原因,这个配置文件是省略了部分常用内容,但是并不代表其他不需要.(以下为需要特别注意的地方)


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
upstream www {
    #ip_hash;
    server 192.168.100.11:80;      #多个realserver服务器在此添加
    server 192.168.100.12:80;
    check interval=3000 rise=2 fall=5 timeout=1000;
}
server {
    listen       80;
    server_name  www.etiantian.org;
    #charset koi8-r;
    access_log  logs/host.access.log  main;
    root   /data0/www;
    location / {
        proxy_pass http://www;
        proxy_set_header Host $host;
        proxy_set_header X-Real-IP $remote_addr;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
    }
                                                                                                                                                                                             
       location /status {
            check_status;
            access_log   off;
            #allow SOME.IP.ADD.RESS;
            #deny all;
       
}


※ 附件会发上来我的nginx 配置文件,希望对大家有帮助.


1  upstream 后面的www不是域名.可以根据需要自己起。

2  upstream 后面的www 要和proxy_pass http://www; 里面的www相互对应.

3  注解:check interval=3000 rise=2 fall=5 timeout=1000;

   interval检测间隔时间,单位为毫秒。

   rsie请求2次正常的话,标记此realserver的状态为up。

   fall表示请求5次都失败的情况下,标记此realserver的状态为down。

   timeout为超时时间,单位为毫秒。


测试nginx:

1
2
3
/usr/local/nginx/sbin/nginx -t
nginx: the configuration file /usr/local/nginx/conf/nginx.conf syntax is ok
nginx: configuration file /usr/local/nginx/conf/nginx.conf test is successful


启动nginx:


1
/usr/local/nginx/sbin/nginx &


测试截图:

114423662.jpg

阅读全文
0 0
原创粉丝点击