Quick Start Tomcat User Guide

Introduction

The document is a guide to demonstrate the Tomcat capabilities of the product – to install Apache Tomcat, to configure the application server and deploy a sample application.

It uses the in-built Hypersonic in memory database, but in a live scenario, the data would be persisted to a RDBMS such as Oracle or DB2. Details of how to configure the application to use these databases can be found in the installation guide.

The instructions in this demonstration uses a remote agent to connect to the target server (in this case localhost). However a more likely scenario is to connect to a target server using the RapidDeploy in-built SSH client. Details of how to do this can be found in the MidVision RapidDeploy User Guide.

This user guide is supplemented by the MidVision on-line media including quick-start video guides, all of which can be accessed from www.midvision.com

This document explains how to:

  • Initially create a Tomcat 7 binary installation.
  • Deploy and undeploy a simple war file to the installation
  • Take a snapshot of this environment.
  • Detect configuration drift and compare environment configurations
  • Create a template from the snapshot, and promote this to create further downstream environments based on this initial “golden” environment. This promote uses the RapidDeploy Snapshot/Template/Promote framework and doesn’t rely on any scripts.

In the case of a brown field site, the initial Tomcat install may not be required, and we would start by deploying to an existing environment.

Once these projects are implemented, creating further downstream Tomcat installations  should take minutes to set up and install. Deploying configuation to these installations is a simple matter of cloning (copying) the environment configurations already set up and deploying them either alone or with bundled code. Ear file builds can be performed by your usual process or through RD (using continuous integration if required) and the packages deployed through RD or automatically using the RapidDeploy command line API.

Windows/Linux: This demo project has been configured for use on Windows. However it is quite easy to convert to Linux. Look out for “Linux Configuration Tip:” throughout this guide.

Download the Tomcat binary Zip file

Since this is a large file it is worth beginning the download (if you don’t already have the media to hand) for use in a later step when we create the package.

Downloads can be obtained from the apache WebSite. The latest current version is:  http://apache.mirror.rbftpnetworks.com/tomcat/tomcat-7/v7.0.23/bin/apache-tomcat-7.0.23.zip

Later on this can be moved into your “build store”.

Download and install the RapidDeploy application

Download the latest RapidDeploy from one of the link below, check you select the correct version of your operating system:

Unzip the file to an installation directory, e.g. “/midvision” for linux or “C:\midvision” for windows.

This will create a directory called midvision. This location will now be referred to as $MV_HOME, e.g. “/midvision” for linux or “C:\midvision” for windows.

Edit the remote agent orchestration file.

If you plan to use a remote agent to run the deployments on the target servers then you will need to edit the remoting server file, putting in the host name of the server it will accept deployment requests from. Find the hostname of the machine you have installed the application to then type hostname from a command prompt.

e.g:

Windows Linux
C:\Users\user1>hostname [root@cloud ~]# hostname
user1-MV cloud.server.com

Goto $MV_HOME/remoting and edit the file midvision-remoting-server.xml. On line 43 change line:

<resource type=”auth.servers”>gui@localhost</resource>

To gui@hostname e.g.

<resource type=”auth.servers”>gui@user1-MV</resource>

Start the server and the remoting agent.

Goto $MV_HOME/bin and the run the start-up scripts to start the web app and the remote agent.

Windows Linux
start-web-app.bat start-web-app.sh
start-remoting-server.bat start-remoting-server.sh

Wait until you see “INFO: Server startup in“ in the output logs of the tomcat console (which opens as a separate window in Windows environments), alternatively check the $MV_HOME/logs/rapiddeploy-web-app.log for the line ”RapidDeploy web application is started” and ensure there are no errors, then go to http://localhost:9090/MidVision in a web browser. (Replace localhost with your linux server hostname/IP as appropriate)

At the login page enter the default username “mvadmin” and the default password “mvadmin” then click “Login”.  You will then be presented with a license page. Request a trial license from MidVision by emailing licensing@midvision.com. Once you have been emailed the license, enter the values on the screen and accept the EULA.

Note: This demo uses a Hypersonic in-memory database. This means if the web application process is killed from the Task Manager or a “kill” command then all data will be lost. To ensure that your data is stored to a file when the application is stopped, run the “stop-web-app.sh” or “stop-web-app.bat” script which is in the $MV_HOME/bin directory.

Use the Plugin Manager to Install the Tomcat Demo

