Tomcat Server Cloud Hosting with Jelastic PaaS

13

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 Jelastic PaaS.

Create Tomcat Server

Jelastic Platform as a Service provides easy steps for Tomcat installation.

1. Register and log into the dashboard at our Jelastic PaaS platform.

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.

1334-1-tomcat-latest-version

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.

1334-1-java-application-server-tomcat-open-in-browser

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

1334-1-tomcat-clustering

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.

1334-1-tomcat-web-server-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.

1334-1-apache-tomcat-redeploy-containers

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

1334-1-deploy-available-tomcat-versions

Tomcat Clustering and Scaling

Jelastic PaaS can automatically scale applications, both vertically and horizontally, as well as set up a 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 MB and 400 MHz) with the slider located at the top.

1334-1-tomcat-server-configuration-vertical-scaling

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 the Change environment topology button.

1334-1-change-tomcat-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 default platform 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.

1334-1-tomcat-horizontal-scaling

As you can see, when you add extra servers, Apache Tomcat load balancing is enabled automatically. This Load Balancer represents the front-end which receives all the incoming requests and evenly distributes them between back-ends – 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 automatic horizontal scaling, use the Settings button for the desired environment.

1334-1-tomcat-cloud-hosting-settings

Navigate to the Monitoring > Auto Horizontal Scaling section.

1334-1-apache-tomcat-auto-horizontal-scaling

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

1334-1-apache-tomcat-triggers-for-automatic-horizontal-scaling

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

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.

1334-1-apache-tomcat-server-load-balancing-and-scaling

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

1334-1-apache-tomcat-high-availability

Deploy Application to Tomcat Environment

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

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

1334-1-tomcat-web-server-archive-deploy

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

1334-1-deploy-war-file-in-tomcat

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

1334-1-tomcat-java-application-server-deploy-java-project

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

1334-1-deploy-archive-to-tomcat-server

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.

1334-1-deploy-java-application-within-tomcat-server

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 part 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.

1334-1-tomcat-default-environment-variables

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.

1334-1-how-to-configure-tomcat-server

Then use the available file manager for browsing.

1334-1-tomcat-configuration-file-manager

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

1334-1-core-tomcat-configuration-files

Please, find more details about Tomcat server configurations in the documentation.

Tomcat Security Settings
In order to restrict access to your project deployed to Tomcat server, we recommend two possible solutions: set up user authentication and deny access to your web application for the certain client IP addresses. The detailed instruction is described in the article on how to Secure Tomcat Hosting.

One more way to ensure the security of your applications is using Container Firewall feature. It lets control your nodes availability both from inside and outside of the platform. Configure Tomcat container firewall using the information from the Container Firewall Management documentation.

1334-1-tomcat-security-firewall-configuration

Multiple Domains on Single Tomcat Server
You can set up multiple domain names on the Tomcat server in order to increase the usability, efficiency and scalability of your application, as well as save your costs without having to configure separate instances. For this, make some minor adjustments within Tomcat configuration files as described in the documentation about multiple domains.

1334-1-multiple-domains-on-single-tomcat-server

As you can see, Jelastic PaaS makes Tomcat hosting easy and flexible. The cloud platform provides a wide range of already predefined settings for you not to bother about routine tasks, and at the same time leaves the server fully customizable for specific complex configurations. Get started with effortless Tomcat cloud hosting from our Jelastic PaaS platform and enjoy the benefits in a turnkey package.

As always, feel free to ask for a help from Jelastic technical expert assistance at Stackoverflow in case you have any questions about configuring and scaling your Tomcat environment.
SOURCEJelastic, Inc.