Nginx负载均衡后端健康检查(支持HTTP和TCP)
之前有一篇文章记录nginx负载均衡后端检查,链接为 https://www.cnblogs.com/minseo/p/9511456.html
但是只包含http健康检查不包含tcp下面安装nginx可以实现http及tcp健康检查
参考 https://github.com/zhouchangxun/ngx_healthcheck_module/
安装
1 2 3 4 5 6 7 8 9 | git clone https: / / github.com / nginx / nginx.git git clone https: / / github.com / zhouchangxun / ngx_healthcheck_module.git cd nginx / ; git checkout branches / stable - 1.12 git apply .. / ngx_healthcheck_module / nginx_healthcheck_for_nginx_1. 12 + .patch . / auto / configure - - with - stream - - add - module = .. / ngx_healthcheck_module / make && make install |
git下载nginx及健康检查模板安装nginx
配置http的upstream配置样式如下
1 2 3 4 5 6 | upstream www.xxx.net{ server 172.16 . 90.232 : 81 ; check interval = 3000 rise = 2 fall = 5 timeout = 5000 type = http; check_http_send "GET / HTTP/1.0\r\n\r\n" ; check_http_expect_alive http_2xx http_3xx; } |
配置tcp的upstream的配置样式如下
1 2 3 4 5 | upstream device5000{ server 172.16 . 90.52 : 5000 ; server 172.16 . 90.53 : 5000 ; check interval = 3000 rise = 2 fall = 5 timeout = 5000 default_down = true type = tcp; } |
在主配置文件新加一个location
1 2 3 | location / upstream_status{ healthcheck_status html; } |
web页面访问
1 | http: / / ip / upstream_status |
页面显示如下
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· SQL Server 2025 AI相关能力初探
· Linux系列:如何用 C#调用 C方法造成内存泄露
· AI与.NET技术实操系列(二):开始使用ML.NET
· 记一次.NET内存居高不下排查解决与启示
· 探究高空视频全景AR技术的实现原理
· 阿里最新开源QwQ-32B,效果媲美deepseek-r1满血版,部署成本又又又降低了!
· AI编程工具终极对决:字节Trae VS Cursor,谁才是开发者新宠?
· 开源Multi-agent AI智能体框架aevatar.ai,欢迎大家贡献代码
· Manus重磅发布:全球首款通用AI代理技术深度解析与实战指南
· 被坑几百块钱后,我竟然真的恢复了删除的微信聊天记录!
2017-04-19 Python之collections序列迭代器下标式循环冒泡算法等