Install and Integrate Tomcat 8.5 with Apache Centos 7

Integrate Tomcat 8.5
Integrate Tomcat 8.5

Integrate Tomcat 8.5 with Apache

In this tutorial, I am going to provide you the steps to integrate Tomcat 8.5 with Apache on Centos 7. 

Before starting with integration steps make sure you have gone through basic installation steps of Apache on Centos 7.

First, install the Apache on Centos 7, Please check below URL for installation steps.

Read: Compile Apache using source code on Centos 7

OVERVIEW

Tomcat8.5.X :

Apache Tomcat is an open-source implementation of the Java Servlet, JavaServer Pages, Java Expression Language and WebSocket technologies. Tomcat provides a “pure Java” HTTP web server environment in which Java code can run.

Let’s understand some important points about Tomcat8.5.X,

Start upgrading the Tomcat older version from 8.0 to 8.5 or the latest. Why?

  • Because Tomcat team have announced the end of life date for Tomcat 8.0.x. Users of Tomcat 8.0.x should plan to upgrade before Tomcat 8.0.x reaches the end of life.
  • The Apache Tomcat team announces that support for Apache Tomcat 8.0.x will end on 30 June 2018.
  • You will get more information about Tomcat8.0.X on “https://tomcat.apache.org/tomcat-80-eol.html

I hope you go through the Apache compilation steps.

Steps to Install & Integrate TOMCAT 8.5 with Apache

  1. Download Tomcat 8.5 & Extract with tar
  • cd /opt/
  • wget http://www-us.apache.org/dist/tomcat/tomcat-8/v8.5.32/bin/apache-tomcat-8.5.32.tar.gz
  • tar -xvf apache-tomcat-8.5.32.tar.gz
  • mv apache-tomcat-8.5.32 tomcat8532

Once extracted the tar file, you will find below directories present under the extracted tar,

$ cd /opt/tomcat8532

$ ls -al

bin/

conf/
lib/
LICENSE
logs/
NOTICE
RELEASE-NOTES
RUNNING.txt
temp/
webapps/
work/

2. INSTALL MOD_JK.SO AND ENABLE MOD_JK MODULE

mod_jk is an Apache httpd module used to make tomcat applications interact with an httpd server.

$ cd /opt/

$ wget http://www-us.apache.org/dist/tomcat/tomcat-connectors/jk/tomcat-connectors-1.2.43-src.tar.gz

$ tar -xvf tomcat-connectors-1.2.43-src.tar.gz

$ cd /opt/tomcat-connectors-1.2.43-src/native

$ ./configure --with-apxs=/DATA/Apache2433/bin/apxs
$ make
$ make install

$ ll /DATA/Apache2433/modules/mod_jk.so [check mod_jk.so module is present or not after installation]

$ vim /DATA/Apache2433/conf/httpd.conf

# Add this line after the last LoadModule line

LoadModule jk_module modules/mod_jk.so

# Add below lines end of conf file

JkWorkersFile conf/workers.properties
# Where to put jk shared memory
JkShmFile logs/mod_jk.shm
# Where to put jk logs
JkLogFile logs/mod_jk.log
# Set the jk log level [debug/error/info]
JkLogLevel info
# Select the timestamp log format
JkLogStampFormat "[%a %b %d %H:%M:%S %Y] "
#JkRequestLogFormat "%w %V %T"
#JkEnvVar SSL_CLIENT_V_START worker1

Save and Exit apache configuration file.

Make sure to create the below folders to store the shared memory of the module:

$ mkdir -p /var/run/mod_jk
$ chown apache:apache /var/run/mod_jk

if you do not create above directory it will throw below error,

[jk:emerg] [pid 19134:tid 140117029619584] Initializing shm:/var/run/httpd/mod_jk.shm.19134 errno=2. Unable to start due to shared memory failure.

Reload the Apache Server and Check Module is Enabled properly,

$ /DATA/Apache2433/bin/apachectl graceful    [Reload Apache service]
$ /DATA/Apache2433/bin/apachectl -M      [To Check mod_jk module enabled or not]

jk_module (shared)    [Module enabled successfully]

3. CONFIGURE WORKERS.PROPERTIES

$ vim /DATA/Apache2433/conf/workers.properties

# Add below lines,

worker.list=tomcat8532 [tomcat85 is the jvmroute for tomcat which used to route request through apache server]
##############################################
worker.tomcat8532.type=ajp13
worker.tomcat8532.host=localhost
worker.tomcat8532.port=8009
worker.tomcat8532.lbfactor=1

4. CONFIGURE VIRTUAL HOST FOR TOMCAT APPLICATION IN APACHE,

Here we need to add virtualhost entry in apache so that we can be able to access the tomcat on browser,

$ vim /DATA/Apache2433/conf/extra/httpd-vhosts.conf

# Add below virtualhost entry and remove dummy host entry

<VirtualHost *:80>
ServerName localhost
LogFormat "%h %l %u %t \"%r\" %>s %b \"%{Referer}i\" \"%{User-agent}i\"" combined
CustomLog /var/log/httpd/app1_access.log combined
ErrorLog /var/log/httpd/app1_error.log
<IfModule mod_jk.c>
JkMount /* tomcat8532
</IfModule>
</VirtualHost>

5. CONFIGURE TOMCAT FOR INTEGRATION

Now the main step is to Integrate Tomcat 8.5 with apache using below line in server.xml file

$ vim /opt/tomcat8532/conf/server.xml
# Add jvmRoute Parameter after defaulthost
<Engine name="Catalina" defaultHost="localhost" jvmRoute="tomcat8532">

6. START TOMCAT SERVICE

Go to the tomcat bin directory and run the startup.sh file,

$ cd /opt/tomcat8532/bin/
$ ./startup.sh

7. BROWSER URL :

To check everything is configured correctly just hit the localhost url in browser and it will show up the Tomcat page,

Tomcat 8.5

I hope you like the article if you find any difficulties then please do comment your queries or problem via the comment section, till then stay tuned to Linuxgrow.com for more such valuable articles.

Prashant

Welcome to Linuxgrow. I'm Prashant, a tech-blogger from Mumbai, India. I started Linuxgrow as a passion and to share my knowledge about technologies. Here at Linuxgrow, I write about Linux technologies, Aws Cloud, Wordpress blogging and scripting knowledge. You can read more about me at About us page. Thank You :)

You may also like...

Leave a Reply

Your email address will not be published. Required fields are marked *

Facebook