• 请不要在回答技术问题时复制粘贴 AI 生成的内容
saytesnake
V2EX  ›  程序员

遇到可能假死的 Spring Cloud 应用, Nginx 的负载均衡应该怎么做?

  •  
  •   saytesnake · Jul 6, 2020 · 2919 views
    This topic created in 2139 days ago, the information mentioned may be changed or developed.

    不是开发人员,情况是这样的,

    一个 Spring Cloud 应用配置了 nginx upstream,

    upstream favresin{
          ip_hash;
          server 10.0.0.1:8080 max_fails=3 fail_timeout=30s;
          server 10.0.0.2:8080 max_fails=3 fail_timeout=30s;
          server 10.0.0.3:8080 backup;
    }
    

    遇到一个问题是,10.0.0.1:8080 假死了,但端口还是通的,而 Nginx 不知道它挂了,后端飘到 10.0.0.1:8080 后,系统也理所当然挂了。

    谷歌也可以查到一些关于 Spring Cloud 健康检查的一些内容,不过我好奇,如果纯粹以运维的角度,在不修改代码的情况下,能否做到更好的负载均衡?

    在 Nginx Plus 似乎看到一些相关的,不知道是否有用。

    10 replies    2020-07-07 19:19:10 +08:00
    myCupOfTea
        1
    myCupOfTea  
       Jul 6, 2020 via Android
    额,spring cloud 不是有 gateway 吗,加上熔断把经常调用失败的服务给熔断掉
    joesonw
        2
    joesonw  
       Jul 6, 2020
    https://docs.nginx.com/nginx/admin-guide/load-balancer/http-health-check 可以不侵入业务代码, 只要有 http 接口可以被访问即可, 返回 4xx 也可以, 可以指定接受的 status 范围
    miao1007
        3
    miao1007  
       Jul 6, 2020 via iPhone
    用 consul sidecar 来规避
    StevenTong
        4
    StevenTong  
       Jul 6, 2020
    既然不能修改代码增加 actuator health,那么把 nginx healthcheck 指定到某个简单的业务接口?
    stefanaka
        5
    stefanaka  
       Jul 6, 2020 via Android
    有第三方的 nginx 模块
    wupher
        6
    wupher  
       Jul 6, 2020
    可以通过第三方模块或者 actuator health check 来判活。偷懒点,定时重启服务也是可以的。

    不过,讲真应该通过 GC log,heap dump 等工具查明为什么会出现假死,解决假死才是第一位吧。
    Oktfolio
        7
    Oktfolio  
       Jul 7, 2020
    nginx -> gateway -> api,降级、熔断
    saytesnake
        8
    saytesnake  
    OP
       Jul 7, 2020
    @joesonw
    @StevenTong

    这个是 Nginx Plus 的功能吧,不过看楼下似乎是有个第三方模块。
    saytesnake
        9
    saytesnake  
    OP
       Jul 7, 2020
    joesonw
        10
    joesonw  
       Jul 7, 2020
    @saytesnake This article describes how to configure and use HTTP health checks in NGINX Plus and NGINX Open Source.
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   937 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 42ms · UTC 22:14 · PVG 06:14 · LAX 15:14 · JFK 18:14
    ♥ Do have faith in what you're doing.