Sun Java System Application Server Enterprise Edition 8.1 2005Q2 Quick Start Guide

- Previous: Deploying an Application
- Next: Cleaning Up

# Setting up Load Balancing

A load balancer is typically deployed in front of a cluster. It:

- Allows an application or service to be scaled horizontally across multiple physical (or logical) hosts yet still presents the user with a single URL

- Insulates the user from host failures or server crashes, when it is used with session replication

- Enhances security by hiding the internal network from the user

Application Server includes load balancing plug-ins for popular web servers like Apache, Microsoft Windows IIS, and Sun Java System Web Server.

This section provides instructions on how to download and set up the Web Server software to act as a load balancer to the cluster of Application Servers. To complete this section, you must have sufficient memory to run a Web Server on your system in addition to the Domain Administration Server and the two Application Server instances you have created so far in this guide. A system with 512 Mbytes to 1024 Mbytes of memory is recommended to complete this section.

This topic presents the following steps:

- Installing Web Server Software

- Installing the Load Balancer Plug-in

- Creating a Load Balancer Configuration

- Starting Load Balancing

- Verifying Load Balancing

## Installing Web Server Software

If you already have Web Server software installed, and if you can identify a Web Server instance to serve as the load balancer, note the location of this instance in the file system and skip to Installing the Load Balancer Plug-in.

### To Install the Web Server Using the Java Enterprise System Installer

If you are using Sun Java Enterprise System software, the Web Server is selected for installation automatically when you choose to install the Load Balancer Plug-in. However, you can also install Web Server software using these steps:

1. Launch the Java Enterprise System installer.

2. Select the Sun Java System Web Server component in the Component Selection page.

3. Choose “Configure Now” to be prompted for Web Server Configuration during installation.

4. When you are prompted, define a default Web Server instance.

   Tip –

   Remember the port number you choose for this default Web Server instance. This guide assumes that port 38000 is selected as the HTTP port for default instance.

### To Install the Web Server for Stand-Alone Application Server Installations

If you are using a stand-alone Application Server, or if you do not have access to the Sun Java Enterprise System installer, install Web Server software using these steps:

1. Go to `http://www.sun.com/downloads`. Scroll down to the Web & Proxy Servers heading and click Web Servers.

2. Download Web Server 6.1 Service Pack 2 or higher for the locale and platform of your choice.

   To download, you must log in with username and password registered with MySunSM, Sun StoreSM, SunSolveSM, or the Online Support Center. If you do not have a login account, you can register online.

3. Follow the instructions to install Web Server software. You must:

   1. Extract the software from the compressed archive.

   2. Run the setup program. If you need additional information, see the Web Server installation instructions at `http://docs.sun.com`.

4. The Web Server installation process configures the Administration Server for Web Server and prompts you to define a default Web Server instance.

   Tip –

   Remember the port number you choose for this default web server instance. This guide assumes that port 38000 is selected as the HTTP port for default instance.

## Installing the Load Balancer Plug-in

The section describes installing the load balancer plug-in for either a Sun Java Enterprise System distribution or a stand-alone Application Server distribution.

### To Install the Load Balancer Plug-in

1. Run the installer for the software distribution you are using—Sun Java Enterprise System software or the stand-alone Sun Java System Application Server software.

2. When you are asked which components you want to install, select Load Balancing Plug-in.

   On the Sun Java Enterprise System installer, you must expand the Application Server item to see the Load Balancing Plug-in. It is not selected for installation by default.

## Creating a Load Balancer Configuration

Now return to interacting with the Application Server’s Domain Admin Server. You need a shell execution environment for this section.

### To Create an HTTP Load Balancer Configuration

1. Create a load balancer configuration called `MyLbConfig` targeted to the cluster FirstCluster:

   `asadmin create-http-lb-config --target FirstCluster MyLbConfig`

2. Enable the FirstCluster cluster and the clusterjsp application deployed in it for HTTP load balancing:

   `asadmin enable-http-lb-server FirstCluster`

   `asadmin enable-http-lb-application --name clusterjsp FirstCluster`

3. Create a health checker for the load balancer, which signals when an instance that goes down recovers.

   `asadmin create-http-health-checker --interval 10 --config MyLbConfig FirstCluster`

   The interval is the number of seconds the health checker waits between checks of an unhealthy instance.

4. Export the configuration to a file `loadbalancer.xml`.

   `asadmin export-http-lb-config --config MyLbConfig loadbalancer.xml`

5. Copy `loadbalancer.xml` to:

   web_server_install_dir`/https-`hostname`/config/loadbalancer.xml`

## Starting Load Balancing

Start load balancing by starting or restarting the Web Server.

- If the Web Server instance serving as load balancer is not already running, start the Web Server software by executing the start program in the following directory:

  web_server_install_dir`/https-`hostname

- If the Web Server instance serving as load balancer is already running, stop the server and start it using the start and stop programs in the following directory:

  web_server_install_dir`/https-`hostname

## Verifying Load Balancing

Once the application is deployed and the load balancer is running, verify that the load balancing is working.

### To Verify Load Balancing

1. To display the first page of the clusterjsp application, type this URL in your browser:

   `http://`localhost`:`web_server_port`/clusterjsp`

   Replace the localhost variable with the name of the system that the Web Server is running on.

   Replace the web_server_port variable with the value of the port attribute of the `LS` element in web_server_install_dir`/https-`hostname`/config/server.xml`. For this example, port 38000 is used.

   A page similar to what you saw in To Verify the Application Deployment. appears.

2. Examine the Session and Host information displayed. For example:

   - `Executed From Server:` localhost

   - `Server Port Number: 38000`

   - `Executed Server IP Address: 192.18.145.133`

   - `Session Created: Day Mon 05 14:55:34 PDT 2005`

3. The Server Port Number is 38000, the Web Server’s port. The load balancer has forwarded the request on the two instances in the cluster.

4. Using different browser software, or a browser on a different machine, create a new session. Requests from the same browser are “sticky” and go to the same instance.

   These sessions should be distributed to the two instances in the cluster. You can verify this by looking at the server access log files located here:

   - Solaris Java Enterprise System installation:

     `/var/opt/SUNWappserver/nodeagents/`nodeagent_name`/i1/logs/access/server_access_log`

     `/var/opt/SUNWappserver/nodeagents/`nodeagent_name`/i2/logs/access/server_access_log`

   - Linux Java Enterprise System installation:

     `/var/opt/sun/appserver/nodeagents/`nodeagent_name`/i1/logs/access/server_access_log`

     `/var/opt/sun/appserver/nodeagents/`nodeagent_name`/i2/logs/access/server_access_log`

   - Windows Java Enterprise System installation:

     install-dir`\nodeagents\`nodeagent_name`\i1\logs\access\server_access_log`

     install-dir`\nodeagents\`nodeagent_name`\i2\logs\access\server_access_log`

   - Stand-alone Application Server installations:

     install-dir`/nodeagents/`nodeagent_name`/i1/logs/access/server_access_log`

     install-dir`/nodeagents/`nodeagent_name`/i2/logs/access/server_access_log`

5. Add a name and value pair (`Name=Name Value=Duke`) for storing in `HttpSession`.

6. Click the “Add to Session Data” button.

7. Verify that the session data was added

##### Next Steps

In this section you created an instance to use as a load balancer and set up a load balancing configuration. You also verified load balancing.

To configure and verify HTTP session failover, continue to Chapter 2, Quick Start for Setting Up High Availability Failover. Otherwise continue on to Cleaning Up.

- Previous: Deploying an Application
- Next: Cleaning Up

- © 2010, Oracle Corporation and/or its affiliates