Configure multiple Tomcat instances on single server

Learn how to set up several different instances of an application on your Tomcat server, and manipulate each of these instances independently. This article will explain to you how to configure multiple Tomcat instances on single server.

Many times we come to a situation where we need to modify the server configuration such that it is specific to an application. And if we got more than one such applications and we want each application to have it’s own defined configuration options, then it needs some sort of configuration. In this tutorial, I am going to discuss the changes you should make to have different instances of tomcat for each application.

multiple-apache-tomcat-instances

Install JAVA

[[email protected] ~]# sudo yum install java-1.8.0-openjdk.x86_64

[[email protected] ~]# sudo java -version
openjdk version “1.8.0_141”
OpenJDK Runtime Environment (build 1.8.0_141-b16)
OpenJDK 64-Bit Server VM (build 25.141-b16, mixed mode)

[[email protected] ~]# sudo cd /opt/; wget http://www-us.apache.org/dist/tomcat/tomcat-8/v8.0.52/bin/apache-tomcat-8.0.52.tar.gz
[[email protected] ~]# sudo tar -zxvf apache-tomcat-8.0.52.tar.gz
[[email protected] ~]# sudo cd apache-tomcat-8.0.52

Create the subdirectories of each instance directory.

[[email protected] ~]# sudo mkdir /var/lib/apache-tomcat-8.0.52

[[email protected] ~]# sudo mkdir -p /var/lib/apache-tomcat-8.0.52/{custserv,prodserv}

[[email protected] ~]# sudo mkdir -p /var/lib/apache-tomcat-8.0.52/custserv/{logs,conf,temp,webapps,work}
[[email protected] ~]# sudo mkdir -p /var/lib/apache-tomcat-8.0.52/prodserv/{logs,conf,temp,webapps,work}

Copy the conf directory from the default Tomcat installation into each instance.

[[email protected] ~]# sudo cp -r /opt/apache-tomcat-8.0.52/conf/* /var/lib/apache-tomcat-8.0.52/custserv/conf
[[email protected] ~]# sudo cp -r /opt/apache-tomcat-8.0.52/conf/* /var/lib/apache-tomcat-8.0.52/prodserv/conf

Create symbolic links to the default bin and lib locations.

[[email protected] ~]# sudo ln -s /opt/apache-tomcat-8.0.52/bin /var/lib/apache-tomcat-8.0.52/custserv/bin
[[email protected] ~]# sudo ln -s /opt/apache-tomcat-8.0.52/bin /var/lib/apache-tomcat-8.0.52/prodserv/bin

[[email protected] ~]# sudo ln -s /opt/apache-tomcat-8.0.52/lib /var/lib/apache-tomcat-8.0.52/custserv/lib
[[email protected] ~]# sudo ln -s /opt/apache-tomcat-8.0.52/lib /var/lib/apache-tomcat-8.0.52/prodserv/lib

Create /usr/lib/systemd/system/tomcat-custserv.service and /usr/lib/systemd/system/tomcat-prodserv.service to configure the environment for each instance.

[[email protected] ~]# sudo vi /usr/lib/systemd/system/tomcat-custserv.service
[Unit]
Description=Apache Tomcat Web Application Container
After=syslog.target network.target

[Service]
Type=forking

Environment=JAVA_HOME=/usr/lib/jvm/jre
Environment=CATALINA_PID=/var/lib/apache-tomcat-8.0.52/custserv/temp/tomcat.pid
Environment=CATALINA_HOME=/var/lib/apache-tomcat-8.0.52/custserv
Environment=CATALINA_BASE=/var/lib/apache-tomcat-8.0.52/custserv
Environment='CATALINA_OPTS=-Xms512M -Xmx1024M -server -XX:+UseParallelGC'
Environment='JAVA_OPTS=-Djava.awt.headless=true -Djava.security.egd=file:/dev/./urandom'

ExecStart=/var/lib/apache-tomcat-8.0.52/custserv/bin/startup.sh
ExecStop=/bin/kill -15 $MAINPID

User=tomcat
Group=tomcat

[Install]
WantedBy=multi-user.target

Update same configuration for /usr/lib/systemd/system/tomcat-prodserv.service and change path.

Make sure user has created and updated for tomcat folders.

[[email protected] ~]# sudo useradd -s /bin/nologin -g tomcat -d /opt/apache-tomcat-8.0.52 tomcat
[[email protected] ~]# sudo cd /opt/apache-tomcat-8.0.52
[[email protected] ~]# sudo chgrp -R tomcat conf
[[email protected] ~]# sudo chown -R tomcat logs/ temp/ webapps/ work/ bin/ /lib

Change default ports in prodserv/conf/server.xml and make sure ports 8080,8005,8009 are not conflicting with custserv/conf/server.xml

[[email protected] ~]# sudo systemctl start tomcat-prodserv.service
[[email protected] ~]# sudo systemctl start tomcat-custserv.service
 

