首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 服务器 > Apache >

apache跟tomcat 负载及转发

2012-07-31 
apache和tomcat 负载及转发1. apache server 一个?httpd-2.2.19-win32-x862. tomcat7 server 五个? ?端口

apache和tomcat 负载及转发

1. apache server 一个?httpd-2.2.19-win32-x86


2. tomcat7 server 五个

? ?端口分别为 8081, 8082, 8083, 8084, 8085


? 对应的项目分别为 /test12, /test12, /test34, /test34,/test5


3. httpd.conf

? ??

? ? 启用:

? ? ? ?mod_proxy.so,mod_proxy_balancer.so,mod_proxy_http.so?


? ? 添加

ProxyPass /images !

ProxyPass /css !?

ProxyPass /js !

#ProxyPassReverse /examples http://127.0.0.1:8081/examples/

ProxyPass /test12 balancer://proxy12/

<Proxy balancer://proxy12>

? ? ? ? BalancerMember http://127.0.0.1:8081/test12/

? ? ? ?BalancerMember http://127.0.0.1:8082/test12/

</Proxy>

ProxyPass /test34 balancer://proxy34/

<Proxy balancer://proxy34>

? ? ? ? BalancerMember http://127.0.0.1:8083/test34/

? ? ? ?BalancerMember http://127.0.0.1:8084/test34/

</Proxy>

ProxyPass /test5 http://127.0.0.1:8085/test5/


分别8081, 8082负载test12项目,8083, 8084负载test34, 转发8085

? ?

4. 效果

? ??http://127.0.0.1/test12/test.jsp?均衡转发到 8081,8082上

? ??http://127.0.0.1/test34/test.jsp?均衡转发到 8083, 8084上

? ??http://127.0.0.1/test5/test.jsp?转发到8085上

?

5. 负载分配算法

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

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

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

?

6. 官方文档地址

? ? ??http://httpd.apache.org/docs/2.2/mod/mod_proxy.html#proxy

热点排行