Version 31

    Using mod_proxy with JBoss bundle and Apache2.2.x

     

    This wiki outlines the various steps required to install a basic load-balancing solution based on mod_proxy, mod_proxy_balancer and JBoss. Mod_proxy allows to use http/https and AJP protocols to proxy to JBoss. This documentation is for Apache httpd-2.2.x if you have to use older version of httpd see Load Balancing using mod_rewrite and mod_proxy

     

    Using mod_proxy with http/https:

     

    Step 1: Download Apache2.2.x Web Server

     

    Get the latest Apache2.2.x package from Apache.org and install it. We require no special configuration, just use the default settings. In the following steps, APACHE_HOME will represent the Apache install directory.

     

    +

    • Note:* At the time of the writting of this document Apache 2.2.9 is most stable version of Apache httpd-2.2.x and is recommended if you want to use load-balancing using mod_proxy

    +

     

     

    Step 2: Setup Apache to use mod_proxy (HTTP)

     

     

    Make sure that at least following modules are loaded (uncomment this in 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
    

     

    These are sufficient for http load balancing. However you may need to load mod_proxy_ftp module if you are using ftp or load mod_proxy_connect module if you are using SSL

     

     

    Add those lines in APACHE_HOME/conf/httpd.conf :

     

         <Proxy balancer://mycluster>
           Order deny,allow
           Allow from all
    
           BalancerMember http://host1:8080 route=node1
           BalancerMember http://host2:8180 route=node2
         </Proxy>
         
    
         ProxyPass /jmx-console balancer://mycluster
         ProxyPassReverse /jmx-console  http://host1:8080/jmx-console
         ProxyPassReverse /jmx-console  http://host2:8180/jmx-console
    
    

     

    By default the requests are load balanced in byrequests fashion, which performs weighted request counting. This is determined by parameter lbmethod. The stickysession parameter is also required, as there is no default value. stickysession is used to determine which URL session name or cookie to use when looking for the route for the request.

     

         ProxyPass /jmx-console balancer://mycluster lbmethod=byrequests stickysession=JSESSIONID|jsessionid 
    

     

    You can find more about ProxyPass attributes in the Apache HTTP Server documentation at http://httpd.apache.org/docs/2.2/mod/mod_proxy.html .

     

     

    Step 3: Configure JBoss Web if you want to use sticky session

     

     

    Edit JBOSS_HOME/server/all/deploy/jbossweb-web.deployer/server.xml (replace /all with your own server name)

    Locate the <Engine> element and add an attribute for jvmRoute:

                   <Engine name="jboss.web" defaultHost="localhost" jvmRoute="node1">
                       .
                   </Engine>
    

     

    Step 4: Configure JBoss session to add jvmRoute to the sessions

     

     

    Finally, we need to tell JBoss Web to add the jvmRoute value to its session cookies so that mod_proxy_balancer can route incoming requests.

     

    Edit JBOSS_HOME/server/all/deploy/jboss-web.deployer/META-INF/jboss-service.xml (replace /all with your own server name)

     

    Locate the attribute element with a name of UseJK, and set its value to "true":

     

    <attribute name="UseJK">true</attribute>
    

     

    Using mod_proxy with AJP:

     

    Step 1: See Using mod_proxy with http/https (above)

     

    Step 2: Setup Apache to use mod_proxy (AJP)

     

     

    Make sure that at least following modules are loaded (uncomment this in httpd.conf)

     

         LoadModule proxy_module modules/mod_proxy.so
         LoadModule proxy_balancer_module modules/mod_proxy_balancer.so
         LoadModule proxy_ajp_module modules/mod_proxy_ajp.so
    

     

    Add those lines in APACHE_HOME/conf/httpd.conf :

     

         <Proxy balancer://mycluster>
           Order deny,allow
              Allow from all
    
              BalancerMember ajp://localhost:8009/jmx-console
              BalancerMember ajp://localhost:8109/jmx-console
         </Proxy>
         
    
         ProxyPass /jmx-console balancer://mycluster
    
    

     

    Step 3: See Using mod_proxy with http/https (above)

     

    Step 4: See Using mod_proxy with http/https (above)

     

    When to use mod_jk and when to use mod_proxy for load-balancing

     

     

      • Load balancing is definitely easier to configure using mod_proxy as compared to mod_jk1.x.

      • mod_proxy works well since version 2.2.2 of Apache httpd. Don't use mod_proxy with older version of Apache httpd.

      • mod_jk is in continous development phase and is tried and tested by many people arround the world. mod_proxy is fairly new.

      • mod_proxy_http doesn't forward the SSL information to JBoss Web (See Forwarding SSL environment when using http/https proxy )

      • mod_proxy allows to use https between Apache httpd and JBoss Web (See Encrypting connection between httpd and TC).

     

    If you decide to use mod_proxy, you have two options for load-balancing

     

     

    When to use mod_proxy + mod_proxy_http and mod_proxy + mod_proxy_ajp for load-balancing

     

     

      • AJP is binary, so there was the transmission savings

      • JBoss Web could handle AJP faster and more efficiently than HTTP (the AJP endpoints were quicker than the HTTP endpoint implementations)

      • However mod_proxy_http now implements connection pooling and load balancing so one needs to test mod_proxy_http as well as mod_proxy_ajp before deciding

     

     

    Here is the FAQ on mod_proxy_ajp vs mod_jk

     

    Using sticky sessions:

     

    Add stickysession parameter to ProxyPass

            ProxyPass /jmx-console balancer://mycluster stickysession=JSESSIONID lbmethod=bytraffic nofailover=Off 
    

     

    Sticky Session is supported by mod_proxy_http as well as mod_proxy_ajp

     

    • Note:* If you are using mod_proxy_http you have to create one ProxyPassReverse for each BalancerMember you define in the balancer.

     

    Going over the 8K AJP headers limits:

    The default size of a AJP package is 8K as the http headers are sent only in the first packet it could be needed to overcome the limit.

     

    To reach this you need to add packetSize parameter in the <Connector/> parameter like:

     

        <Connector port="8009" protocol="AJP/1.3"
                   packetSize="20000"
                   redirectPort="8443" ></Connector>
    

    and ProxyIOBufferSize (also LimitRequestFieldsize probably) directive in httpd.conf too. For example:

     

    ProxyIOBufferSize 19000
    LimitRequestFieldsize 18000
    

    packetSize is supported since Tomcat 5.5.21 and Tomcat 6.0.1.

     

    Old version of httpd-2.2.x (x<5) need a patch to support this extension. You find the patch at http://people.apache.org/~jfclere/patches/ProxyIOBufferSize.patch