Increase Root Volume Size in Google Cloud Instances

You can resize persistent disks when your instances require more storage space and attach multiple secondary disks only when you need to separate your data into unique partitions. Increase root volume size in Google Cloud Instances in the console or GCloud command line without instance reboot.

Now, to the cases where you will need to extend the actual running instance, this disk would be known as a ‘root persistent disk’. You can resize disks at any time, regardless of whether the disk is attached to a running instance.

google cloud disk modify

 

How to increase the root volume size in Google Cloud without reboot

Login to the GCP console

Step 1

  • Go to the Disks page to see a list of persistent disks in your project.
  • GO TO THE DISKS PAGE
  • Click the name of the disk that you want to resize.

or

  • Go to Compute Engine-> VM instances page
  • Click your Instance
  • Click Root Volume under Boot disk and local disks section

Step 2

At the top of the disk details page, click Edit.

In the Size field, enter the new size for your disk. Boot disks and secondary disks with MBR partition tables can resize only up to 2 TB.

Step 3

At the bottom of the disk details page, click Save to apply your changes to the disk.

After you resize the disk, you must resize the file system so that the operating system can access the additional space.

Gcloud Command

In the gcloud tool, use the disks resize command and specify the –size flag with the desired disk size in GB.

gcloud compute disks resize [DISK_NAME] –size [DISK_SIZE]

where:

[DISK_NAME] is the name of the disk that you are resizing.
[DISK_SIZE] is the new size for the disk in GB. Boot disks and secondary disks with MBR partition tables can resize only up to 2 TB.
After you resize the disk, you must resize the file system so that the operating system can access the additional space.

Example 
# gcloud compute disks resize my-instance --size 100GB

Step 4

Login to the Instance

Check with disk size using fdisk -l

# sudo fdisk -l

If the disk that you want to resize has a partition table, you must grow the partition before you resize the file system. Use growpart to resize your image partition.

# sudo yum install cloud-init cloud-utils-growpart

sudo growpart /dev/[DISK_ID] [PARTITION_NUMBER]

# sudo growpart /dev/sda 1

Step 5

we used resize2fs because /dev/sda1 was using ext4 file system format. In the case of XFS, we will use xfs_growfs command instead of resize2fs.

resize2fs can be used to resize ext2, ext3, and ext4 file systems

sudo resize2fs /dev/[DISK_ID][PARTITION_NUMBER]

# sudo resize2fs /dev/sda1

If you are using XFS file system, then use below xfs_growfs command

sudo xfs_growfs /dev/[DISK_ID][PARTITION_NUMBER]

# sudo xfs_growfs /dev/sda1

You have done, use the df command to verify that the file system is resized.

# sudo df -h /dev/sda1
 

vCenter services stop, start, or status command in windows

If your vCenter is on a Windows host, then you must use Windows commands to restart the VMware vSphere web client service in vCenter. There are many ways to restart services in vcenter and troubleshooting purposes, it is required to restart the VMware vCenter Server services such as VMware Virtual Center Server, VMware vSphere Web Client, or VMware Directory Service.

VMware vCenter Server 6.x, VMware recommends to use the vSphere Web Client or Service Control command-line tool to stop, start, or restart vCenter Server. These commands are verified with VMware vCenter Server 6.x and steps to restarting the vSphere web client service in Windows.

How to stop, start and status vCenter services command in Windows server.

1. Log in as an administrator to the windows server that is running vCenter Server.

2. Open an administrative command prompt.
Run this command to change to vCenter Server and/or Platform Services Controller installation directory:

3. Go to default vCenter server installation path

cd C:\Program Files\VMware\vCenter Server\bin

Run this command to list vCenter Server and/or Platform Services Controller services

./service-control --list
 

Run this command to view the current status of vCenter Server and/or Platform Services Controller services:

./service-control --status

Run this command to stop all services:

./service-control --stop --all

Run this command to start all services:

./service-control --start --all

To perform a dry run of the command, This displays the actions that command run without executing the actions.

./service-control --start --all --dry-run

Run this command to stop a specific service:

service-control --stop servicename

Run this command to start a specific service:

service-control --start servicename

 

Example

service commands

vCenter service control commands

 

Errors:

A server error occurred.
[500] SSO error: Cannot connect to the VMware Component Manager https://vcentera.vmusketeers.local/cm/sdk?hostid=8f7ab780-bbd2-11e7-8d6f-2cc260268d52
Check the vSphere Web Client server logs for details.

 

vCenter Errors

To solve this you have to restart the Component Manager and the Web client from the command line, both which are unavailable from the services.msc.

Go to the installation path of your vCenter server:

cd C:\Program Files\VMware\vCenter Server\bin

stop and start Component Manager services

service-control --stop VMwareComponentManager
service-control --start VMwareComponentManager

stop and start the web client service:

service-control --stop vspherewebclientsvc
service-control --start vspherewebclientsvc