Tomcat Server Cloud Hosting with Unipace PaaS

By 17. 7. 2018 July 29th, 2018 Java

Given the fact that Java hosting occupies one of the leading positions in creating web applications, it is understandable the widespread popularity of Apache Tomcat among developers. Due to recently gathered statistics, 28.9% of Jelastic PaaS users also prefer Tomcat server for deploying their projects.

Considering the demand, we decided to get into more details on how to install Tomcat latest version, configure this Java web server and its load balancing, deploy the application and improve Tomcat security on the Unispace Cloud PaaS.

Create Tomcat Server

The Platform-as-a-Service provides easy steps for Tomcat installation.

1. Register and log into PaaS dashboard.

2. Click New Environment button.

3. Pick desirable Tomcat version for your application server as shown in the picture below. The cloud platform allows you to use Apache Tomcat versions starting from 6 up to the latest Tomcat 9 depending on your application requirements. All you need is to choose from the versions available in the drop-down list:

Once the environment is created, you have ready to use Tomcat application server installed there. To check if Tomcat is running, click Open in browser button next to the web server in the environment.

The server is properly installed, so welcome Tomcat web server page is displayed in your browser.

The application server is operating in a separate container (node) which is an isolated virtualized instance, provisioned for a software stack. The container has its own private IP and unique DNS record.

Change Tomcat Version

If you need to change the version of your installed server, you can do this any time without losing data or configurations.

Just click the Redeploy containers button next to the Apache Tomcat server node.

Select a new Tomcat version (e.g. Tomcat 8) in the appeared dialog and confirm the change.

Tomcat Clustering and Scaling

Our PaaS can automatically scale application, both vertically and horizontally, as well as set up Tomcat cluster making hosting truly flexible.

Automatic Vertical Scaling

Automatic vertical scaling is made possible by Jelastic ability to dynamically change the amount of allocated resources (RAM and CPU) for a server according to its current demands, with no manual intervention required. This feature guarantees you never overpay for unused resources and saves your time due to eliminating the necessity of handling the load-related adjustments or architectural changes.

In order to set up automatic resource consumption by your Tomcat server, open the environment topology wizard and specify the upper scaling limit of cloudlets (each equals to 128 MiB and 400 MHz) with the slider located at the top:

Your application will work within these limits reducing resource consumption when the load is down or increasing them when the load is up. Thus, you only pay for the resources that are actually consumed. For more information, please refer to the documentation about automatic vertical scaling.

Manual Horizontal Scaling

For adding extra Tomcat servers manually, just click Change environment topology:

Then press “+” button in the wizard and add the required number of instances.

The maximum number of the same-type servers within a single environment layer depends on a particular hosting provider settings (usually this limit stands for 16 nodes and can be adjusted by sending a request to support). You can check the exact value within the Quotas & Pricing > Account Limits information frame.

As you can see, when you add extra servers, Apache Tomcat load balancing is enabled automatically. Load Balancer represents frontend which receives all the incoming requests and evenly distributes them between backends – application servers.

Please, find more details about manual horizontal scaling in the documentation.

Automatic Horizontal Scaling

Automatic horizontal scaling can be implemented by means of tunable triggers, which monitor the changes in application’s load and increase or decrease the number of nodes due to them.

To configure a trigger for the automatic horizontal scaling use Settings button for the desired environment.

Navigate to the Monitoring > Auto Horizontal Scaling section.

By pressing Add button you can configure the triggers for specific stacks and resources (CPU, RAM, Network, Disk) within your environment separately. Just specify the conditions of scaling and apply changes.

Please, find more details about automatic horizontal scaling in the corresponding document.

Automatic Tomcat Clustering

The embedded application server clustering feature provides replication of sessions between pairs of nodes and eliminates the necessity of additional software or Memcached usage for increasing application availability.

You can get multicast replication between pairs of Tomcat servers without any manual configurations. If one of the instances fails, the users who were on that instance are automatically moved to the other instance in the cluster.

To activate Tomcat clustering, you just need to turn on High-Availability button within environment wizard as shown in the picture below:

Deploy Application to Tomcat Environment

There are several options on how to deploy Java application to the Tomcat environment but the most common way is by means of Deployment Manager.

1. Open Deployment Manager from the taskbar of Jelastic dashboard and click Upload button.

2. Browse to your local file (or use URL to your project) and upload it. The Deployment Manager supports .WAR, .ZIP or .EAR formats.

3. Select your package in the list and click Deploy to button:

4. Choose the appropriate environment, specify context (or leave default ROOT value) and start deploying the application.

Note: At this step, you can also add deployment hooks to execute your custom scripts before or after the application deployment.

5. When the process is completed, you can see your project within deployments of the environment.

There are more options for deploying your application to Tomcat, for example, via Git/SVN using Maven build node. For more information refer to the Deployment Guide.

Tomcat Configurations

In this chapter we will cover some settings and features that help to optimize your work with Tomcat web server.

Environment Variables

In order to make your application more portable and flexible, you can use environment variables instead of specifying the required values in the application code each time. Jelastic PaaS provides you with a number of Tomcat default environment variables for the commonly used directories. You can find them in the table below:

VariableValue (server path)
user.home/opt/tomcat/temp
user.dir/opt/tomcat/temp
java.io.tmpdir/opt/tomcat/temp
java.home/usr/java/latest
catalina.home/opt/tomcat/
catalina.base/opt/tomcat/

Along with default ones, you can add custom Tomcat environment variables which are stored in /opt/tomcat/conf/variables.conf file.

Configuration Files

The Tomcat configuration files are available for editing right from the dashboard. In order to access them, press the Config button next to the Tomcat server.

Then use available file manager for browsing.

In the table below you can find the names and paths to the core Apache Tomcat configuration files.

FolderFilePath
confcatalina.policy
catalina.properties
context.xml
jaspic-providers.xml
jaspic-providers.xsd
jelastic-ha.xml
jelastic-ssl.xml
logging.properties
server.xml
tomcat-env.sh
tomcat-users.xml
tomcat-users.xsd
variables.conf
web.xml
/opt/tomcat/conf
temp/opt/tomcat/temp
webapps/opt/tomcat/webapps
latest/usr/java/latest
lib/opt/tomcat/lib
crontomcat/var/spool/cron
keys/var/lib/jelastic/keys

Please, find more about Tomcat server configurations in the linked document.

 

Leave a Reply