Setting up Load Balancing and Highly Available Cluster in GlassFish V2


This document explains on how to create a GlassFish V2 cluster and how to configure and manage the Load balancer for this cluster. We will also see how the failover and In-memory Replication features work in GlassFish V2. This blog is an effort to put all the content that exists on the web and put them together to create a scenario which you can try and which will work. I will walk you through the steps.

Installing the GlassFish V2
Configuring a Cluster
Installing a GlassFish V2 Load Balancer Plugin
Setting up Secure connection between DAS and SJSWS 7.0
Managing Load balancer from GlassFish Admin Console
Deploy clusterjsp sample
Export the loadbalancer.xml
Load Balancer in action
Failover and High Availability with In-memory Replication
Load balancing with other Web Servers
Using a Hardware Load Balancer

1. Installing the GlassFish V2

The GlassFish V2 bits can be downloaded from Download GlassFish V2. Also please view this screencast which shows on how to get started with GlassFish V2.

2. Configuring a Cluster

Once the GlassFish V2 is installed, we are ready to create a cluster. You can configure a cluster either through Admin CLI or Admin GUI. I recommend using the Admin CLI if you are a beginner and once you get a hang of the concepts then you can switch to Admin GUI.

a. Creating a cluster using Admin CLI

This blog will walk you through the steps in creating a two machine cluster using Admin CLI.

b. Creating a cluster using Admin Console

This screencast and blog explain on how to use the Admin Console to create and configure the GlassFish V2 cluster.

3. Using the Free Software Load Balancer from GlassFish

GlassFish V2 comes with a separate bundle of Software Load Balancer which is a plugin for Sun Java System Web Server(SJSWS) 7.0. Lets see how to install and configure this free Load balancer plugin.

a. Installing the GlassFish V2 Load Balancer Plugin

Before you install the Load Balancer Plugin you have to download and install the SJSWS 7.0, it can be downloaded from here. Now, The recommended way of installing the Load Balancer Plugin is to use the Sun Java System Application Server (SJSAS) 9.1 installer. Sun Java System Application Server 9.1 is the Productized version (from Sun) of Glassfish V2 ([1],[2]). You can download it here (SJSAS 9.1 is due to be released on 9/17/07) and you are interested in installing only the Load Balancer Plugin component, since the GlassFish V2 Application Server is already installed as part of step 1 above. The SJSAS 9.1 installer asks you for SJSWS 7.0 install location. Note that we are installing the GlassFish V2 Load balancer Plugin for SJSWS 7.0 so the Web Server understands the GlassFish V2 instances and load balances the http requests coming to the Web Server Instance.  .

SJSAS 9.1 installation of Load Balancer plugin component will perform several (about 14) steps as part of the install procedure. Alternatively, if you are brave enough, you could do these steps manually which I do not recommend, by following the steps here.

b. Setting up Secure connection between DAS and SJSWS 7.0

GlassFish V2 has a unique feature which works in sync with SJSWS 7.0. This step explains the advanced setup of GlassFish V2's Load balancer Administration with SJSWS 7.0, where one can configure the SSL connection between the Web Server and the GlassFish's Domain Administration Server. With this setup, the changes in the Glassfish V2 related to the configured cluster (ex., adding a new instance to the cluster, deploying an application to the cluster) will trigger the automatic generation of the loadbalancer.xml (by checking the deployment descriptors to identify the context root for the deployed web modules in the target cluster, pulls the webserver host and ssl port information and also the enable flags information for server-instances and applications from cluster configuration) and it is transferred over the SSL connection to the WebServer. No manual generation and copying of this file will be necessary. The steps can be found here.
Before the last step 'Testing the SSL Connection' (in the previous linked document) can be performed, you need to configure the load balancer in the GlassFish with a cluster first, which is explained in the next section.

I am soon planning to write an 'ant' script which will automate the steps described in this section. I will update these instructions when done, please stay tuned.

Alternatively if for any reason if you choose not to configure the SSL connection, you will have to manually generate the loadbalancer.xml file and then copy it to the Web Server location. This can be done by the following commands, but before that make sure you configured the Load Balancer in the GlassFish, which is explained in the next section.




