前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >http| tengine-2.3.0 upstream http check

http| tengine-2.3.0 upstream http check

作者头像
heidsoft
发布2019-06-19 18:49:02
1.5K0
发布2019-06-19 18:49:02
举报

一、编译配置

采用模块:ngx_http_upstream_check_module

https://tengine.taobao.org/document_cn/http_upstream_check_cn.html

该模块可以为Tengine提供主动式后端服务器健康检查的功能。

参数生成

while read line; do echo -e "--add-module=modules/$line" ; done < 1.txt yum install luajit yum install luajit-devel

tengine-2.3.0 编译

./configure --add-module=modules/ngx_backtrace_module --add-module=modules/ngx_debug_pool --add-module=modules/ngx_debug_timer --add-module=modules/ngx_http_concat_module --add-module=modules/ngx_http_footer_filter_module --add-module=modules/ngx_http_proxy_connect_module --add-module=modules/ngx_http_reqstat_module --add-module=modules/ngx_http_slice_module --add-module=modules/ngx_http_sysguard_module --add-module=modules/ngx_http_trim_filter_module --add-module=modules/ngx_http_upstream_check_module --add-module=modules/ngx_http_upstream_consistent_hash_module --add-module=modules/ngx_http_upstream_dynamic_module --add-module=modules/ngx_http_upstream_dyups_module --add-module=modules/ngx_http_upstream_keepalive_module --add-module=modules/ngx_http_upstream_session_sticky_module --add-module=modules/ngx_http_user_agent_module --add-module=modules/ngx_slab_stat --without-http_upstream_keepalive_module --with-luajit-inc=/usr/include/luajit-2.0

二、基于head请求方式

HTTP HEAD 方法 请求资源的头部信息, 并且这些头部与 HTTP GET 方法请求时返回的一致. 该请求方法的一个使用场景是在下载一个大文件前先获取其大小再决定是否要下载, 以此可以节约带宽资源.

检查方式:

upstream cluster1 { # simple round-robin server xxx1:80; server xxx2:80; server xxx3:80; check interval=3000 rise=2 fall=5 timeout=1000 type=http; check_http_send "HEAD /actuator/health HTTP/1.0\r\nHOST:devops-backend.heidsoft.com\r\n\r\n"; check_http_expect_alive http_2xx http_3xx; } # 此处需要注意发送head请求的地址与主机信息,标红字段 server { listen 80; server_name devops.heidsoft.com; location / { proxy_set_header Host "devops-backend.heidsoft.com"; proxy_pass http://cluster1; } location /status { check_status; } }

三、check指令参数:

指令后面的参数意义是:

  • interval:向后端发送的健康检查包的间隔。
  • fall(fall_count): 如果连续失败次数达到fall_count,服务器就被认为是down。
  • rise(rise_count): 如果连续成功次数达到rise_count,服务器就被认为是up。
  • timeout: 后端健康请求的超时时间。
  • default_down: 设定初始时服务器的状态,如果是true,就说明默认是down的,如果是false,就是up的。默认值是true,也就是一开始服务器认为是不可用,要等健康检查包达到一定成功次数以后才会被认为是健康的。
  • type:健康检查包的类型,现在支持以下多种类型
    • tcp:简单的tcp连接,如果连接成功,就说明后端正常。
    • ssl_hello:发送一个初始的SSL hello包并接受服务器的SSL hello包。
    • http:发送HTTP请求,通过后端的回复包的状态来判断后端是否存活。
    • mysql: 向mysql服务器连接,通过接收服务器的greeting包来判断后端是否存活。
    • ajp:向后端发送AJP协议的Cping包,通过接收Cpong包来判断后端是否存活。
  • port: 指定后端服务器的检查端口。你可以指定不同于真实服务的后端服务器的端口,比如后端提供的是443端口的应用,你可以去检查80端口的状态来判断后端健康状况。默认是0,表示跟后端server提供真实服务的端口一样。该选项出现于Tengine-1.4.0。

四、请求结果

请求状态页面:http://devops.heidsoft.com/status

html格式结果

json或者csv请求结果

代码语言:javascript
复制
/status?format=html
/status?format=csv
/status?format=json
本文参与 腾讯云自媒体分享计划,分享自微信公众号。
原始发表:2019-06-14,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 云数智圈 微信公众号,前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体分享计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档