Nginx健康检查
目录一、失败重试二、健康检查三、安装模块nginx_upstream_check_module1. 下载模块2. 解压模块3. 查看Nginx版本4. 安装补丁5. 配置模块6. 修改配置7. 验证检查结果一、失败重试Nginx配置如下:#usernobody;worker_processes1;#error_loglogs/error.log;#error_loglogs/error.logno
目录
三、安装模块nginx_upstream_check_module
一、失败重试
Nginx配置如下:
#user nobody;
worker_processes 1;
#error_log logs/error.log;
#error_log logs/error.log notice;
#error_log logs/error.log info;
#pid logs/nginx.pid;
events {
worker_connections 1024;
}
http {
upstream backend2 {
server 192.168.1.55:9022 max_fails=2 fail_timeout=10s weight=1;
}
server {
listen 8200;
server_name localhost;
#access_log logs/host.access.log main;
location / {
proxy_pass http://backend2;
#连接超时
proxy_connect_timeout 5s;
#读超时
proxy_read_timeout 5s;
#发送超时
proxy_send_timeout 5s;
#上游服务器超时
proxy_next_upstream error timeout;
proxy_next_upstream_timeout 10s;
#上游服务器重试次数
proxy_next_upstream_tries 2;
}
location /lua {
default_type 'text/html';
content_by_lua_block {
ngx.say("<p>hello, world</p>")
}
}
location /upstream_status {
#开启upstream状态页面
check_status;
}
}
二、健康检查
如上图所示,主动检查需要Nginx添加模块nginx_upstream_check_module(GitHub - yaoweibin/nginx_upstream_check_module: Health checks upstreams for nginx),见下章节介绍。
Nginx配置如下:
http {
upstream backend2 {
server 192.168.1.55:9022 weight=1;
#http类型检查:interval调用间隔时间,成功rise次后存活,失败fall次后不存活
check interval=3000 rise=1 fall=3 timeout=2000 type=http;
#和上游服务器长连接数
check_keepalive_requests 100;
#检查调用接口
check_http_send "HEAD /vms-match/v3/staticcache/basic/switch-info/900000211 HTTP/1.0\r\nConnection: keep-alive\r\n\r\n";
#调用接口响应状态码为正常
check_http_expect_alive http_2xx http_3xx;
}
}
三、安装模块nginx_upstream_check_module
1. 下载模块
https://github.com/yaoweibin/nginx_upstream_check_module
2. 解压模块
3. 查看Nginx版本
目录下:/home/openresty/openresty-1.19.9.1/bundle/nginx-1.19.9
使用补丁版本:check_1.20.1+.patch
4. 安装补丁
在/home/openresty/openresty-1.19.9.1/bundle/nginx-1.19.9下命令:
patch -p1 < /home/nginx_upstream_check_module-master/check_1.20.1+.patch
5. 配置模块
./configure --with-luajit --add-module=/home/nginx_upstream_check_module-master
make & make install
6. 修改配置
a. 检查接口:/status
b. 接口返回:2XX和3XX为成功
c. 检查上游服务器结果:check_status
7. 验证检查结果
更多推荐
所有评论(0)