阿里云-云小站(无限量代金券发放中)
【腾讯云】云服务器、云数据库、COS、CDN、短信等热卖云产品特惠抢购

Nginx负载均衡后端健康检查(支持HTTP和TCP)

194次阅读
没有评论

共计 1902 个字符,预计需要花费 5 分钟才能阅读完成。

前面有一篇文章记录 nginx 负载均衡后端检查,链接为 https://www.linuxidc.com/Linux/2019-04/158352.htm

但是只包含 http 健康检查不包含 tcp 下面安装 nginx 可以实现 http 及 tcp 健康检查

安装

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 配置样式如下

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 的配置样式如下

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

location /upstream_status{
        healthcheck_status html;
    }

Web 页面访问

http://ip/upstream_status

页面显示如下

Nginx 负载均衡后端健康检查(支持 HTTP 和 TCP)

下面关于 Nginx 的文章您也可能喜欢,不妨参考下:

CentOS 7 下 Nginx 服务器的安装配置  https://www.linuxidc.com/Linux/2017-04/142986.htm
CentOS 上安装 Nginx 服务器实现虚拟主机和域名重定向  https://www.linuxidc.com/Linux/2017-04/142642.htm
CentOS 6.8 安装 LNMP 环境(Linux+Nginx+MySQL+PHP)https://www.linuxidc.com/Linux/2017-04/142880.htm
Linux 下安装 PHP 环境并配置 Nginx 支持 php-fpm 模块  https://www.linuxidc.com/Linux/2017-05/144333.htm
Nginx 服务的 SSL 认证和 htpasswd 认证  https://www.linuxidc.com/Linux/2017-04/142478.htm
Ubuntu 16.04 上启用加密安全的 Nginx Web 服务器  https://www.linuxidc.com/Linux/2017-07/145522.htm
Linux 中安装配置 Nginx 及参数详解  https://www.linuxidc.com/Linux/2017-05/143853.htm
Nginx 日志过滤 使用 ngx_log_if 不记录特定日志 https://www.linuxidc.com/Linux/2014-07/104686.htm
CentOS 7.2 下 Nginx+PHP+MySQL+Memcache 缓存服务器安装配置  https://www.linuxidc.com/Linux/2017-03/142168.htm
Nginx 反向代理实现 Tomcat 负载均衡 https://www.linuxidc.com/Linux/2018-03/151223.htm

Nginx 的正向代理与反向代理详解  https://www.linuxidc.com/Linux/2019-03/157360.htm

Nginx 搭建反向代理服务器 https://www.linuxidc.com/Linux/2018-03/151418.htm

Nginx 的详细介绍:请点这里
Nginx 的下载地址:请点这里

正文完
星哥说事-微信公众号
post-qrcode
 
星锅
版权声明:本站原创文章,由 星锅 2022-01-21发表,共计1902字。
转载说明:除特殊说明外本站文章皆由CC-4.0协议发布,转载请注明出处。
【腾讯云】推广者专属福利,新客户无门槛领取总价值高达2860元代金券,每种代金券限量500张,先到先得。
阿里云-最新活动爆款每日限量供应
评论(没有评论)
验证码
【腾讯云】云服务器、云数据库、COS、CDN、短信等云产品特惠热卖中