我是Ha-proxy的新手并陷入困境。
我为两台服务器10.x.y.10和10.x.y.20配置了ha-proxy。这两个跑码头。
如果其中一个码头停机,一切都运转良好。请求转到第二台服务器,一切都按预期发生。
问题:假设两个码头都在运行,如果我从一个码头删除“war”文件,请求不会转到第二个服务器。它只是给出错误“错误404未找到”
我知道我为jetty配置了ha-proxy而不是war文件,但如果war文件丢失或者请求的情况不可能,有没有办法重定向请求。
请指出正确的方向。
提前致谢。
这是我的haproxy配置。
defaults
mode http
log global
option httplog
option logasap
option dontlognull
option http-server-close
option forwardfor except 127.0.0.0/8
option redispatch
retries 3
timeout http-request 10s
timeout queue 1m
timeout connect 10s
timeout client 1m
timeout server 1m
timeout http-keep-alive 10s
timeout check 10s
maxconn 3000
frontend vs_http_80
bind *:9090
default_backend pool_http_80
backend pool_http_80
#balance options
balance roundrobin
#http options
mode http
option httpchk OPTIONS /
option forwardfor
option http-server-close
#monitoring service endpoints with healthchecks
server pool_member1 10.x.y.10:8080 // x and y are dummy variables
server pool_member2 10.x.y.20:8080
frontend vs_stats :8081
mode http
default_backend stats_backend
backend stats_backend
mode http
stats enable
stats uri /stats
stats realm Stats\ Page
stats auth serveruser:password
stats admin if TRUE
答案 0 :(得分:3)
我终于找到了解决方案。如果有人遇到同样的问题,请找到以下解决方案。
以下链接解决了我的问题
http://tecadmin.net/haproxy-acl-for-load-balancing-on-url-request/
基本上,前端配置中的以下行条目可以解决问题。
acl is_blog url_beg /blog
use_backend tecadmin_blog if is_blog
default_backend tecadmin_website
ACL =访问控制列表 - > ACL用于测试某些条件并执行操作
如果满足前提条件,则重定向到后端服务器。 我们可以使用多个acls并通过相同的前端指向多个后端。
接下来在后端服务器配置中,我们需要添加"检查"最终会影响其健康状况。
backend tecadmin_website
mode http
balance roundrobin # Load Balancing algorithm
option httpchk
option forwardfor
server WEB1 192.168.1.103:80 check
server WEB2 192.168.1.105:80 check
这是我的问题的完整配置。
defaults
mode http
log global
option httplog
option logasap
option dontlognull
option http-server-close
option forwardfor except 127.0.0.0/8
option redispatch
retries 3
timeout http-request 10s
timeout queue 1m
timeout connect 10s
timeout client 1m
timeout server 1m
timeout http-keep-alive 10s
timeout check 10s
maxconn 3000
frontend vs_http_80
bind *:9090
acl x1_app path_dir x1
acl x2_app path_dir x2
acl x1_avail nbsrv(backend_x1) ge 1
acl x2_avail nbsrv(backend_x2) ge 1
use_backend backend_x1 if x1_app1 x1_avail
use_backend backend_x2 if x2_app x2_avail
backend backend_x1
#balance options
balance roundrobin
#http options
mode http
option httpchk GET /x1
option forwardfor
option http-server-close
#monitoring service endpoints with healthchecks
server pool_member1 10.x.y.143:8080/x1 check
server pool_member2 10.x.y.141:8080/x2 check
backend backend_x2
#balance options
balance roundrobin
#http options
mode http
option httpchk GET /x2
option forwardfor
option http-server-close
#monitoring service endpoints with healthchecks
server pool_member1 10.x.y.143:8080/x2 check
server pool_member2 10.x.y6.141:8080/x2 check
frontend vs_stats :8081
mode http
default_backend stats_backend
backend stats_backend
mode http
stats enable
stats uri /stats
stats realm Stats\ Page
stats auth serveruser:password
stats admin if TRUE