Apache Tomcat is an open-source application server maintained by the Apache community. It is one of the most popular solutions for hosting Java applications due to its ease-of-use and lightweight yet versatile functionality. However, if you run the projects based on Jakarta EE 8 (or higher), you may be interested to use TomEE server with built-in required enterprise technology that isn’t found in Tomcat.
Due to the extreme popularity of these stacks globally and within Virtuozzo Application Management in particular, we’ve decided to share tips on how to install automatically clustered Tomcat and TomEE servers to achieve a highly available solution that can efficiently serve a large number of users, handle high traffic, and remain reliable.
Before starting the Tomcat cluster automation package development, our team gathered requirements that this solution should achieve, or, as we call them, the challenges:
- Efficient processing of a large number of requests (performance)
- Horizontal scalability support in case of workload growth
- Zero downtime in case of failures (fault tolerance)
Now, with these goals in mind, we’ve analyzed numerous successful examples online to create a solution that can be seamlessly integrated into the platform.
Below, you can find out more about the implementation of Tomcat and TomEE auto-clustering in Virtuozzo Application Management, as well as how to get these clusters up and running.
Tomcat/TomEE Auto-Cluster Installation
There are multiple tutorials on how to set up Tomcat clusters, but the configuration is relatively complex and includes many tweaks, which makes it seem like a lot. However, with the Auto-Clustering feature, we went further and automated the whole process, making it as simple as flipping a switch.
1. Log in to your Virtuozzo Application Management account and click New Environment at the top.

2. In the open topology wizard, choose Tomcat or TomEE from Java application servers and turn on the Auto-Clustering switcher. Make any other necessary adjustments and click Create.

3. In a few minutes, your Tomcat cluster will appear within the dashboard.

Tomcat/TomEE Cluster Topology and Specifics
The topology of the highly available Tomcat cluster is straightforward and efficient, without any unnecessary elements to complicate it or reduce performance. The default cluster topology looks like below:

Such topology ensures that performance and fault tolerance requirements are met. NGINX load balancer in front of the cluster handles workload distribution. Also, it automatically registers any changes in the cluster, reacting to the compute nodes’ addition, deletion, or failure. You can follow our load-balancing test tutorial to evaluate workload distribution.
In general, Auto-Clustering creates a simple TCP cluster that connects multiple Tomcat servers via TCP protocol. In our configuration, we automatically detect session changes and propagate them to other Tomcat instances in the cluster. Once nodes connect to each other, they establish a set of sender and receiver socket channels. Session replication data is transferred via these channels. The implementation provides session replication, context attribute replication, and cluster-wide deployment of WAR files. Also, various interceptors are configured to intercept data transfers.
You can refer to the official documentation for general information on Tomcat clustering and session replication. In our Auto-Clustering implementation, all the cluster-specific changes and optimizations are gathered in the dedicated /opt/tomcat/conf/tomcat-cluster.xml configuration file for convenience:

If necessary, you can check and adjust cluster settings via the built-in Configuration File Manager.
- A simple TCP cluster option is used with the channelSendOptions=“6” (channelSendOptions=“sync,use_ack”) parameter. The sender will block completion of the current request until all receiving nodes have acknowledged receipt and processing of the message.
- Static membership is used for discovering the cluster peers – the whole and exact list of all the cluster members is listed on every node. Members are added to the configuration by their IP addresses and unique IDs.

- Interconnection is done through port 4004 using the TCP protocol – an appropriate rule is added to the firewall during the cluster configuration.
- In the /opt/tomcat/conf/context.xml configuration file, the org.apache.catalina.ha.context.ReplicatedContext class is used for the context implementation to provide replication.

All these settings are done automatically during creation and do not require manual maintenance during the cluster lifecycle.
Tomcat/TomEE Cluster Horizontal Scaling
It’s evident that high availability is demanded almost for any application, so it is a great benefit that you can automate cluster nodes’ addition/deletion based on the configurable scaling triggers to match the variable load.
1. Go to Settings > Auto Horizontal Scaling for your Tomcat / TomEE cluster environment.

2. Set up scaling triggers for the required resources (RAM, CPU, Network, Disk).
Note: Keep in mind that the minimum count of worker nodes in the cluster is 2, so set up the scale limit respectively (as in the image above).
So, if you are looking for a reliable Tomcat hosting to keep your projects scalable and highly available, Virtuozzo Application Management auto-clustering is an excellent solution to hop on with ease. No need to struggle with routine and complex configuration tasks, just let Virtuozzo do all the work for you and get a guaranteed result in a matter of minutes.