【问题标题】:haproxy 1.8 sc0_get_gpc0 activate acl from bad request counthaproxy 1.8 sc0_get_gpc0 从错误的请求计数中激活 acl
【发布时间】:2023-03-26 16:34:01
【问题描述】:

我正在运行 HAproxy 1.8 并尝试使用 Stick-table 跟踪通用计数器,但每次 ACL 调用它时它都不会返回 true。

我的期望是;一旦计数器超过 5,ACL 将导致它转到不同的后端。可能出了什么问题?

# default block configs are set to http settings

frontend my_service
  bind *:80
  tcp-request inspect-delay 5s

  acl bad_request sc0_get_gpc0(my_service_bk) gt 5
  use_backend my_service_bad_bk if bad_request

  default_backend my_service
backend my_service_bad_bk
  errorfile 503 /etc/haproxy/429.http
backend my_service
  http-request track-sc0 req.fhdr(X-My-Service)
  http-response sc-inc-gpc0 if { status gt 399 }
  stick-table type string len 350 size 10m expire 10m store gpc0

  balance roundrobin
  server .....
  server .....

我查看了 Stick-table 统计信息,它在 6 次请求后显示:

0x7f2279cdsa42: key=test use=0 exp=278850 gpc0=6

它仍然将它发送到错误的后端 (my_service)

【问题讨论】:

    标签: load-balancing acl haproxy


    【解决方案1】:

    移动stick-tableacls 我想出了一个解决方案。看来sc0_get_gpc0backend 中时可以从stick-table 获取正确的内容

    下面是工作代码的样子:

    # default block configs are set to http settings
    
    frontend my_service
      bind *:80
      tcp-request inspect-delay 5s
    
      http-request track-sc0 req.fhdr(X-My-Service)
      stick-table type string len 350 size 10m expire 10m store gpc0
    
      default_backend my_service
    backend my_service
      http-response sc-inc-gpc0 if { status gt 399 }
    
      acl bad_request sc0_get_gpc0(my_service) gt 5
      use-server bad_request if bad_reqest
    
      balance roundrobin
      server bad_request localhost:9090 weight 0
    
      # normal app servers below this without weight 0
      server .....
    
    frontend bad_requests
      bind localhost:9090
    
      default_backend my_service_bad
    
    backend my_service_bad
      errorfile 503 /etc/haproxy/429.http
    

    在后端执行此操作的关键是将weight 0 用于仅提供错误代码和响应的服务器。如果 ACL 未激活,带有weight 0 的服务器将不会用于流量。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多