Copy the generated loadbalancer.xml file to <websrvr_instance_dir>/config directory. My websrvr_instance_dir looks like '/var/opt/SUNWwbsvr7/https-<machine-name>.domain-name' (domain name as in 'sun.com')

The above manual step has to be performed whenever there is a change to the cluster configuration.

Here is how the loadbalancer.xml looks like and here is the dtd

c. Managing Load balancer from GlassFish Admin Console

i.  Create a load balancer using the Admin Console.

  1. Click the HTTP Load Balancers node in the Admin Console.
  2. Click New.
  3. Type my-lb as the name of the load balancer, the host on which Web Server is installed, and the Web Server instance port. In this sample scenarios Web Server host is localhost and the port is 8989.
  4. Select the 'Automatically Apply Changes' check box. If you choose this option, you do not have to export the load balancer configuration. All changes you make to the load balancer configuration are propagated automatically. For this to happen you need to follow the steps in this section . Alternatively you may choose to do the generation and copying of loadbalancer.xml manually as discussed in this section. If that is the case, you will have to unselect the 'Enabled' flag for 'Apply Changes', and you might want to give some arbitrary values for device-host and device-port attributes since it will not be used.
  5. Note that the Enabled flags for 'All Instances' and 'All Applications' are turned on by default. This will allow all the instances and deployed applications in the target cluster to be load balanced.
  6. Select cluster1 as target.
  7. Click OK.

ii.  Create a load balancer using Admin CLI

create the 'load-balancer' element using the asadmin 'create-http-lb' command




This will create the load-balancer with the cluster 'cluster1' as the target. The --devicehost and --deviceport options are valid when you have established the SSL connection between GlassFish Domain Administration Server (DAS) and the Web Server 7.0. When you mention these arguments they are used to identify the WebServer's ssl host and port information, and it is used to automatically upload the changes in the form of loadbalancer.xml from DAS to WebServer. The loadbalancer.xml is generated and exported automatically to Web Server whenever there is a change in configuration of the targeted cluster (ex. add/delete an instance in cluster, deploy an application to the cluster etc.,). For this to happen you need to follow the steps in this section . Alternatively you may choose to do the generation and copying of loadbalancer.xml manually as discussed in this section. If that is the case, you will have to set the option --autoapplyenabled to false, and you might want to give some arbitrary values for --devicehost and --deviceport attributes since it will not be used.

d. Starting and Verifying the Load Balancing

i.  Deploy clusterjsp sample 

Deploy the clusterjsp sample with availabilityenabled flag set to true. You may choose to do this from Admin Console too.

asadmin deploy --availabilityenabled=true --target cluster1 ../samples/quickstart/clusterjsp/clusterjsp.ear

ii. Export the loadbalancer.xml

When the SSL channel is setup between DAS and Web server, the loadbalancer.xml is automatically transferred across after the deployment is done for cluster1 target.

In case the SSL is not setup, you need to manually export the loadbalancer.xml as follows.

asadmin export-http-lb-config --lbname my-lb <my-location>/loadbalancer.xml

Copy the loadbalancer.xml generated from above step to the Web Server instance location's config directory. Restart the web server instance.

iii. Load Balancer in action

Now we are ready to see the load balancer in action. Go to a browser (say firefox) and give the web server instance location as the url and append the clusterjsp context root as shown below. Do the same from another browser (different than the first time, say IE), you will see that the  request is sent to the second  machine/instance. This means that the Load Balancer is  using the round robin policy to delegate the incoming requests to different instances. If you try to access the URL from the same browser, you will see that the request goes to the same instance again, this shows that the 'sticky round robin' policy of the Load Balancer is working.


iv. Failover and High Availability with In-memory Replication

Lets see how the Failover and Recovery (High availability) of session data happens using the In-memory replication feature of GlassFish V2.