Ensure the web application is started. Go to “Help / Plugin Manager” the “Available Plugins / Patches” tab. Click the “Install” button on the “Tomcat Example App” Plugin and then “Yes” to confirm, the project files will be downloaded to the $MV_HOME/projects directory. Once the download is complete the plugin will appear in the “Installed Plugins / Patches” tab.

Select Tomcat from Available Plugins

Alternatively, download the latest zip file from http://www.midvision.co.uk/wordpress/dnld/plugins/demo_projects_310/rapiddeploy-demo-projects-3.1.0-tomcat.zip and unzip in the root of your RapidDeploy installation (MV_HOME).

Configure the Resources.

Please note. If you are running RapidDeploy against an oracle database, a Sql script can be found in $MV_HOME/plugins/Tomcat Example App/<VERSION> that will create all of the following resources for you. You will still need to edit each project and replace “MV_HOME” with the correct path to the RapidDeploy install directory, and run a discovery on each project by editing it and then clicking “Discover” and clicking “Ok” to confirm.

Create the Projects

Go to “Resources/Projects/Add Project” then enter the following information (remember to change $MV_HOME with the actual location).

Field Value
Name TOMCAT_BINARY_INSTALL
Description TOMCAT_BINARY_INSTALL desc
Owner mvadmin
Deployment Type binaryInstall
Collection Type TOMCAT_70
Log Directory $MV_HOME/logs
Project Root Directory $MV_HOME/projects/TOMCAT_BINARY_INSTALL
Properties Directory $MV_HOME/projects/TOMCAT_BINARY_INSTALL/j2ee/config
Build Store $MV_HOME/buildstore
Promotion Store $MV_HOME/promotionstore
Deployment package search string apache-tomcat
Properties file identifier conf
Master in Database False(not selected)

TOMCAT_BINARY_INSTALL Project (Click to Enlarge)

Then click “Create”. Now add another project.

Field Value
Name TOMCAT_DEPLOY
Description TOMCAT_DEPLOY desc
Owner mvadmin
Deployment Type codeDeploy
Collection Type TOMCAT_70
Log Directory $MV_HOME/logs
Project Root Directory $MV_HOME/projects/TOMCAT_DEPLOY
Properties Directory $MV_HOME/projects/TOMCAT_DEPLOY/j2ee/config
Build Store $MV_HOME/buildstore
Promotion Store $MV_HOME/promotionstore
Deployment package search string TOMCAT_DEPLOY
Properties file identifier dict
Master in Database False(Not Selected)

Then click “Save”.

TOMCAT_DEPLOY (Click to Enlarge)

Now edit the project named TOMCAT_DEPLOY and then click “Discover” and click “Ok” to confirm.

This will search the project configuration directory and look for the environment definition files and create any servers, environment, instances and deployment components it finds in to the application database. The environments are defined by the file names defined in the project properties directory. The structure of the environment filename is this:

SERVER.ENVIRONMENT.INSTANCE.APPLICATION

In a Tomcat context this relates to:

SERVER.TOMCAT_INSTALL.TOMCAT_INSTANCE.WEB_APPLICATION

As the project TOMCAT_DEPLOY has a pre-configured environment definition, the discovery will create a new server named “tcserver01”, a new environment named “tcenvironment01” and a new instance named “tcinstance01”. We will later configure the connection details to the server so we can install Tomcat and also we will configure the environment and the instance.

Now add another project – the final one!

Field Value
Name TOMCAT_UNDEPLOY
Description TOMCAT_UNDEPLOY desc
Owner mvadmin
Deployment Type codeDeploy
Collection Type TOMCAT_70
Log Directory $MV_HOME/logs
Project Root Directory $MV_HOME/projects/TOMCAT_UNDEPLOY
Properties Directory $MV_HOME/projects/TOMCAT_UNDEPLOY/j2ee/config
Build Store $MV_HOME/buildstore
Promotion Store $MV_HOME/promotionstore
Deployment package search string TOMCAT_UNDEPLOY
Properties file identifier conf
Master in Database False(Not Selected)

Now edit the project named TOMCAT_UNDEPLOY and then click “Discover” and click “Ok” to confirm.

Orchestration Panel

It is worth looking at the project orchestration panel at this point. The Examples projects have preconfigured orchestrations, but these may be amended as desired to add or change individual task actions (from the list of around 150 on the left hand side) for this deployment. Open the TOMCAT_DEPLOY project. In the example below, the TOMCAT tree item is opened, displaying tomcat tasks. Task actions are environment independent actions that run in sequence whenever this deployment project is run (when any deployment package based on this project is deployed).

Take a look at the orchestrations for the other projects.

Orchestration Panel for the TOMCAT_DEPLOY Project (Click to Enlarge)

