Configuring
Apache 2.x and Tomcat 6.x with mod_jk
The system used in this tutorial has the following installed:
1.WebServer: Apache 2.x
2.JDK: JDK 6.x
3.Servlet Container: Tomcat 6.x
4.Tomcat Connecter: Jakarta Tomcat Connector mod_jk.so (not mod_jk2.so)
tcp 0 0 :::80 :::* LISTEN 2793/httpd
Tomcat can be run as a standalone server. Tomcat can also be run as an add-on
to the Apache HTTP Server (or Microsoft IIS) - as the Java servlet/JSP
container. In this combination, Tomcat executes the Java servlets and
JSPs, the Apache serves the static HTML pages and performs other
server-side functions such as CGI, PHP, SSI, etc. Read "Why should I
integrate Apache with Tomcat? (or not)" at Tomcat FAQ
To configure Tomcat to work with Apache HTTP Server, you should first read the documentation provided in Tomcat thoroughly, and read the "Tomcat Connector" documents
To run Tomcat together with Apache:
To configure Tomcat to work with Apache HTTP Server, you should first read the documentation provided in Tomcat thoroughly, and read the "Tomcat Connector" documents
To run Tomcat together with Apache:
- Apache needs to load a "adapter" module, which uses a certain protocol, such as Apache JServ Protocol (AJP), to communicate with the Tomcat, via another TCP port (port 8009 in the default configuration).
- When Apache receives an HTTP request, it checks if the request belongs to Tomcat. If so, it lets the adapter takes the request and forwards it to Tomcat, as illustrated below.
The system used in this tutorial has the following installed:
2.JDK: JDK 6.x
3.Servlet Container: Tomcat 6.x
4.Tomcat Connecter: Jakarta Tomcat Connector mod_jk.so (not mod_jk2.so)
Installing
Apache:
#yum
install httpd*
#yum install gcc gcc-cpp gcc-c++
Because you will need httpd-devel for apxs
or
#yum install httpd-devel
#yum install gcc gcc-cpp gcc-c++
Because you will need httpd-devel for apxs
or
#yum install httpd-devel
Start
the apache service
#/etc/init.d/httpd start
#Chkconfig httpd on
#/etc/init.d/httpd start
#Chkconfig httpd on
Checking
process:-
#
netstat -ntplau | grep httpd
tcp 0 0 :::80 :::* LISTEN 2793/httpd
First
install jdk java
#yum
install java*
Set
the following environment variables:
You
can add it in .bashrc for permanent use
example:-
export
JAVA_HOME=/usr/lib/jvm/java-1.7.0-openjdk-1.7.0.5/
export
PATH=/usr/lib/jvm/java-1.7.0-openjdk-1.7.0.5/bin:/root/Desktop/grails-1.0.2/bin:$PATH
export
GRAILS_HOME=/root/Desktop/grails-1.0.2
Checking
process:-
#javac
#java
-version
Download
Tomcat 6:
Untar
the package:
#tar xvzf apache-tomcat-6.0.26.tar.gz
#cd apache-tomcat-6.0.26
#cd bin
#./startup.sh
#tar xvzf apache-tomcat-6.0.26.tar.gz
#cd apache-tomcat-6.0.26
#cd bin
#./startup.sh
Checking
process:-
#netstat
-tulpn | grep 8080
tcp
0 0 :::8080 :::*
LISTEN 2525/java
Now
install jakarta connector:
#tar
xvzf jakarta-tomcat-connectors-1.2.15-src.tar.gz
#cd jakarta-tomcat-connectors-1.2.15-src
#cd jk/
#cd native/
#./configure --with-apxs=/usr/sbin/apxs
#make
#make install
#cd jakarta-tomcat-connectors-1.2.15-src
#cd jk/
#cd native/
#./configure --with-apxs=/usr/sbin/apxs
#make
#make install
Create
workers.properties file in /etc/httpd/conf with following contents:
#
# This file provides minimal jk configuration properties needed to
# connect to Tomcat.
#
# We define a worked named 'default'
#
workers.tomcat_home=/usr/local/tomcat
workers.java_home=/usr/java/jdk1.5.0_05
ps=/
worker.list=default
worker.default.port=8009
worker.default.host=localhost
worker.default.type=ajp13
worker.default.lbfactor=1
# This file provides minimal jk configuration properties needed to
# connect to Tomcat.
#
# We define a worked named 'default'
#
workers.tomcat_home=/usr/local/tomcat
workers.java_home=/usr/java/jdk1.5.0_05
ps=/
worker.list=default
worker.default.port=8009
worker.default.host=localhost
worker.default.type=ajp13
worker.default.lbfactor=1
Edit
httpd.conf and add the following mod_jk-specific directives (I added
them just before the start of Section 3 / Virtual Hosts).
#
# Mod_jk settings
#
# Load mod_jk module
LoadModule jk_module modules/mod_jk.so
# Where to find workers.properties
JkWorkersFile conf/workers.properties
# Where to put jk logs
JkLogFile logs/mod_jk.log
# Set the jk log level [debug/error/info]
JkLogLevel debug
# Select the log format
JkLogStampFormat "[%a %b %d %H:%M:%S %Y] "
# JkOptions indicate to send SSL KEY SIZE,
JkOptions +ForwardKeySize +ForwardURICompat -ForwardDirectories
# JkRequestLogFormat set the request format
JkRequestLogFormat "%w %V %T"
# Send JSPs for context /jsp-examples to worker named default
JkMount /sureryplant default
# Send servlets-examples to worker named default
JkMount /sureryplant/* default
# Mod_jk settings
#
# Load mod_jk module
LoadModule jk_module modules/mod_jk.so
# Where to find workers.properties
JkWorkersFile conf/workers.properties
# Where to put jk logs
JkLogFile logs/mod_jk.log
# Set the jk log level [debug/error/info]
JkLogLevel debug
# Select the log format
JkLogStampFormat "[%a %b %d %H:%M:%S %Y] "
# JkOptions indicate to send SSL KEY SIZE,
JkOptions +ForwardKeySize +ForwardURICompat -ForwardDirectories
# JkRequestLogFormat set the request format
JkRequestLogFormat "%w %V %T"
# Send JSPs for context /jsp-examples to worker named default
JkMount /sureryplant default
# Send servlets-examples to worker named default
JkMount /sureryplant/* default
#
Static files in the jsp-examples webapp are served by apache
Alias /sureryplant "/usr/local/tomcat/webapps/sureryplant"
Alias /sureryplant "/usr/local/tomcat/webapps/sureryplant"
Restart
Apache via /etc/init.d/httpd restart
Test
standalone Tomcat server by going to
http://Web_server_name_or_IP:8080
Test Apache/Tomcat integration by going to http://Web_server_name_or_IP/ sureryplant and http://Web_server_name_or_IP/ sureryplant
Test Apache/Tomcat integration by going to http://Web_server_name_or_IP/ sureryplant and http://Web_server_name_or_IP/ sureryplant
##################################################################################

No comments:
Post a Comment