日期:2014-05-16  浏览次数:20807 次

apache+glassfish2负载均衡及会话粘滞参考2

Apache load balancer without Glassfish cluster profile

Requirements

  • Apache 2.2.x
  • mod_proxy
  • mod_proxy_balancer
  • mod_rewrite
  • Glassfish 2 ur2 +

Setup

Add the following to make Apache load balance to your Glassfish instances:
  RewriteEngine On
  ProxyRequests Off

  <Proxy *>
    Order deny,allow
    Allow from all
  </Proxy>

  <Location /balancer-manager>
    SetHandler balancer-manager
  </Location>

  <Proxy balancer://mycluster>
    BalancerMember http://10.1.1.2:8080 route=w1
    BalancerMember http://10.1.1.3:8080 route=w2
    BalancerMember http://10.1.1.4:8080 route=w3
  </Proxy>

  <Location /clusterjsp>
    Order allow,deny
    Allow from all
  </Location>

  ProxyPass /clusterjsp balancer://mycluster/clusterjsp stickysession=JSESSIONID
                    
Note the BalancerMember entries mentioned above. These are the separate Glassfish instances you will need to install. Use the regular Glassfish install and deploy the clusterjsp application with a /clusterjsp context root. Follow the directions below for each separate Glassfish instance.

?

The Glassfish distribution contains an example application that allows you to see how it works in a cluster. You will deploy this application since we are still running the load-balancer. See GLASSFISH_ROOT/samples/quickstart/clusterjsp.

?

Go to the administration console of your Glassfish installation. Click on the Applications tab and click on Deploy, select the clusterjsp.ear file that you found in the Glassfish samples directory. Then click OK. Then browse to http://localhost/clusterjsp and see your work in action!

?

To make sure the session sticks you will have to set a JVM option, add the following JVM option to your Glassfish instance so it knows it is running in an Apache cluster setting:
  -DjvmRoute=ROUTE
                    
Note ROUTE needs to be the same as the route parameter mentioned in the BalancerMember entries. I cannot stress this enough, make sure that this setting matches up otherwise your sticky sessions will NOT work!

?

Once you are finished setting up all the instance continue on below, otherwise repeat the same process for all the instances you want to setup.

?

You now have both Apache and the Glassfish instances configured so it is time to check if the load-balancer is online. Browse to http://localhost/balancer-manager (where localhost is your Apache server) and verify if the load-balancer sees the 3 workers and if the routes are set.

?

Please send comments, suggestions and any feedback to sales@manorrock.com.