Linux Configuration Tip: The orchestrations for all of these Tomcat projects will work correctly out of the box for Windows and Linux.

Configure the Server

Goto “Resources/Targets/Servers” then edit the server named tcserver01. Edit these fields (remember to change $MV_HOME with the actual location, you will also need to ensure the Build Store directory exists on your target):

Field Value
General Tab
Display Name tcserver01
Hostname localhost
Build Store: $MV_HOME/remotebuildstore
OS Type: <Select your OS type>
Version: <Set your OS version>
Allow Deployments: True
Connection timeout (ms): 2000000
Remoting Tab
Agent Enabled for deployments: True
Agent Enabled for discovery: True
Remote Agent Port: 20000
Agent Path:

Then click “Save”.

Click edit on the server named “tcserver01”” and then click “Test Agent” and click “Yes” to confirm. The application will then check it can communicate with the remote agent. You should see the following output:


Test Success
The test connection completed successfully.

If the test was successful.

Configure the Tomcat Installation Directory for TOMCAT_BINARY_INSTALL

In this section we define the file path that Tomcat will be installed into on the target server. Subsequent installations on this or other servers can be based on the same TOMCAT_BINARY_INSTALL project by defining additional installations.

Go to “Resources / Targets / Installations” then click “Add Environment Installation”.

Enter these fields. Remember to change $TC_HOME with the actual location you want to install Tomcat to, the default value for this demonstration example is:

Linux: “/midvision/apps/Tomcat”

Windows: “/midvision/apps/Tomcat”

Field Value
Installation Path $TC_HOME
Server tcserver01
Project TOMCAT_BINARY_INSTALL

Then click “Create”.

No  Environment Variables are required for this installation.

Installation for the TOMCAT_BINARY_INSTALL project on tcserver01

Install Tomcat

Now you have defined a server and an installation directory you can install Tomcat to your target server at the location specified. Using the Tomcat binary file downloaded at the start of this document, add it to the $MV_HOME/buildstore directory otherwise you will not have a package to install.

Now start the install job. Go to “Job / New Job”. Select the project TOMCAT_BINARY_INSTALL, open the server tree and select the EnvironmentInstallation you created in the earlier step, then click “Next”.

New Tomcat Binary Job Selection (Click to Enlarge)

Select the version (which is the file you have copied to the buildstore). Then select “Skip to finish” and then click “Next”. Click “Execute Request” then click “Yes” to confirm. Tomcat will start to install in the target server. You can click the “View Progress” button on the job and you should see the deployment log files.

In this binary installation the following tasks are executed:

  1. Check there is at least 1024Mb of free space on the target server at the install directory.
  2. Check the directory is writable
  3. Install Tomcat to the directory.

When the job has finished you will see the text:


2011-12-21 12:01:34,902 [Thread-12] INFO  com.midvision.rapiddeploy.utilities.exec.LocalScriptRunner - 100%
2011-12-21 12:05:48,173 [Thread-12] DEBUG com.midvision.rapiddeploy.utilities.exec.LocalScriptRunner - Closing streams...
2011-12-21 12:05:48,174 [Thread-12] INFO  com.midvision.rapiddeploy.utilities.exec.LocalScriptRunner - Execution finished, exit code 0
2011-12-21 12:05:48,214 [Thread-12] INFO  com.midvision.rapiddeploy.orchestration.tasks - Task [ TomcatBinaryInstallTask ]...Fixing permissions...
2011-12-21 12:05:48,214 [Thread-12] INFO  com.midvision.rapiddeploy.orchestration.tasks - Task [ TomcatBinaryInstallTask ]...Finished... 2011-12-21 12:05:48,214 [Thread-12] INFO  com.midvision.rapiddeploy.orchestration.tasks - Work Unit ... Complete ...
2011-12-21 12:05:48,214 [Thread-12] INFO  com.midvision.rapiddeploy.orchestration.tasks - Finishing generic-batch...
2011-12-21 12:05:48,214 [Thread-12] DEBUG com.midvision.rapiddeploy.orchestration.tasks - Return Code = 0 Completed RapidDeploy Deployment Request

You can go to “Jobs / Previous Jobs” and you can download and view the log file of the complete deployment.

Install a sample Web Application

Check configuration

If you have installed Tomcat in a location other than c:/midvision/apps/Tomcat (Windows) or /midvision/apps/Tomcat  (Linux), please change the data dictionary in the TOMCAT_DEPLOY project  as follows:

