This article will explain how to install tomcat webserver as a extension of Apache 2 webserver. Apache webserver will act as a proxy for n tomcat instances installed in the machine. This articles is written based on the need of installing multiple instances of tomcat webserver in the one physical server. We assume there are existing Apache 2 webserver already installed in the machine, JVM has been installed as well. We also assume that we have registered domain softonelogic.com and our aim is installing tomcat for main softonelogic.com and sub domain funds.softonelogic.com.
The steps required for tomcat installation will be divided into 2 section, setting in Apache 2 side and setting in the tomcat side
Apache 2 setting
Register new domain name in to Apache 2
Register domain to the DNS system in the machine. In our lab, we are using tinydns to handle DNS in our machine. The command to add new domain in the apache are:
# cd /service/tinydns/root
# ./add-ns new-domain.org 192.168.0.2
# make
Replace new-domain.org with the desired domain. In our case will be funds.softonelogic.com. And change the 192.168.0.2 to the correct IP Address.
The /var/tinydns/root/data file is where all your DNS entries are stored. There are a number of scripts inside /var/tinydns/root that will help you add various lines to your data file. Whenever you edit the data file, run ’make’ in the root dir to "compile" the data file into a tinydns readable file.
You can use the scripts to add nameservers, aliases, childns servers, mx servers, and regular hosts. After using the scripts, and seeing what they do, you might be comfortable enough to edit the data file directly. Hence, to make it easy, adding a new domain quickly, just add these 4 lines to the end of the file:1
.new-domain.org:203.211.130.159:a:259200
.new-domain.org:203.211.130.158:b:259200
@new-domain.org:203.211.130.159:a::86400
+new-domain.org:203.211.130.159:86400
Virtual Host
To add a new virtual host, create a file with .conf extension in the /etc/apache2/vhosts.d/ you can copy one of the conf file in it to get started with, and then edit the file. The conf file is self explanatory. Please refer to Apache Virtual Host Documentation8 for more details. If you specify the ErrorLog in the conf file, make sure you create an empty file for the log.
Once you have finished editing the conf file, restart the apache.
Edit /etc/apache2/workers.properties.
This file contains the details about how each process is linked to Tomcat by defining workers that communicate through the ajpv13 protocol. Refer to the Workers HowTo
for more detail.
(a) Add more worker entry in the worker.list. This variable is comma separated without containing any space. Tip: You can add it right away after the equal sign (=) since the order doesn’t matter.
worker.list=ajpnewapp,ajpexistingapp
(b) Add at least the type, host and port properties of the worker somewhere after the worker.list. The combination of host and port values between applications must not be the same. The easiest way is to use different host (or ip) and use the same port.
worker.ajpnewapp .type=ajp13
worker.ajpnewapp .host=127.0.0.n*
worker.ajpnewapp .port=8009
* Where n is a number between 1 to 254. Your system has been pre-set to all these IPs.
Create the apache vhost configuration file in the /etc/apache2/vhosts.d/
The difference with the regular apache vhost is that you need to specify the mount point. This is where JkMount parameter comes in.
JkMount /a_folder* ajpnewapp
Restart the apache.
Tomcat Setting
Unzip compressed tomcat folder in the path /opt/
rename the unzipped file to any name that easy to remember, example apache-tomcat-softonelogic-portal
mv apache-tomcat-6.0.20 apache-tomcat-softonelogic-portal
Since the tomcat will be run by non-root user, we need to change the ownership of the tomcat.
syntax: chown -[option] [user].[group] target-folder-ownership-to-be-changed
Assume we have user called softonelogic and group tomcat, so the command will be
chown -R softonelogic.tomcat apache-tomcat-softonelogic-portal
-R recursively
Then create symbolic link the apache-tomcat-softonelogic-portal at the /home directory or any other directory you want. This article, the symbolic link will be placed at /home/softonelogic
login as user softonelogic
ln -s /opt/apache-tomcat-softonelogic-portal ./tomcat
to test the symbolic link
ls -l
You should see tomcat->/opt/apache-tomcat-softonelogic-portal
Next, go to tomcat directory at /opt/ go to directory conf, edit the server.xml
vi server.xml
Fine <Connector by using command
/Connector
in command mode of vi
Find the Connector that define the AJP 1.3 connector. Compare the address and port with the worker.properties
Next, run the tomcat. Go to the bin folder in the tomcat, run
./startup.sh
You should get the tomcat homepage or any other defined page.