Note that we used GlassFish V2 cluster profile when creating the domain and then created the cluster in that domain. When you do this, the In-memory replication is configured by default as the high-availability option for this cluster. Also remember, we deployed the clusterjsp app with --availabilityenabled option set to 'true'.
  • Access the clusterjsp application from a browser (http://<web-server-instance-machine>:port/clusterjsp). You will see that the request is served by one of the instances and the name of the machine is displayed.
  • Enter the data in the Name and Value fields of 'Session Attribute' (say name1 & value1) at the bottom of the page.
  • Now stop the instance where the request is going (the instance on the machine which is displayed in the clusterjsp page) using the following command.
asadmin stop-instance --user admin --host DASHost --port 4848 <instance-name>
  • Go back to the browser where the request was served the first time. Add more session data to it (say name2 & value2). Click on 'Add Session Data'.
  • Notice that the request has now gone to the second machine. This has happened since the instance on the first machine was bought down, so the session has failed over to the next available instance. Also notice that the Session data at the bottom of the screen contains both the data (one that was entered when the instance on the first machine was up and also the new data when it went down). This shows that the In-memory replication feature is working.
Note\*: For multi machine clusters the following are prerequisites for the In-Memory Replication and Shoal's GMS dynamic clustering facility
  1. Machines/Instances should be located on the same subnet
  2. The system times on the machine clocks should be synchronized to be as close as possible

4. Load balancing with other Web Servers and GlassFish V2

a. Sun Java System Web Server 6.1

The instructions to setup the SJSWS 6.1 should not be any different from 7.0. Additionally you can also follow the specific instructions for 9.1 installation here. Or you can follow the instructions from this blog.

b. Apache Web Server 2.0 and mod_jk

These instructions explain in detail on how to setup the load balancing with mod_jk and GlassFish. These instructions explain the installation of Load Balancer Plugin for Apache Web Server 2.0.

c. Microsoft IIS  5.0 and 6.0

The instructions are in great detail in this doc for installing the Load Balancer Plugin for Microsoft IIS 5.0 and 6.0.

5. Using a Hardware Load Balancer

a. F5's Big-IP with Glassfish V2

This blog gives details on how to configure the F5's BIG-IP hardware load balancer with GlassFish V2

b. Sun Secure Application Switch with Glassfish and SJSAS 9.0

This article gives details on how to configure Sun Secure Application Switch with GlassFish and SJSAS 9.0

Comments:

Great Blog!<br>
Just wanted to add for the benefit of users that for multi machine clusters the following are prerequisites for the In-Memory Replication and Shoal's GMS dynamic clustering facility:<br>
1. machines/instances should be located on the same subnet<br>
2. the system times on the machine clocks should be synchronized to be as close as possible<br>

Posted by Shreedhar on September 17, 2007 at 02:53 AM PDT #

Nice work. We should also do
something about automating these
steps.

- Kedar

Posted by Kedar Mhaswade on September 20, 2007 at 05:43 AM PDT #

Where you speak of the Load Balancer you say "Now, The recommended way of installing the Load Balancer Plugin is to use the Sun Java System Application Server (SJSAS) 9.1 installer"

I downloaded the SJSAS 9.1 and there was no option in the installer to do this.

Posted by Sam on September 26, 2007 at 11:12 AM PDT #

I downloaded the SJSAS 9.1 and there was no option in the installer to do this.

I think he is refereing SJSAS 9.1 EE edition with HADB.

Posted by Troydm on December 09, 2007 at 06:53 AM PST #

Hi Prashant,
One of our client is using F5 BIG-IP 9.1.2 Build 40.2 LoadBalancer, and here they used SSO mechanism and, when they login to application they are entered into application and immediatly login page showing, In log files showing SSO errors.We are thinking errors occured because of Loadbalancer misconfiguration. Colud Suggest on this..?
i have doubt at below entry..
virtual webct-https {
destination 10.151.90.40:443
ip protocol tcp
profile tcp webct-ssl weblogic-https-header
persist webct-session
pool webct-pool
rule HTTP_Error_page
}

Thanks in advance

Posted by Phani Kumar on July 14, 2008 at 04:48 PM PDT #

Is this still the current best practices approach with the currently released Glassfish 2.1 and Sun Webserver 7.0? (I'm just trying to setup the load balancer for a Glassfish cluster with the Sun Webserver.)

Posted by Rob Ratcliff on February 19, 2009 at 08:45 AM PST #

Hi, First thanks for a such a great post. I am looking for similar information for GF V3. Greatly appreciate if you can kindly provide some links/pointers.

Kudos

Posted by code brain on February 23, 2010 at 02:09 PM PST #

Post a Comment:
  • HTML Syntax: NOT allowed
About

bloggerprashanth

Search

Categories
Archives
« April 2014
SunMonTueWedThuFriSat
  
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
   
       
Today