Goto “Environment/ Edit/Promote” then select the TOMCAT_DEPLOY project from the drop down.

Edit/Promote panel for the TOMCAT_DEPLOY project

Click the edit button next to the environment. From the menu panel, select Dictionary/Data Dictionary:

TOMCAT_DEPLOY Initial Environment Data Dictionary

Amend the values to match your chosen Tomcat install.

Create a deployment package

Goto “Resources/Software Management/Packages” then select the TOMCAT_DEPLOY project from the drop down.

Click “Add Package Wizard” button and enter “TOMCAT_DEPLOY_001″ as the package name. Check the “Skip to Finish” checkbox and click next.

Click “Create This Deployment Package” on the final tab.

Tomcat initial deployment package (Click to Enlarge)

We have now packaged our project directory, including a war file and all the required configuration to create the target application. This package can be used to create our environment. It could also be used to create additional environments by simply cloning the configuration of the first environment. Instructions can be found in the RapidDeploy User Guide. For our purposes, creating one environment using this method is sufficient.

Deploy the Package (TOMCAT_DEPLOY).

Go to “Jobs / New Job” then select the project TOMCAT_DEPLOY then open the server, environment, instance and select the application “examplesWebApp” then click “Next”

New Tomcat Configuration Deployment Selection (Click to Enlarge)

Now select the version, which is the deployment package you have just created, select “Skip to finish” then click “Next”. Click “Execute Request” then click “Yes” to confirm. This will start to deploy the package.

The steps taken in this deployment are:

The following steps will:

  1. Stop the Tomcat Server (not necessary but added to show functionality)
  2. Copy a tomcat-users.xml into the installation. This is to give the “tomcat” user the ability to do deployments via the manager application.
  3. Change the default ports. We move the ports from 8080 etc to different ports. THis is because it is often the case that existing applications (tomcat, Oracle etc) are already using ports 8080. This is an example of an environment specific search replace task.
  4. Start the Tomcat Server
  5. Stop the Tomcat examplesWebApp application (if it is running)
  6. Deploy the examplesWebApp to the target
  7. Start the Tomcat examplesWebApp application (if it is running)
  8. Check for memory leaks.

Once the job has completed you can view the deployment log file from the Previous Jobs section.

As the job executes you see the progress and can view logs in real time. If multiple concurrent jobs are executing, each can be observed in the same way.

Executing TOMCAT_DEPLOY Job

Check the Deployment

The following Url: http://localhost:8780/examplesWebApp/ should return the standard “Hello” message from the installed application.

Log into and explore the Tomcat install by accessing the Admin Web UI at: http://localhost:8780

Log in to the manager application with:

Username: tomcat

Password: tomcat

Undeploy the Package (TOMCAT_UNDEPLOY).

Follow the steps for deploying a package, but this time use the TOMCAT_UNDEPLY project:

  • Check the configuration of the environment in the TOMCAT_UNDEPLOY project
  • Create a (first) deployment package for this project
  • Look at the orchestration file for the TOMCAT_UNDEPLOY project to see what tasks are performed.
  • Deploy the package
  • Confirm that you can no longer access the examplesWebApp.

Snapshot a Tomcat Server Profile

Now Tomcat has been installed we can take a snapshot of the default configuration to use as a control when configuration changes are made.  When we use RapidDeploy to take a snapshot of Tomcat we use the tcserver01 connection (agent or Ssh) to connect to the server and retrieve all the configuration settings.

Configure the Environment (Tomcat installation)

Go to “Resources / Targets / Environments” edit the environment named “tcenvironment01”. Enter the following values (remember to change $TC_HOME with the actual location):

Field Value
General Tab
Display Name tcenvironment01
Parent Server display name tcserver01
Owner mvadmin
Software Product: Tomcat 7
Environment Type: Unknown
Software Version: 7.0.0.23
Binary Path: $TC_HOME e.g./midvision/apps/Tomcat/apache-tomcat-7.0.23/conf (Windows,  Linux)
Connectivity Tab
Admin Port:
Connection String:
Environment Admin Username:
Environment Admin Password:

Then click save.

Configure the Instance

Go to “Resources / Targets / Instances” edit the instance named “DEFAULTServer”.  This is normally the logical name of  a cluster or stand alone server to deploy to. Enter the following values:

Field Value
General Tab
Instance Name tcinstance01
Parent Environment name: tcenvironment01
Parent Server display name tcserver01
Owner mvadmin
Collection Type: TOMCAT_70
Software Version: 7
Binary Path:
Allow deployments True
Connectivity Tab
Hostname
Port:
Username:
Password:
Alias:

