Setting up a Tomcat Web Cluster
Introduction
This guide is intended to step you through the process of installing and deploying your web application in a Terracotta Sessions cluster.
The architecture of a Terracotta-enabled, high-availability web application looks like this:
The load balancer parcels out HTTP requests from the Internet to each application server. Ideally, the load balancer would use HTTP session affinity to route all requests that corresponded to the same HTTP session to the same application server to maximize the locality of reference of the clustered HTTP session data, although with a Terracotta-enabled web application, any application server can process any request.
The application servers run your web application and the Terracotta client software. More application servers may be deployed as needed to handle additional request load, but, for simplicity, this guide will assume there are three active application servers.
The Terracotta server acts as the data store for HTTP session data and coordinates access by the application servers to that session data.
Basic Steps
Process of getting this system installed, configured, and running is as follows:
- download relevant software, including Terracotta, Java, and the application server
- setup and install software on the cluster
- install software
- prepare a load balancer
- Install Terracotta configuration on the server
- Configure the application server to run with Terracotta enabled
- Start the Terracotta server
- Start the application server instances
- Start the load balancer
- Test
Download
Install
- Install Java on all machines
- Install Terracotta on all machines
- Install Tomcat on all of the application server machines
- Install the web application on all of the application server machines
Generating a Boot Jar
You may need to generate a boot jar on the application server machines for the version of the JVM that you are using on your application servers. That can be done using the make-boot-jar.sh script in the Terracotta kit. It will also be created for you automatically as necessary if you use the dso-env.sh script as discussed in the next section.
For more information on what the boot jar is and how to create it, see the following:
- XXX: There's no documentation on the make-dso-bootjar script. Need to add it and xref it.
- Concept and Architecture Guide
Configuring Terracotta to Work With Your Application
If you already have a working Terracotta configuration for your application, copy the configuration file to the Terracotta server machine.
If you don't yet have a Terracotta configuration for your application, you can build one by hand or you can use the Terracotta Sessions Configurator to help you build one.
See the following for more information on configuring Terracotta for your application:
- Sessions Quick Start
- Sessions Configurator Reference Guide
- Configuration Guide and Reference
Start the Terracotta Server
Once the Terracotta configuration file is on the Terracotta server machine, start the Terracotta server on the Terracotta server machine.
To start the Terracotta server, use the start-tc-server.sh script. You should see output similar to this:
See the Tools Guide for more information on the start-tc-server script.
Configure Tomcat
Configure Tomcat to run with Terracotta enabled. This is as simple as adding some elements to the JAVA_OPTS environment variable. The easiest way to do this is to execute the dso-env script and add the output to the JAVA_OPTS environment variable prior to calling any of the Tomcat startup scripts. Here's a shell script snippet that you can either put directly into catalina.sh or write as a standalone environment script:
Here's a sample script with actual values plugged in:
Here's a sample of how to use it:
Here's what the JAVA_OPTS environment variable looks like after the script is run:
Start the Tomcat Servers
Once the JAVA_OPTS environment variable is set properly, you can use either the startup.sh script or the catalina.sh script to start Tomcat.
Here's an example of the entire process, using the sample environment script described above.
If Terracotta is set up correctly, you should see something like this in the catalina.out log file:
If you don't see the terracotta INFO lines, you probably don't have the JAVA_OPTS environment variable set or passed in to Tomcat propertly.
Start Tomcat in this way on all of the application server machines.
Configure and Start the Load Balancer
In a production environment, you should use a production quality hardware or software load balancer. For testing purposes, Terracotta comes with a simple TCP proxy that may be used like a load balancer. You should not use this TCP proxy in a production environment.
Here's a sample script to start the TCP proxy:
Here's a version of the script with the terracotta installation directory and the web hosts filled in:
To run the TCP proxy, execute the script on the load balancer machine:
Functional Testing
<insert description>
Load Testing
<caveats about load testing>