Vous êtes sur la page 1sur 9

12/24/2014

HowdoIinstallandconfiguremod_jk1.2.2xwithApache2.xandJBossEAP4/5?RedHatCustomerPortal

C USTO ME R PO RTAL
Products & Services Knowledgebase
Apache 2.x and JBoss EAP 4 / 5?

Solutions

How do I install and congure mod_ jk 1.2.2x with

How do I install and configure mod_jk


1.2.2x with Apache 2.x and JBoss EA
/ 5?
( Updated July 3 2014 at 5:35 AM

0 ISSUE
How do I install and congure mod_jk with Apache and JBoss?
How to congure the communication between our JBossEAP5 and JbossWebserver?

ENVIRONMENT
JBoss Enterprise Application Platform (EAP)
4.2
4.3
5
JBoss Enterprise Web Server (EWS)
mod_ jk 1.2
Apache 2

, RESOLUTION
Quick Overview
1. Download Apache2/Use existing Apache (EWS is the ofcially supported JBoss version of
Apache)
https://access.redhat.com/solutions/18414

1/9

12/24/2014

HowdoIinstallandconfiguremod_jk1.2.2xwithApache2.xandJBossEAP4/5?RedHatCustomerPortal

2. Download the supported modjk 1.2.x (See component matrix which includes the mod_ jk
version at http://www.jboss.com/products/platforms/application/components/
(http://www.jboss.com/products/platforms/application/components/)) mod_ jk.so comes
with the EWS and the EAP 5+ Native builds.
3. Change the main Apache cong to include mod_ jk cong
4. Create the mod_ jk cong
5. Congure the mod_ jk workers (which JBoss/Tomcat nodes Apache uses)
6. Congure the Apache URIs served by modjk (the applications served by JBoss/Tomcat)
7. Restart Apache
8. Congure Tomcat (Give each JBoss/Tomcat a jvmRoute for session stickness)
9. Restart JBoss
10. Test it

More Details
This wiki outlines the various steps required to install a basic load-balancing solution based
on JBoss/Tomcat and mod_ jk 1.2.
For quick generation of optimized mod_ jk congurations please see
http://lbcong.appspot.com (http://lbcong.appspot.com).
Step 1: Download Apache2 Web Server
Apache can be installed through RHN with certain Red Hat/JBoss entitlements such as the JBoss
Enterprise Web Server (EWS) In the community Apache can also be obtained through
http://httpd.apache.org though it will be unsupported in the enterprise realm.
In the following steps, $APACHE_HOME will represent the Apache install directory.
Step 2: Download mod_ jk 1.2.x
mod_ jk can also be installed through RHN from the above entitlements or downloaded through the
EWS or EAP 5+ Native builds or unsupported through http://tomcat.apache.org/downloadconnectors.cgi Always download the latest stable release if possible. Rename the lib
mod_ jk.so and drop it in $APACHE_HOME/modules directory.
Step 3: Setup Apache to use modjk
Add this line at the very bottom in $APACHE_HOME/conf/httpd.conf :

https://access.redhat.com/solutions/18414

2/9

12/24/2014

HowdoIinstallandconfiguremod_jk1.2.2xwithApache2.xandJBossEAP4/5?RedHatCustomerPortal

#Includemod_jkconfigurationfile
Includeconf/modjk.conf

Step 4: Create the modjk cong


Under $APACHE_HOME/conf, create mod-jk.conf and populate it as follows:
#Loadmod_jkmodule
#Specifythefilenameofthemod_jklib
LoadModulejk_modulemodules/mod_jk.so
#Wheretofindworkers.properties
JkWorkersFileconf/workers.properties
#Wheretoputjklogs
JkLogFilelogs/mod_jk.log
#Setthejkloglevel[debug/error/info]
JkLogLevelinfo
#Selectthelogformat
JkLogStampFormat"[%a%b%d%H:%M:%S%Y]"
#JkOptionsindicatestosendSSKKEYSIZE
#Notes:
#1)Changedfrom+ForwardURICompat.
#2)Formod_rewritecompatibility,use+ForwardURIProxy(defaultsince1.2.24)
#Seehttp://tomcat.apache.org/securityjk.html
JkOptions+ForwardKeySize+ForwardURICompatUnparsedForwardDirectories
#JkRequestLogFormat
JkRequestLogFormat"%w%V%T"
#Mountyourapplications
JkMount/__application__/*loadbalancer
#LetApacheservetheimages
JkUnMount/__application__/images/*loadbalancer
#Youcanuseexternalfileformountpoints.
#Itwillbecheckedforupdateseach60seconds.
#Theformatofthefileis:/url=worker
#/examples/*=loadbalancer
JkMountFileconf/uriworkermap.properties
#Addsharedmemory.
#Thisdirectiveispresentwith1.2.10and
#laterversionsofmod_jk,andisneededfor
#forloadbalancingtoworkproperly
#Note:ReplacedJkShmFilelogs/jk.shmduetoSELinuxissues.Referto
https://access.redhat.com/solutions/18414

3/9

12/24/2014

HowdoIinstallandconfiguremod_jk1.2.2xwithApache2.xandJBossEAP4/5?RedHatCustomerPortal

#https://bugzilla.redhat.com/bugzilla/show_bug.cgi?id=225452
JkShmFilerun/jk.shm
#Addjkstatusformanagingruntimedata
<Location/jkstatus>
JkMountstatus
Orderdeny,allow
Denyfromall
Allowfrom127.0.0.1
</Location>

mod_ jk is ready to forward requests to JBoss instances. We need now to setup the workers
Note: As of mod_ jk 1.2.6+ you need to include "JkMountCopy all" in the mod_ jk conguration if you
intend to specify global JkMount's or JkMountFile's instead of per VirtualHost. If you do not want to
copy the same JkMount/JkMountFile for each VirtualHost, you can specify "JkMountCopy On"
inside the VirtualHost directive.
See entry in: http://tomcat.apache.org/connectors-doc/reference/apache.html
(http://tomcat.apache.org/connectors-doc/reference/apache.html)

Step 5: Conguring workers


Under $APACHE_HOME/conf, create workers.properties and populate it as follows:

https://access.redhat.com/solutions/18414

4/9

12/24/2014

HowdoIinstallandconfiguremod_jk1.2.2xwithApache2.xandJBossEAP4/5?RedHatCustomerPortal

#Definelistofworkersthatwillbeused
#formappingrequests
#Theconfigurationdirectivesarevalid
#forthemod_jkversion1.2.18andlater
#
worker.list=loadbalancer,status

#DefineNode1
#modifythehostasyourhostIPorDNSname.
worker.node1.port=8009
worker.node1.host=node1.mydomain.com
worker.node1.type=ajp13
worker.node1.ping_mode=A
#DefineNode2
#modifythehostasyourhostIPorDNSname.
worker.node2.port=8009
worker.node2.host=node2.mydomain.com
worker.node2.type=ajp13
worker.node2.ping_mode=A
#Loadbalancingbehaviour
worker.loadbalancer.type=lb
worker.loadbalancer.balance_workers=node1,node2
#Statusworkerformanagingloadbalancer
worker.status.type=status

Important: Please review http://tomcat.apache.org/connectors-doc/reference/workers.html


(http://tomcat.apache.org/connectors-doc/reference/workers.html) for the directive descriptions.
(1) You should only set the connection_pool_size if the number of allowed connection to
the Httpd is higher than maxThreads in server.xml
If you specify worker.loadbalancer.sticky_session=Off, each request will be load balanced between
node1 and node2. But when a user opens a Session on one server, it is a good idea to always forward
this user's requests to the same server. Otherwise the user's session data would need to be
synchronized between both servers. This is called a "sticky session", as the client is always using the
same server he reached on his rst request.
Session stickiness is enabled by default.
Step 6: Create the URI to worker map le
Create a uriworkermap.properties le in the $APACHE_HOME/conf directory. This le should
contain the URL mappings you want Apache to forward to Tomcat. The format of the le is
/url=worker_name. To get things started, paste this example into the le you created:
https://access.redhat.com/solutions/18414

5/9

12/24/2014

HowdoIinstallandconfiguremod_jk1.2.2xwithApache2.xandJBossEAP4/5?RedHatCustomerPortal

#Simpleworkerconfigurationfile
#
#MounttheServletcontexttotheajp13worker
/jmxconsole=loadbalancer
/jmxconsole/*=loadbalancer
/webconsole=loadbalancer
/webconsole/*=loadbalancer
/myapp/*=loadbalancer
!/myapp/images/*=loadbalancer

This will congure mod_ jk to forward requests for the /jmxconsole, /webconsole and /myapp
contexts to JBoss Web. The '!' at the beginning of the last line results in the URLs for the images dir
in the myapp context not being forwarded. Instead httpd will handle them directly (which means they
must be available on the httpd server).
Step 7: Restart Apache
Step 8: Congure the JBoss EAP
To complete the conguration, we also need to name each node to match the names specied in
workers.properties.
To do this, edit the server.xml le. Where server.xml is located depends on the version of JBoss:
In JBoss 5, it's $JBOSS_HOME/server/$PROFILE/deploy/jbossweb.sar/server.xml
In JBoss 4.2.x and EAP 4.x, it's
$JBOSS_HOME/server/$PROFILE/deploy/jbossweb.deployer/server.xml
Inearlierreleasesit's$JBOSS_HOME/server/$PROFILE/deploy/jbosswebtomcatXX.sar/server.xml

where XX is 40, 50, 55 etc depending on the Tomcat version embedded in the AS.
Locate the <Engine/.> element and add an attribute jvmRoute:
<Enginename="jboss.web"defaultHost="localhost"jvmRoute="node1">
.
</Engine>

The jvmRoute attribute value must match the name specied in workers.properties.
In the server.xml le, make sure that the AJP 1.3 Connector is uncommented, e.g.:
<!AAJP1.3Connectoronport8009>
<Connectorport="8009"address="${jboss.bind.address}"
emptySessionPath="true"enableLookups="false"redirectPort="8443"
protocol="AJP/1.3"connectionTimeout="600000"maxThreads="200"/>
https://access.redhat.com/solutions/18414

6/9

12/24/2014

HowdoIinstallandconfiguremod_jk1.2.2xwithApache2.xandJBossEAP4/5?RedHatCustomerPortal

If you are only accepting requests via mod_ jk, you can comment out the regular HTTP Connector;
Tomcat then won't listen on port 8080.
Step 9: Activate the JvmRouteValve in JBoss (not needed with Tomcat Standalone)
Finally, we need to tell JBoss to add a special valve that detects when failover of a session from a
distributable webapp has occurred. This JvmRouteValve ensures a new session cookie is emitted
that includes the jvmRoute of the server that is now handling the session.
This conguration step is only needed with JBoss 4.2.x and earlier; beginning with JBoss 5 the
application server uses the existence of a jvmRoute conguration in server.xml as an indication that
it should add the JvmRouteValve.
To do this, edit the jbossservice.xml le for the JBoss Web service. Where this is located
depends on the version of JBoss AS:
In JBoss 5, this step isn't needed.
In JBoss 4.2.x and EAP 4.x, it's
$JBOSS_HOME/server/$PROFILE/deploy/jbossweb.deployer/METAINF/jbossservice.xml

Inearlierreleasesit's$JBOSS_HOME/server/$PROFILE/deploy/jbosswebtomcatXX.sar/``METAINF/jb

where XX is 40, 50, 55 etc depending on the Tomcat version embedded in the AS.
Locate the <attribute> element with a name of UseJK, and set its value to "true" (not applicable to
EAP 5):
<attributename="UseJK">true</attribute>

Step 10: Restart JBoss.


Step 11: Access the JBoss web-console through Apache by browsing to http://localhost/webconsole (http://localhost/web-console) and you should see the JBoss web console page.
*

Note: You may need to use VirtualHost in you mod-jk.conf. For example:
Instead of just
JkMount/jmxconsoleloadbalancer
JkMount/jmxconsole/*loadbalancer

try

https://access.redhat.com/solutions/18414

7/9

12/24/2014

HowdoIinstallandconfiguremod_jk1.2.2xwithApache2.xandJBossEAP4/5?RedHatCustomerPortal

<VirtualHosthost.name.or.IP>
ServerNamehost.name.or.IP
JkMount/jmxconsoleloadbalancer
JkMount/jmxconsole/*loadbalancer
</VirtualHost>

Step 12: Optimize the conguration

Further reference
See Troubleshooting & Optimizing mod_ jk (/knowledge/node/18415) for optimizing mod_ jk
for your specic environment
See Troubleshooting & Optimizing mod_ jk (/knowledge/node/18415) if you encounter issues
with mod_ jk
See [DOC-34454]Does Red Hat / JBoss offer support for Apache / mod_ jk / mod_proxy /
mod_cluster? (/knowledge/node/18495) for information pertaining to mod_ jk support

Product(s)
Red Hat JBoss Enterprise Application Platform (https://access.redhat.com/search/browse/solutions#?
&portal_product=Red+Hat+JBoss+Enterprise+Application+Platform)
Red Hat JBoss Web Server (https://access.redhat.com/search/browse/solutions#?
&portal_product=Red+Hat+JBoss+Web+Server)
Component
Category
Tags

jbossas (https://access.redhat.com/search/browse/solutions#?&portal_component=jbossas)
Learn more (https://access.redhat.com/search/browse/solutions#?&portal_category=Learn+more)

apache (https://access.redhat.com/search/browse/solutions#?&portal_tag=apache)

mod_ jk (https://access.redhat.com/search/browse/solutions#?&portal_tag=mod_ jk)

COMMENTS
(/user/1162213)
Jim Tyrrell
(/user/1162213)
https://access.redhat.com/solutions/18414

I am having the below error message:


[jimtyrrell@localhost conf]$ sudo service httpd restart
8/9

12/24/2014

HowdoIinstallandconfiguremod_jk1.2.2xwithApache2.xandJBossEAP4/5?RedHatCustomerPortal

Red Hat

Stopping httpd:

[FAILED]

Newbie

5 points

Starting httpd: Syntax error on line 36 of /etc/httpd/conf/mod-jk.conf:


JkMountFile: Can't nd the mount le specied
When I am trying to use the mod-jk.conf le verbatim above, what is
missing with EAP 5.1 mod_ jk and this command/line?
March 2 2011 at 12:46 AM (https://access.redhat.com/solutions/18414#comment-326123)

Add new comment

Formatting Help

SUBMIT COMMENT

Privacy Policy (http://www.redhat.com/en/about/privacy-policy)


Customer Portal Terms of Use (https://access.redhat.com/help/terms/)
All Policies and Guidelines (http://www.redhat.com/en/about/all-policies-guidelines)
Copyright 2014 Red Hat, Inc.

https://access.redhat.com/solutions/18414

9/9