«

»

Sep
26

Glassfish load balancing using mod_proxy_balancer

Overview

In my previous article about configuring a glassfish load balancer, I’ve used the mod_jk connector for the apache webserver.
These time I’m going to show, how to solve this using the mod proxy balancer plugin shipped with the most apache installations. (A “cleaner” way in my oppinion)

A couple of times I’ve tried to get the Sun load balancing plugin working, but without success. This was because of  some operating system issues or other problems.
So after looking around the web, I’ve found some good solutions using apache and the mod_jk connector from the apache tomcat project.

Requirements

Installation

  1. Configuring the glassfish cluster
    1. Copy the $CATALINA_HOME/server/lib/tomcat-ajp.jar to your $GLASSFISH_HOME/lib directory on each glassfish installation in your cluster.
    2. Also copy the commons-logging.jar and commons-modeler.jar to your $GLASSFISH_HOME/lib directory on each glassfish installation in your cluster.
    3. Now you have to define jvmRoute and com.sun.enterprise.web.connector.enableJK system properties for the cluster (this can be done from the domain administration server)
      asadmin create-jvm-options --target cluster1 "-DjvmRoute=\${AJP_INSTANCE_NAME}"
      asadmin create-jvm-options --target cluster1 "-Dcom.sun.enterprise.web.connector.enableJK=\${AJP_PORT}"
    4. Now you have to define the values for these properties for each instance running in the cluster (this can also be done from the domain administration server).
      This is needed, because the instance name, the user is working on has to be appended to the session id.

      asadmin create-system-properties --target instance1 AJP_INSTANCE_NAME=instance1
      asadmin create-system-properties --target instance1 AJP_PORT=8020
  2. Configuring the apache web server
    1. Enable mod_proxy, mod_proxy_http and mod_proxy_balancer on your apache installation.
    2. Create a virtual-host (or use your main server), and copy the following lines to i.
      Be aware, that the route parameters matches the instance names assigned in the previous steps.

      ProxyRequests       Off
      ProxyPreserveHost   On
      
      <Proxy *>
        Order deny,allow
        Allow from all
      </Proxy>
      
      <Location /balancer-manager>    
        SetHandler balancer-manager 
        ProxyPass !  
        Order deny,allow
        Allow from all
      </Location>
      
      <Proxy balancer://cluster>
        BalancerMember http://192.168.0.10:38080 route=instance1
        BalancerMember http://192.168.0.11:38080 route=instance2
        BalancerMember http://192.168.0.12:38080 route=instance3
      </Proxy>
      
      <Location />
        ProxyPass balancer://cluster/ lbmethod=byrequests stickysession=JSESSIONID|jsessionid
      </Location>
    3. Restart all cluster instances and the web server. Your load balancing should be working now.
      Each time a new session is creted by the glassfish, it appends its instance name to the JSESSIONID, so the load balancer can determine on which instance to route the request.
      If one instance crashes, the load balancer will notice this and redirects all requests to another instance. If you have enabled session replication, your old session will be resumed there.

    Further reading

Leave a Reply

Your email address will not be published.

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>