我正在为我的tomcats工作haproxy配置,我有两个后端组,第一个后端有两个tomcat和循环方法的服务请求,而其他后端只有一个tomcat。现在我想要如果请求进入第二个backeng并且它已经关闭,请求应该重新发送到其他后端的服务器。我正在使用此配置。
#---------------------------------------------------------------------
# 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
任何人都可以帮助我在这里做错了什么
答案 0 :(得分:3)
您可以尝试在规则中添加第二个条件,以便向第二个后端发送请求,即检查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