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

[centos@localhost ~]# sudo yum install java-1.8.0-openjdk.x86_64
[centos@localhost ~]# 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)

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

Create the subdirectories of each instance directory.

[centos@localhost ~]# sudo mkdir /var/lib/apache-tomcat-8.0.52

[centos@localhost ~]# sudo mkdir -p /var/lib/apache-tomcat-8.0.52/{custserv,prodserv}

[centos@localhost ~]# sudo mkdir -p /var/lib/apache-tomcat-8.0.52/custserv/{logs,conf,temp,webapps,work}
[centos@localhost ~]# 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.

[centos@localhost ~]# sudo cp -r /opt/apache-tomcat-8.0.52/conf/* /var/lib/apache-tomcat-8.0.52/custserv/conf
[centos@localhost ~]# 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.

[centos@localhost ~]# sudo ln -s /opt/apache-tomcat-8.0.52/bin /var/lib/apache-tomcat-8.0.52/custserv/bin
[centos@localhost ~]# sudo ln -s /opt/apache-tomcat-8.0.52/bin /var/lib/apache-tomcat-8.0.52/prodserv/bin

[centos@localhost ~]# sudo ln -s /opt/apache-tomcat-8.0.52/lib /var/lib/apache-tomcat-8.0.52/custserv/lib
[centos@localhost ~]# sudo ln -s /opt/apache-tomcat-8.0.52/lib /var/lib/apache-tomcat-8.0.52/prodserv/lib

 

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

Now, we are going to create the user and group of Apache, for that we are going to execute the following:

[centos@localhost ~]# sudo groupadd tomcat 

[centos@localhost ~]# sudo useradd -s /bin/false -g tomcat -d /opt/apache-tomcat-8.0.52/ tomcat

 

Now, let’s change the owner of the tomcat directory to the user and tomcat group:

[centos@localhost ~]# sudo chown -R tomcat.tomcat  /opt/apache-tomcat-8.0.52/  /var/lib/apache-tomcat-8.0.52/custserv/ /var/lib/apache-tomcat-8.0.52/prodserv

Start Tomcat Services

we will execute a test to make sure that everything is working the way we want, for this we will execute the following:

[centos@localhost ~]# sudo cd /var/lib/apache-tomcat-8.0.52/prodserv/bin

[centos@localhost ~]# sudo ./startup.sh

We can see that everything is correct in the “Tomcat started” line. Tomcat runs by default on port 8080.

[centos@localhost ~]# sudo cd /var/lib/apache-tomcat-8.0.52/custserv/bin

[centos@localhost ~]# sudo ./startup.sh

We have changed the default tomcat port to 8081.

Enable ports 8080 and 8081 on your Firewall.

Create a sample page on your webapps directory /var/lib/apache-tomcat-8.0.52/custserv/webapps/sample and access Apache Tomcat service to validate its installation.

http://<host>:8080/sample and http://<host>:8081/sample

 

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