How Apache httpd web server communicate to Tomcat server
Before we going to detail about how communication happen between httpd server and tomcat.How many ports are bind when we start single tomcat?
- shutdown port
- http connector port
- https connector port (optional)
- ajp port
The port configuration are stored in $CATALINA_HOME/conf/server.xml file. we can change the ports when its necessary.
Steps to Implement Virtual Host Concept in this Scenario:
- Install Apache httpd Web Server
- Install mod_jk connector
- Configure JK Connector
- Configure Apache httpd server apply virtual host concepts
Prerequisite : We already installed Tomcat in different departments and deployed the application and works fine.
Install Apache httpd web server:
We can install Apache web server in two ways.
- Binary module
- From Source
We can install Apache httpd server from distribution package manager (either apt-get or yum). Or we can download the source code and then compile and install.
Second option: First download the httpd server source code from here . then extract it and install
./configure --prefix=/usr/local/apache --enable-rewrite=shared --enable-proxy=sharedmakesudo make install
Install mod_jk connector
Now Apache httpd server is ready. we need to add ajp support to server.
download the mod_jk connector module from here. extract it and install it
cd native
./configure --with-apxs=/usr/local/apache/bin/apxs
make
sudo make install
here --with-apxs option to specify where apxs module is located. so we need to give Apache httpd server location.
now mod_jk.so files is created on modules directory in apache installed location (/usr/local/apache/modules)
Configure mod_jk connector
This step have 2 sub step
- Create workers.properties file
- Load and configure the JK connector module in apache httpd.conf file
Create workers.properties file
mod_jk connector is ready. but this connector is works based on configuration file. so we need to create configuration file called workers.properties file
this file syntax is key=value pair,
here we define the workers. i.e all department tomcat hosts IP address and ajp port for corresponding tomcat.
here entry format is look like
worker..property =
for example
worker..type=ajp13
worker..port=
worker..host=
worker.list=
here
worker.list key have all workers name separated by comma.
type = here type of the worker. we use ajp13 version
port= we specify the ajp port (not http port ) of that server
host= IP address or host name of tomcat server
workers.properties
# Refer to http://kbase.redhat.com/faq/docs/DOC-15866 # for instructions on setting up mod_jk. # # Configuration directives valid for mod_jk version 1.2.28 and later. # # Define list of workers that will be used for mapping requests worker.list=loadbalancer,status # Define template worker worker.template.port=8009 worker.template.type=ajp13 worker.template.ping_mode=A worker.template.reply_timeout=10000 worker.template.socket_connect_timeout=10000 # Not necessary to specify connection_pool_timeout with worker mpm worker.template.connection_pool_timeout=600 # Referencing the template worker properties makes the workers.properties # shorter and more concise. worker.node1.reference=worker.template worker.node1.host=192.168.1.2
worker.node1.lbfactor=50
worker.node2.reference=worker.template
worker.node2.host=192.168.1.3
worker.node2.lbfactor=100
worker.loadbalancer.type=lb
worker.loadbalancer.balance_workers=node1,node2
worker.loadbalancer.sticky_session=True
worker.status.type=status
-----------
Configure httpd.conf
Apache httpd server is installed. mod_jk module is installed and workers.properties file is created. but these 3 are isolated. we put together,we need to configure the httpd server. find the conf/httpd.conf file in Apache installed location and add these following entries to it
LoadModule jk_module modules/mod_jk.soJkWorkersFile conf/workers.propertiesJkLogFile logs/mod_jk.logJkLogLevel emergJkLogStampFormat "[%a %b %d %H:%M:%S %Y] "JkOptions +ForwardKeySize +ForwardURICompat -ForwardDirectoriesJkRequestLogFormat "%w %V %T"
here LoadModule - Load mod_jk shared module to Apache httpd server (enable the mod_jk module)JkWorkersFile - Specify the mod_jk module file location.
Specify the workers.properties file location. all others are logging system of mod_jk. Its boilerplate code just copy and paste.
......
Delegate httpd to Tomcat
now we inform to Apache httpd server how delegate the request to corresponding server.JkMount /status/* stat JkMount /* loadbalancerhere
JkMount - specify the if URL have /* pattern then that request delegate to loadbalancer worker. that worker IP address and port is specified in workers.properties file.
Comments