Then click Save.

Take a Snapshot

Now we will take a snapshot of the version of Tomcat that has just been installed. It is a “Golden Image” version of the configuration, which will be used to compare against in the future.

Go to “Resources / Targets / Environments” edit the environment named “tcenvironment01″.

Then click “Snapshot” then click “Yes” to confirm. The snapshot will be requested. You can go to “Jobs / Executing Jobs” and see the log output of the snapshot.

Tomcat Environment tcenvironment01 - Take Snapshot

Create a configure project

Now add another project.

Field Value
Name TOMCAT_CONFIGURE
Description TOMCAT_CONFIGURE desc
Owner mvadmin
Deployment Type codeDeploy
Collection Type TOMCAT_70
Log Directory $MV_HOME/logs
Project Root Directory $MV_HOME/projects/TOMCAT_CONFIGURE
Properties Directory $MV_HOME/projects/TOMCAT_CONFIGURE/j2ee/config
Build Store $MV_HOME/buildstore
Promotion Store $MV_HOME/promotionstore
Deployment package search string TOMCAT_CONFIGURE
Properties file identifier dict
Master in Database False(Not Selected)

Then click “Save”. Run discovery on this project as you did for the deploy projects.

Convert the Snapshot to a template

Go to “Environment / Edit/Promote”, Select the  “TOMCAT_CONFIGURE” project.

Now click “Create Snapshot from template”.

  • Accept the defaults on the “Configuration Directory” tab.
  • On the “Snapshot Selection” tab, choose the snapshot you just requested.
  • On the “Name” tab, enter “tcinstance01″ for the instance, and “examplesWebApp1″ for the application.
  • On the “Create Template” tab we can add dictionary items as placeholders in the configuration. We will do this later so skip on to the final tab.
  • Click “Create This Environment”.

Name Tab in the Snapshot to Template Wizard

Edit the template directly

Now go into “Environment/ Edit/Promote. Select the TOMCAT_CONFIGURE project. Edit examplesWebApp environment.

Edit Template for the first environment in the TOMCAT_CONFIGURE project.

Select “Resources / Files”. Navigate down to server.xml and add the maxPostSize attribute to the connector as in the following diagram. (maxPostSize=”@@MAX_POST_SIZE@@”).

Setting maxPostSize in server.xml

Save the configuration.

Now go to “Dictionary / Data Dictionary “and add a dictionary item for this environment @@MAX_POST_SIZE@@ = 0

We set maxPostSize to “0″ giving an unlimited maxPostSize. This allows us to now use this dictionary item to set maxPostSize to different values in different tomcat environments.

Save MAX_POST_SIZE to the data dictionary

Save the configuration.

Create a new Package

As done before, use the package creation wizard to create a package for the TOMCAT_CONFIGURE project.

Deploy the Package (TOMCAT_CONFIGURE).

This next project will demonstrate how to use the configuration based tasks to configure Tomcat.

Go to “Jobs / New Job” then select the project TOMCAT_CONFIGURE then open the server, environment, instance and select the application “examplesWebApp” then click “Next”.

Now select the version, which is the deployment package you have just created, select “Skip to finish” then click “Next”. Click “Execute Request” then click “Yes” to confirm. This will start to deploy the package.

The steps taken in this deployment are:

The following steps will:

  1. Deploy the package to the target
  2. Update the configuration to add “maxPostSize”

Once the job has completed you can view the deployment log file from the Previous Jobs section.

Take another Snapshot

Take another snapshot of the “tcenvironment01″, as per the previous snapshot instructions.

Compare Snapshots

Go to “Environment / Environment Comparison”.

On the “Snapshot Comparison” panel, select for the left side and right side to compare, the two snapshots taken previously.

Set the “Comparison Context size (optional 1-50):” to 5, to display 5 rows of context around each difference, and select compare:

Snapshot settings for the TOMCAT_CONFIGURE example

The snapshot shows the difference (macPostSize):

Comparison of Snapshots for the TOMCAT_CONFIGURE example

Result

We have shown above how to install a Tomcat binary instance and deploy war files and configuration changes to this instance.

We can now “clone” the environments configured in the projects we have created to may further downstream environments.

In theory we do not need to create any further projects. We can use the projects created in the examples above to create many more binary installs and deploy our war file to them. Additional war files can be added to these projects, or new projects created for them.

Once we are settled on our optimum tomcat configuration, we can deploy this to all of our created binary installs, changing any environment specific items we choose on a per environment basis by use of the data dictionary.

Leave a Reply