千家信息网

Nginx uptream健康检查

发表于:2024-09-24 作者:千家信息网编辑
千家信息网最后更新 2024年09月24日,upstream hello {server 100.14.1.3:1201;server 100.14.1.4:1201;check interval=3000 rise=2 fall=5 time
千家信息网最后更新 2024年09月24日Nginx uptream健康检查

upstream hello {
server 100.14.1.3:1201;
server 100.14.1.4:1201;
check interval=3000 rise=2 fall=5 timeout=1000 type=http;
check_http_send "HEAD /product HTTP/1.0\r\n\r\n";
check_http_expect_alive http_2xx http_3xx;
}
server {
listen 80;
server_name hello.youbest.com;
access_log /data/logs/nginx/hello.youbest.com.access.log main;
location / {
proxy_set_header X-Forwarded-For $remote_addr;
proxy_set_header X-Real-IP $remote_addr;
proxy_pass http://hello;
}
}

首先要确认服务类型是 http 还是tcp

 check interval=3000 rise=2 fall=5 timeout=1000 type=http;  or check interval=3000 rise=2 fall=5 timeout=1000 type=tcp; 然后确认健康检查的url是否支持 HEAD请求或者GET 请求 [root@100-14-1-3 ~]# curl -v -XHEAD http://hello.youbest.com/product
  • About to connect() to hello.youbest.com port 80 (#0)
  • Trying 10.24.1.3... connected
  • Connected to hello.youbest.com (100.14.1.3) port 80 (#0)

    HEAD / HTTP/1.1
    User-Agent: curl/7.19.7 (x86_64-redhat-linux-gnu) libcurl/7.19.7 NSS/3.27.1 zlib/1.2.3 libidn/1.18 libssh3/1.4.2
    Host: baidu.com
    Accept: /

    < HTTP/1.1 200 OK
    < Date: Tue, 07 Jan 2020 08:29:28 GMT
    < Server: Apache
    < Last-Modified: Tue, 12 Jan 2010 13:48:00 GMT
    < ETag: "51-47cf7e6ee8400"
    < Accept-Ranges: bytes
    < Content-Length: 81
    < Cache-Control: max-age=86400
    < Expires: Wed, 08 Jan 2020 08:29:28 GMT
    < Connection: Keep-Alive
    < Content-Type: text/html
    <

以上返回表示支持 HEAD 请求 nginx 就可以这样做健康检查

    check interval=3000 rise=2 fall=5 timeout=1000 type=http;    check_http_send "HEAD /product HTTP/1.0\r\n\r\n";    check_http_expect_alive http_2xx http_3xx;

其中 /product 表示服务里面的埋点路径

< HTTP/1.1 200 OK 表示返回200状态

如果HEAD 请求不支持 参考下面baidu.com的GET 请求

[root@vhs100-14-1-3 ~]# curl -v -XGET http://baidu.com

  • About to connect() to baidu.com port 80 (#0)
  • Trying 220.181.38.148... connected
  • Connected to baidu.com (220.181.38.148) port 80 (#0)

    GET / HTTP/1.1
    User-Agent: curl/7.19.7 (x86_64-redhat-linux-gnu) libcurl/7.19.7 NSS/3.27.1 zlib/1.2.3 libidn/1.18 libssh3/1.4.2
    Host: baidu.com
    Accept: /

    < HTTP/1.1 200 OK
    < Date: Tue, 07 Jan 2020 08:41:38 GMT
    < Server: Apache
    < Last-Modified: Tue, 12 Jan 2010 13:48:00 GMT
    < ETag: "51-47cf7e6ee8400"
    < Accept-Ranges: bytes
    < Content-Length: 81
    < Cache-Control: max-age=86400
    < Expires: Wed, 08 Jan 2020 08:41:38 GMT
    < Connection: Keep-Alive
    < Content-Type: text/html
    <


  • Connection #0 to host baidu.com left intact
  • Closing connection #0

以上表示支持 GET 请求 nginx 就可以这样做健康检查

    check interval=3000 rise=2 fall=5 timeout=1000 type=http;    check_http_send "GET /product HTTP/1.0\r\n\r\n";    check_http_expect_alive http_2xx http_3xx;

加了健康检查后,当后端有多台服务器提供服务时
Down掉的机器就不会被代理转发业务过去
从而保障业务的正常处理

健康 检查 支持 服务 业务 多台 服务器 机器 状态 类型 路径 还是 代理 保障 参考 处理 数据库的安全要保护哪些东西 数据库安全各自的含义是什么 生产安全数据库录入 数据库的安全性及管理 数据库安全策略包含哪些 海淀数据库安全审计系统 建立农村房屋安全信息数据库 易用的数据库客户端支持安全管理 连接数据库失败ssl安全错误 数据库的锁怎样保障安全 河北时代网络技术服务五星服务 山东电力公司网络安全讲座 基因数据库进化 软件开发需求申请函 顺义区好的软件开发经历 智慧央厨软件开发多少钱 以下哪些关于网络安全的认知 王者荣耀其他服务器能删除吗 江汉区国际网络安全维护收费标准 图书馆怎样提高数据库使用培训 深圳市涌浪网络技术 如何利用数据库的数据做研究 网络安全ip 一抹橙网络技术有限公司 中国股市科技互联网股票有哪些 我的世界手机服务器id 软件开发类创业计划书 如何查看当前数据库版本 数据库软件下载apk 使用专线上网的服务器ip 房务托管收缴租选软件开发 网络服务器端口不同会怎么样 网络技术与运用 测试题库 写数据库需要哪些基础 mysql数据库认证考试有哪些 辽宁信息化软件开发价格服务标准 古冶区软件开发常见问题 软件开发质量控制策略 关于网络安全的知识54字 石家庄原舟互联网科技
0