将请求重新发送到 haproxy 中的默认服务器或其他服务器?

redispatch request to default server or other server in haproxy?

我正在为我的 tomcat 进行 haproxy 配置,我有两个后端组,第一个后端有两个 tomcat 并且以循环法服务请求,而其他后端只有 1 个tomcat。现在我想如果请求转到第二个后端并且它已关闭,请求应该重新发送到其他后端的启动服务器。我正在使用这个配置。

#---------------------------------------------------------------------
# Example configuration for a possible web application.  See the
# full configuration options online.
#
#   http://haproxy.1wt.eu/download/1.4/doc/configuration.txt
#
#---------------------------------------------------------------------

#---------------------------------------------------------------------
# Global settings
#---------------------------------------------------------------------
global
    log         127.0.0.1 local0
    chroot      /var/lib/haproxy
    pidfile     /var/run/haproxy.pid
    maxconn     4000
    user        haproxy
    group       haproxy
    daemon

    # turn on stats unix socket
    stats socket /var/lib/haproxy/stats
    stats socket /var/run/haproxy.sock level admin

#---------------------------------------------------------------------
# common defaults that all the 'listen' and 'backend' sections will
# use if not designated in their block
#---------------------------------------------------------------------
defaults
    mode                    http
    log                     global
    option                  httplog
    option                  dontlognull
    option http-server-close
    option forwardfor       except 127.0.0.0/8
    retries                 3
    timeout http-request    600s
    timeout queue           1m
    timeout connect         10s
    timeout client          1m
    timeout server          1m
    timeout http-keep-alive 15s
    timeout check           5s
    maxconn                 2000

frontend nginx
    bind *:5000
    mode http 
    acl tomcat1 path_beg -i /dologin
    acl tomcat2 path_beg -i /mobileapp
    default_backend backend_tomcat1
    use_backend backend_tomcat1    if tomcat1
    use_backend backend_tomcat2    if tomcat2

backend backend_tomcat1
    mode http
    balance roundrobin
    server tomcat01 X.X.X.X:8080 check inter 2000
    server tomcat03 X.X.X.X:8080 check inter 2000

backend backend_tomcat2
    mode http
    option persist
    option redispatch
    server tomcat02 X.X.X.X:8080 check inter 2000

listen stats *:1936
    stats enable
    stats refresh 2s
    stats uri /
    stats hide-version
    stats auth admin:admin
    stats admin if TRUE

任何人都可以帮助我我在这里做错了什么

您可以尝试在向第二个后端发送请求的规则中添加第二个条件,即检查 backcend2 的服务器状态,然后设置默认后端。

更多信息:http://cbonte.github.io/haproxy-dconv/configuration-1.5.html#7.3.2-srv_is_up

frontend nginx
    bind *:5000
    mode http 
    acl tomcat1 path_beg -i /dologin
    acl tomcat2 path_beg -i /mobileapp
    acl is_alive srv_is_up(backend_tomcat2/tomcat02)
    use_backend backend_tomcat1    if tomcat1
    use_backend backend_tomcat2    if tomcat2 is_alive
    default_backend servers tomcat1