1. 程式人生 > >Windows下Apache+Tomcat反向代理負載均衡(HTTP)

Windows下Apache+Tomcat反向代理負載均衡(HTTP)

0、資料準備

      下載:httpd-2.2.25-win32-x86-openssl-0.9.8y

       準備:tomcat 6

1、配置2tomcat例項

tomcat1

<Engine name="Catalina" defaultHost="localhost" jvmRoute="tomcat1">

tomcat2

<Engine name="Catalina" defaultHost="localhost" jvmRoute="tomcat1">

2、若在同一臺機器上的兩個tomcat注意相關的埠

tomcat1

<Server port="8010" shutdown="SHUTDOWN">

<Connector port="8080" protocol="HTTP/1.1" 
               connectionTimeout="20000" 
               redirectPort="8443" URIEncoding="UTF-8"/>

<Connector port="8090" protocol="AJP/1.3" redirectPort="8443" />

tomcat2

<Server port="8011" shutdown="SHUTDOWN">

<Connector port="8081" protocol="HTTP/1.1" 
               connectionTimeout="20000" 
               redirectPort="8443" URIEncoding="UTF-8"/>

<Connector port="8091" protocol="AJP/1.3" redirectPort="8443" />

3、Apache上配置Proxy

 (1)載入相關代理模組

  ${apacheserver}/conf/httpd.conf中做如下配置:

   LoadModule proxy_module modules/mod_proxy.so
   LoadModule proxy_balancer_module modules/mod_proxy_balancer.so
   LoadModule proxy_http_module modules/mod_proxy_http.so


  (2)定義反向代理和負載均衡

<IfModule proxy_balancer_module>
    # define a Load Balance Proxy based HTTP protocol
    <IfModule proxy_http_module>
        <Proxy balancer://myHttpLB>
          BalancerMember http://localhost:8081/examples loadfactor=50 route=tomcat2
            BalancerMember http://localhost:8080/examples loadfactor=50 route=tomcat1
        </Proxy>
        ProxyRequests off
        ProxyPass /HdFinancialPay balancer://myHttpLB/ stickySession=JSESSIONID nofailover=Off
        ProxyPassReverse /examples balancer://myHttpLB/
    </IfModule>
   </IfModule>

測試:

http://localhost/examples