加载中…
个人资料
尧舜禹
尧舜禹
  • 博客等级:
  • 博客积分:0
  • 博客访问:6,956
  • 关注人气:9
  • 获赠金笔:0支
  • 赠出金笔:0支
  • 荣誉徽章:
正文 字体大小:

为OpenResty增加nginx_http_upstream_check_module模块

(2019-01-09 14:16:35)
分类: linux类文章
下载模块安装文件
cd /root
git clone https://github.com/yaoweibin/nginx_upstream_check_module.git
yum -y install patch

下载openresty源码包
wget https://openresty.org/download/openresty-1.13.6.2.tar.gz

打补丁和编译安装
tar zxvf openresty-1.13.6.2.tar.gz
cd /root/openresty-1.13.6.2/bundle/nginx-1.13.6
patch -p1 < /root/nginx_upstream_check_module/check_1.12.1+.patch 
./configure --prefix=/usr/local/openresty/ --with-http_stub_status_module --add-module=/root/nginx_upstream_check_module/
make
//注意不需要执行make install,执行make install是覆盖安装

mv /usr/local/openresty/nginx/sbin/nginx /usr/local/openresty/nginx/sbin/nginx.old
cp /root/openresty-1.13.6.2/build/nginx-1.13.6/objs/nginx /usr/local/openresty/nginx/sbin/.

检测模块是否被增加
/usr/local/openresty/nginx/sbin/nginx -V
重启服务:
/etc/rc.d/init.d/openresty restart

使用:

在nginx.conf配置文件里面的upstream加入健康检查,如下:

 

 upstream search89 {
# ip_hash;
 server  172.0.1.19:80 max_fails=2 fail_timeout=5s;
 server  172.0.1.20:80 max_fails=2 fail_timeout=5s;
 check interval=3000 rise=2 fall=5 timeout=2000 type=http;
 #check_keepalive_requests 1;
 #check_http_send "GET / HTTP/1.0\r\n\r\n";
 #check_http_send "GET / HTTP/1.0\r\n HOST www.redhat.sx\r\n\r\n";
 check_http_expect_alive http_2xx http_3xx;
 }

在生产环境的实施应用中,需要注意的有 2 点:

1、主要定义好type。由于默认的type是tcp类型,因此假设你服务启动,不管是否初始化完毕,它的端口都会起来,所以此时前段负载均衡器为认为该服务已经可用,其实是不可用状态。

2、注意check_http_send值的设定。由于它的默认值是"GET / HTTP/1.0\r\n\r\n"。假设你的应用是通过http://ip/name访问的,那么这里你的check_http_send值就需要更改为"GET /name HTTP/1.0\r\n\r\n"才可以。针对采用长连接进行检查的,这里增加keep-alive请求头,即"HEAD /name HTTP/1.1\r\nConnection: keep-alive\r\n\r\n"。如果你后端的tomcat是基于域名的多虚拟机,此时你需要通过check_http_send定义host,不然每次访问都是失败,范例:check_http_send "GET /mobileapi HTTP/1.0\r\n HOST www.redhat.sx\r\n\r\n";

0

阅读 收藏 喜欢 打印举报/Report
  

新浪BLOG意见反馈留言板 欢迎批评指正

新浪简介 | About Sina | 广告服务 | 联系我们 | 招聘信息 | 网站律师 | SINA English | 产品答疑

新浪公司 版权所有