![]() | |
Sun Java System Application Server Enterprise Edition 7 2004Q2 Getting Started Guide |
Chapter 3
Enterprise Features Configuration TutorialThis chapter includes a tutorial to set up and use features in your Sun Java System Application Server environment. This chapter contains the following sections:
Preparing to Use the TutorialsThis guide walks you through setting up a clustered environment, deploying an application to it, and testing the load balancing and HTTP session persistence features with the application. It includes two tutorials: the Enterprise Features Configuration Tutorial, which covers configuring the cluster and load balancer, and the Cluster JSP Sample Application Tutorial, which covers deploying the application and verifying that load balancing and session persistence work.
This section contains the following topics:
Installation Requirements
The installation configuration suggested here is a basic, single-machine configuration for use with this guide. It is not necessarily the right configuration for your environment. You need to carefully consider your needs before deploying the Sun Java System Application Server in your environment. For more information on recommended configurations, see the Sun Java System Application Server System Deployment Guide.
For the purposes of doing the tutorials included in this book, use the following basic configuration:
Required Steps Before Using the Tutorials
Before you start the tutorials, you must have already completed the following steps.
Overview of Tutorial StepsThe following table summarizes the steps required in the tutorials to configure your system, deploy an application, and verify the enterprise features. The left column describes the step, and the right column gives the location of the instructions needed to perform the step.
Table 3-2 Steps for Using Tutorials
Step
Location of Instructions
1. Start the Admin Server and application server instances.
2. Verify that the Admin Server and application server instances are running.
“Verifying Server Start-up” on page 41
3. Create a loadbalancer.xml file.
4. Set up a cluster in loadbalancer.xml.
5. Configure the load balancer in theloadbalancer.xml file.
6. Verify your loadbalancer.xml file against the sample loadbalancer.xml file.
7. Deploy the sample application to the instances in your cluster using cladmin.
8. Start the application server instances using cladmin.
9. Verify that you deployed your application successfully.
10. Add the sample application to the cluster information in loadbalancer.xml.
11. Apply changes and restart the web server.
Applying Configuration Changes and Restarting the Web Server
12. Run the sample.
13. Verify load balancing.
14. Verify session persistence.
15. Quiesce a server instance.
Starting the ServerBefore you can use the tutorials in this guide, you need to start the Admin Server and all the application server instances in your cluster. Your Sun Java System Web Server should also be running.
The most straightforward way to start the Admin Server and the application server instances when all the server instances and the Admin Server are in a single domain is to use the asadmin utility’s start-domain command.
This section contains the following topics:
Setting the PATH Variable
Before running asadmin, for added convenience you can set your PATH variable.
Setting the PATH variable allows you to run asadmin, cladmin, and the asant (the application server’s Ant utility) from the command line at any location. Add the following directory to your PATH environment variable:
If you add the Application Server's bin directory to your login profile it is automatically added to your environment's PATH setting during login.
For example, add the following to your .cshrc file:
set path=( /opt/SUNWAppserver7/bin)
After you have saved the file, source it:
source .cshrc
You can test your change by executing the asadmin utility at the command prompt. Type:
asadmin
The following result should appear:
Use "exit" to exit and "help" for online help
asadmin>
Type exit to quit the asadmin interface.
If the command is not found:
If you do not set the PATH environment variable, you can still run the commands and utilities from the directory where they are located (install_dir/bin), for example:
cd /opt/SUNWappserver7/bin
./asadmin
Running asadmin start-domain
To start the Admin Server and all the application server instances in it, run the asadmin start-domain command. At the command prompt, type:
asadmin start-domain --domain domain1
domain1 is the default domain configured when you installed the server and ran the clsetup command.
Note
In the configuration described in this guide, all the instances are in the same domain. If the server instances are not in the same domain, you need to run asadmin start-domain for every domain you plan to use. Once you have created a cluster, you can also use cladmin start-instance to start all the instances in a cluster. For information on cladmin syntax, see The cladmin Command Syntax.
Use the following command to stop both the Admin Server and the application server instances of the initially configured domain:
asadmin stop-domain --domain domain1
where domain1 is the name of the administrative domain defined during installation of the application server.
For a full list of asadmin commands, see the asadmin help. To access help, at the command prompt, type:
asadmin
Your prompt should change to the asadmin prompt, if you have set your PATH variable. Type help at the prompt to see a list of all asadmin commands. To get help on a specific asadmin command, at the asadmin prompt type the command name followed by the help option. For example:
asadmin> start-domain --help
Verifying Server Start-upAfter starting the Admin Server and application server instances, verify that they have started successfully, as described in the following sections:
Verifying Admin Server Start-up
You can verify that the Admin Server started by accessing the Sun Java System Application Server’s Administration interface, or by viewing the Admin Server’s event log, as described in the following sections:
Accessing the Administration Interface
To verify that the Admin Server started correctly, you can access the Sun Java System Application Server’s web-based Administration interface. You can use this interface to administer the Sun Java System Application server instances, though for clustered instances it is more convenient and less error-prone to use the cladmin command.
Note
For a list of browsers compatible with the Administration interface, see the Sun Java System Application Server Platform Summary.
To access the Administration interface, follow these steps:
- Sign into the Administration interface using the administration user name and password supplied during product installation.
Tip
Port not accessible? If the connection was refused when attempting to contact the Admin Server's Administration interface, it is likely that the Admin Server is not running. Check your start-up procedures and the content of the Admin Server's log file to determine the reason why the server is not running. For instructions on viewing the log file, see Viewing the Admin Server’s Event Log.
Viewing the Admin Server’s Event Log
You can also look in your Admin Server event log for a server start-up message. To open and view the event log file, follow these steps:
You can also use the tail -f command to view messages in the server log.
tail -f server.log
The -f option leaves the tail command running so new log entries are displayed as they are written to the file.
You can also access the Admin Server and the application server instance event log files through the Administration interface. Click the server name in the left pane (Admin Server or the application server instance) and click the Logging tab in the right pane.
For more information, see the Sun Java System Application Server Administration Guide.
Verifying Start-up of Server Instances
After running clsetup, you should have two server instances in domain1: server1 and server2. This section discusses two ways to verify that those instances exist, and to verify that they are running:
Verifying Instances using asadmin
To verify, use the asadmin list-instances command:
- Launch asadmin by typing asadmin at the command prompt:
asadmin
Your prompt becomes asadmin>
- Use the list-instances command at the asadmin prompt to show all current instances.
list-instances
This command lists the instances and whether or not they are currently running. You should see two running instances, server1 and server2.
Verifying Instances by Accessing the HTTP Server
Another method to determine whether or not an application server instance has started is to access the instance's HTTP server welcome page through a web browser.
Using a browser, access the following location:
http://server_instance:server_instance_port_number
where server_instance_port_number is the HTTP server port number specified during installation or server instance creation.
If the application server instance is up and running normally, you should see the default HTTP server welcome page in your browser:
Creating the loadbalancer.xml FileAfter you have installed the components, run clsetup, and started the Admin Server, you are ready to configure your installation. The first step is to create a cluster.
Since the configuration of the cluster for this guide uses one load balancer plug-in, you must define the cluster in the web server’s loadbalancer.xml configuration file. This file belongs in the configuration file directory of your web server. The loadbalancer.xml file does not exist by default. You must create it.
To create the loadbalancer.xml file, follow these steps:
- Find the sample loadbalancer.xml file, called loadbalancer.xml.example, located in your web server’s config directory.
By default, this directory is:
webserver_install_dir/servers/https-server_name/config
- Save a copy of loadbalancer.xml.example as loadbalancer.xml.
You will edit this copy to include information for your environment, including information to create a cluster and allow load balancing to work.
An example loadbalancer.xml file is shown in Code Example 3-1.
Code Example 3-1 The loadbalancer.xml.example file
<!DOCTYPE loadbalancer PUBLIC "-//Sun Microsystems Inc.//DTD Sun ONE Application Server 7.0//EN" "sun-loadbalancer_1_1.dtd">
<loadbalancer>
<cluster name="cluster1">
<instance name="instance1" enabled="true" disable-timeout-in-minutes="60" listeners="<REPLACE_WITH_LISTENER1> <REPLACE_WITH_LISTENER2>"/>
<web-module context-root="/abc" enabled="true" disable-timeout-in-minutes="60" enabled="true" />
<health-checker url="/" interval-in-seconds="10" timeout-in-seconds="30" />
</cluster>
<property name="reload-poll-interval-in-seconds" value="60"/>
<property name="response-timeout-in-seconds" value="30"/>
<property name="https-routing" value="true"/>
<property name="require-monitor-data" value="false"/>
</loadbalancer>
Notice the example file refers to the sun-loadbalancer_1_1.dtd, also found in the web server’s config directory.
Adding a Cluster to the loadbalancer.xml FileNext you need to add a cluster, for this tutorial called cluster1, to your loadbalancer.xml file. The cluster includes two Sun Java System Application Servers or server instances.
Edit your newly-created loadbalancer.xml to include the instances and the URLs to the HTTP listeners:
- Go to your web server’s config directory and open loadbalancer.xml using a text editor.
Notice that the sample file already includes a cluster called cluster1.
<cluster name=“cluster1”>
- Add the two application server instances that you created with clsetup, server1 and server2, to cluster1.
Create an instance subelement of the cluster for each of the instances. The instances need to be enabled (enabled=true). You also need to add the URLs of the HTTP listeners. In the case of the default server instance (server1) and the second server instance you have added (server2), there is one HTTP listener each. You could have more in a different environment.
The sample loadbalancer.xml file contains the following lines that you can edit:
<instance name="instance1" enabled="true" disable-timeout-in-minutes="60" listeners="<REPLACE_WITH_LISTENER1> <REPLACE_WITH_LISTENER2>"/>
- Replace “instance1” with “server1” for this tutorial.
- Replace <REPLACE_WITH_LISTENER1> with the listener URL for your server instance, for example:
http://test.sun.com:81.
The listener URL consists of the server name and port. If the listener has security enabled, the URL starts with HTTPS. If the listener is not secure, the URL starts with HTTP. To find information on the HTTP listener for each Sun Java System Application Server instance:
- Save your changes to loadbalancer.xml. Your file now has a line similar to the following:
<instance name="server1" enabled="true" disable-timeout-in-minutes="60" listeners="http://test.sun.com:81"/>
- Change the disable-timeout-in-minutes value to 5.
The disable timeout in minutes is the instance-level quiescing period, in which you allow time for sessions to terminate for a server instance. The server is still running, but no requests that would result in new sessions are sent to it, though the server does accept requests that are for existing sessions. In the real world, this number would be quite high. The time specified in the example is 60 minutes. However, because the tutorial requires you to shut down the server, in this tutorial you are asked to set the timeout artificially low.
<instance name="server1" enabled="true" disable-timeout-in-minutes="5" listeners="http://test.sun.com:81"/>
- Add a second instance to the cluster element. You can do that by copying the line above and pasting it below the existing line, then changing the server name and the listener URL. For example:
<instance name="server2" enabled="true" disable-timeout-in-minutes="5" listeners="http://test.sun.com:82"/>
- Save your changes.
So far, your loadbalancer.xml file should look similar to the following:
<!DOCTYPE loadbalancer PUBLIC "-//Sun Microsystems Inc.//DTD Sun ONE Application Server 7.0//EN" "sun-loadbalancer_1_1.dtd">
<loadbalancer>
<cluster name="cluster1">
<instance name="server1" enabled="true" disable-timeout-in-minutes="5" listeners="http://test.sun.com:81"/>
<instance name="server2" enabled="true" disable-timeout-in-minutes="5" listeners="http://test.sun.com:82"/>
<web-module context-root="/abc" enabled="true" disable-timeout-in-minutes="60" enabled="true" />
<health-checker url="/" interval-in-seconds="10" timeout-in-seconds="30" />
</cluster>
<property name="reload-poll-interval-in-seconds" value="60"/>
<property name="response-timeout-in-seconds" value="30"/>
<property name="https-routing" value="true"/>
<property name="require-monitor-data" value="false"/>
</loadbalancer>
You’ll add information associated with the deployed application (the sample line that begins with “web-module”) during a later procedure.
Configuring Load BalancingAfter creating the loadbalancer.xml file and adding a cluster, edit the loadbalancer.xml file to include the load balancer settings.
This section contains the following topics:
Configuring the Health Checker
If you enable the health checker, the load balancer periodically checks all the Sun Java System Application Server instances that are flagged as unhealthy to see whether they have become healthy. If an application server instance that was marked as unhealthy has become healthy, the instance is added to the list of healthy instances, and requests are once more routed to it.
You configure the health checker in the health-checker element in loadbalancer.xml. You configure the listener URL that the health checker pings to see if the server is running, as well as how often the health checker pings the server and how long the health checker waits for a response before marking the server as unhealthy.
The sample loadbalancer.xml file includes the following line, which you do not need to edit in order to complete the tasks in this guide.
health-checker url="/" interval-in-seconds="10" timeout-in-seconds="30" />
- The health-checker url specifies the URL to ping to determine whether the server instance is healthy (that is, whether it is responding). The example shows a URL of "/". For example, if your listener URL is http://www.example.com:80, then a health checker URL of "/" pings http://www.example.com:80/. For the purposes of this guide, leave the value "/".
- The interval-in-seconds attribute specifies the interval between load balancer health checks. You do not need to change the value from the default 10.
- The timeout-in-seconds attribute specifies the interval within which the load balancer must receive a response from the pinged server instance in order for the server instance to be considered healthy. You do not need to change the value from the default 30.
For example, using the default values, the health checker follows these steps:
- The health checker pings the unhealthy listeners using the health checker URL.
- For each listener, it waits 30 seconds (timeout-in-seconds) for a response.
If the server responds within 30 seconds, the listener is marked healthy. If the server does not respond, the health checker considers the server to still be unhealthy.
- The health checker waits ten seconds (the interval-in-seconds) before starting another cycle of health checks.
If there are no unhealthy instances when the health checker starts, it skips the first two steps.
Enabling Load Balancer Monitoring
The load balancer plug-in uses the web server logging mechanism to write log messages. When monitoring is enabled, the following information is logged to the web server log file:
- Start/stop information for every request
- Failover request information when a request is failed over from an unhealthy to a healthy instance
- List of unhealthy instances logged at the end of every health checker cycle
To monitor load balancing, you need to:
To enable monitoring in loadbalancer.xml, follow these steps:
In addition, to change the default web server log level, follow these steps:
Turn on the Sun Java System Web Server’s verbose logging:
- Go to the web server’s config directory. If you installed your Sun Java System Web Server in the default location, the path will be:
/web_server_install_dir/https-server_name/config
- Open the magnus.conf file for editing.
- Add the following line:
LogVerbose on
- Save the changes to the file.
- Restart the web server to apply the changes.
Other Load Balancer Properties
The example loadbalancer.xml contains the following additional load balancer properties:
<property name="reload-poll-interval-in-seconds" value="60"/>
<property name="response-timeout-in-seconds" value="30"/>
<property name="https-routing" value="true"/>
For this tutorial, you do not need to change the default values. For more information on these properties, see the following sections:
Dynamic Reconfiguration using the Reload Poll Interval
After the initial configuration, the load balancer plug-in detects changes to its configuration and loads them automatically. It detects changes by looking at the time stamp on the loadbalancer.xml file. If the time stamp has changed, the load balancer automatically reconfigures itself. The reload poll interval specifies how often the load balancer checks the time stamp.
Response Timeout
The response timeout designates how long the server waits for the instance to respond to a request. After the specified number of seconds, if the instance has not responded an error message is sent to the browser.
HTTPS Routing
When HTTPS routing is disabled, HTTPS listeners listed in the loadbalancer.xml file are ignored, and only HTTP listeners are used for load balancing. When HTTPS routing is enabled, HTTPS requests are failed over only to HTTPS ports.
Sample loadbalancer.xml FileThe following sample loadbalancer.xml file includes one cluster of two instances. Check the syntax of your loadbalancer.xml file against this example.
Code Example 3-2 The loadbalancer.xml File
<!DOCTYPE loadbalancer PUBLIC "-//Sun Microsystems Inc.//DTD Sun ONE Application Server 7.0//EN" "sun-loadbalancer_1_1.dtd">
<loadbalancer>
<cluster name="cluster1">
<instance name="server1" enabled="true" disable-timeout-in-minutes="5"
listeners="http://test.sun.com:81"/>
<instance name="server2" enabled="true" disable-timeout-in-minutes="5"
listeners="http://test.sun.com:82"/>
<web-module context-root="/abc" enabled="true" disable-timeout-in-minutes="60" enabled="true" />
<health-checker url="/" interval-in-seconds="10" timeout-in-seconds="30" />
</cluster>
<property name="reload-poll-interval-in-seconds" value="60"/>
<property name="response-timeout-in-seconds" value="30"/>
<property name="https-routing" value="true"/>
<property name="require-monitor-data" value="true"/>
</loadbalancer>
Now that you have configured the enterprise features, you can deploy and run the sample application. Continue on to Chapter 4, "Cluster JSP Sample Application Tutorial."