Apache-JBoss configuration
Hey, let me show how to configure Apache Web Server with JBoss Application Server (any edition/version, things remain almost same) using mod_jk connector.
Before proceeding further, let’s go through why
we need Apache Web Server:
1. Mainly,
we never want to expose the application server IP into Public. It would be
easier any hacker to get into roots of our application. If the web server is compromised, there is an
additional barrier for the hackers to overcome before they can get access to
your precious application and database servers.
2. Application
is redirected through Apache instead of directly accessing JBoss server. So,
your JBoss server is safe. However, network firewall is already enabled
throughout network by IT team.
3. A
single Apache server instance can serve multiple domains using virtual hosting
and at the same time they can all be serviced by different JBoss servers. It
ensures process isolation for web applications hosted in each domain
Apache to JBoss
Request Routing – Hmm,how it works?
We have two ways to configuring Apache to JBoss routing.
1. Configuring
through mod_jk connector. This is an Apache module specifically developed by Apache.
This module routes the Apache to JBoss request via the AJP (Apache Jserv
Protocol).
2.Secondly,
we can use an Apache module called mod_proxy. This proxy can either use HTTP or
AJP for routing request from Apache to JBoss.
When it
comes to load balancing and failure detection, mod_jk is better than mod_proxy.
The only disadvantage is the need to separately deploy mod_jk module.
In either cases, make sure that AJP port is enabled on JBoss server.
In this
case, my environment consists of:
- Windows 2008 R2
- JBoss Application Server 7.1.1
- Apache Web Server 2.4
- Mod_jk connector
- Download the latest Apache from http://httpd.apache.org/download.cgi and install it. We require no special configuration, just use the default settings. In the following steps, APACHE_HOME will represent the Apache install directory.
- Download latest mod_jk module from http://tomcat.apache.org/download-connectors.cgi
- Prefer to download latest stable version of mod_jk. Then uncomment load module mod_jk.so lines in httpd.conf file in conf folder.
- Rename the lib mod_jk.so and copy it in APACHE_HOME/modules directory.
Now the real configuration begins:
Step
1: Load mod_jk.so module, uncomment the below line if already there or add.
LoadModule jk_module modules/mod_jk.so
LoadModule jk_module modules/mod_jk.so
Step 2: Setup Apache to use mod_jk
Add this line in APACHE_HOME/conf/httpd.conf :
#Include mod_jk configuration
file
Include conf/mod-jk.conf
Step 3: Create the mod_jk config, Under
APACHE_HOME/conf, create mod-jk.conf and populate it as follows:
# Load mod_jk
module
# Specify the
filename of the mod_jk lib
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
info
# Select the
log format
JkLogStampFormat
"[%a %b %d %H:%M:%S %Y]"
# JkOptions
indicates to send SSK KEY SIZE
JkOptions
+ForwardKeySize +ForwardURICompatUnparsed -ForwardDirectories
# JkRequestLogFormat
JkRequestLogFormat
"%w %V %T"
# Mount your applications
JkMount
/__Application_Name_/* node1
# You can use external file for mount
points.
# It will be
checked for updates each 60 seconds.
# The format
of the file is: /url=worker
#
/examples/*=node1
JkMountFile
conf/uriworkermap.properties
Step 4: Configuring workers.
Under APACHE_HOME/conf, create workers.properties and
populate it as follows:
# Define list
of workers that will be used
# for mapping
requests
# The
configuration directives are valid
# for the
mod_jk version 1.2.18 and later
#
worker.list=loadbalancer,status
# Define
Node
# modify the
host as your host IP or DNS name.
worker.node1.port=8009
worker.node1.host=node1.mydomain.com
worker.node1.type=ajp13
worker.node1.lbfactor=1
#
worker.node1.connection_pool_size=10 (1)
#
Load-balancing behaviour
worker.loadbalancer.type=lb
worker.loadbalancer.balance_workers=node1,node2
# Status
worker for managing load balancer
worker.status.type=status
Then we have
to define the applications or the servlet contexts which you are going to
access through the nodes which we have defined in worker file. So create a
uriworkermap.properties file reference to which we have already given in our
mod_jk .conf file.
Mount the
Servlet context to the ajp13 worker
/jmx-console=node1
/jmx-console/*=node1
/web-console=node1
/web-console/*=node1
/ Application
Name /*=node1
Configuration
changes at JBoss:
Earlier
in JBoss 5, we used to update in server.xml under directory “<Jboss_Installation>/jboss-5.0.1.GA\server\default\deploy\jbossweb.sar”
as below:
From:
<Engine name="jboss.web" defaultHost="localhost">
To: <Engine name=”jboss.web”
defaultHost=”localhost” jvmRoute=”node1″>
But in JBoss7 and later, changes need to be edited in standalone.xml as below:
Either we can
instance id or adding jvmRoute.
1. Using Instance
id:
Search for domain:web in standalone.xml file and make below
changes:
From:
<subsystem xmlns="urn:jboss:domain:web:1.1"
default-virtual-server="default-host" native="false">
To:
<subsystem xmlns="urn:jboss:domain:web:1.1"
default-virtual-server="default-host" native="false"
instance-id="node1>
2. Adding
jvmRoute under System properties as below:
<system-properties>
<property
name="jvmRoute" value="<node1>"/>
</system-properties>
Now, restart
both the Apache and JBoss and try to access the application with Apache
server URL.
Hope
this article helps you to integrate Apache-JBoss. Cheers!!
|
|
