2014-07-01 35 views
3

我是Ha-proxy的新手,陷入困境。在码头配置ha-proxy“war”文件

我为两台服务器10.x.y.10和10.x.y.20配置了ha-proxy。这两个运行码头。

如果其中一个码头发生故障,一切正常。请求转到第二台服务器,一切都按预期发生。

问题:假设两个码头都在运行,并且如果我从一个码头中删除“war”文件,请求不会转到第二个服务器。它只是给出错误“错误404未找到”

我知道我已配置码头的ha代理不是为战争文件,但有没有任何方式来重定向请求,如果战争文件丢失或所需的情况是不均匀可能。

请指点我正确的方向。

在此先感谢。

这是我的haproxy配置。

HA代理配置

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 

回答

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