Apache负载均衡相关重要配置

1 负载分配算法
ProxyRequests Off   
<Proxy balancer://myCluster>  
  BalancerMember http://localhost:3006   
  BalancerMember http://localhost:3007
  BalancerMember http://localhost:3008
  ProxySet lbmethod=bybusyness
</Proxy>
lbmethod取值有:
lbmethod=byrequests 按照请求次数均衡(默认)
lbmethod=bytraffic 按照流量均衡
lbmethod=bybusyness 按照繁忙程度均衡(总是分配给活跃请求数最少的服务器)

2 负载比例分配
ProxyRequests Off   
<Proxy balancer://myCluster>  
  BalancerMember http://localhost:3006 loadfactor=3 
  BalancerMember http://localhost:3007 loadfactor=3
  BalancerMember http://localhost:3008 loadfactor=4
  ProxySet lbmethod=bybusyness
</Proxy>
这样就使得比例为3:3:4

3 热备份(Hot Standby)
ProxyRequests Off   
<Proxy balancer://myCluster>  
  BalancerMember http://localhost:3006   
  BalancerMember http://localhost:3007
  BalancerMember http://localhost:3008
  BalancerMember http://localhost:4001 status=+H
  ProxySet lbmethod=bybusyness
</Proxy>  
只要在后面加上status=+H即可,正常情况下请求总是流向3006 3007和3008的,一旦3006 3007和3008有挂掉, Apache会检测到错误并把请求分流给4001。Apache会每隔几分钟检测一下3006 3007和3008的状况,如果3006 3007和3008恢复,就继续使用3006 3007和3008。

你可能感兴趣的:(apache,算法)