此内容没有您所选择的语言版本。
Chapter 2. Apache Tomcat Connector (mod_jk)
The Apache Tomcat Connector, mod_jk, is a plug-in designed to allow request forwarding from Apache HTTP Server to a Servlet container. The module also supports load-balancing HTTP calls to a set of Servlet containers while maintaining sticky sessions.
2.1. Downloading and Installing mod_jk 复制链接链接已复制到粘贴板!
The mod_jk module is included in the Apache HTTP Server part of a JBoss Core Services installation.
Follow the procedures in the JBoss Core Services Installation Guide to download and install Apache HTTP Server for your operating system.
You can use the mod_jk connector to configure Apache HTTP Server load balancing. Follow the tasks in this section to configure load balancing using mod_jk, including configuring worker nodes.
Sample configuration files are provided for mod_jk, and are located in JBCS_HOME/httpd/conf.d/
. The sample configuration files are: mod_jk.conf.sample
, workers.properties.sample
, and uriworkermap.properties.sample
. To use these samples instead of creating your own configuration files, remove the .sample
extension, and modify their content as needed.
Red Hat customers can also use the Load Balancer Configuration Tool on the Red Hat Customer Portal to quickly generate optimal configuration templates for mod_jk and Tomcat worker nodes.
When using this tool for Apache HTTP Server 2.4, ensure you select 2.4.x
as the Apache version, and select Tomcat
as the back-end configuration.
2.2.1. Configuring Apache HTTP Server to load mod_jk 复制链接链接已复制到粘贴板!
Create a new file
JBCS_HOME/httpd/conf.d/mod_jk.conf
, and insert the following configuration:Copy to Clipboard Copied! Toggle word wrap Toggle overflow ImportantThe
LoadModule
directive must reference the mod_jk native binary you installed.NoteThe
JkMount
directive specifies which URLs that Apache HTTP Server will forward to the mod_jk module. Based on the directive’s configuration, mod_jk forwards the received URL to the correct Servlet containers.To enable Apache HTTP Server to serve static content (or PHP content) directly and only use the load balancer for Java applications, the suggested configuration above specifies that only requests with the URL
/application/*
are sent to the mod_jk load balancer.Alternatively, you can forward all URLs to mod_jk by specifying
/*
in theJkMount
directive.Optional:
JKMountFile
DirectiveIn addition to the
JkMount
directive, you can use theJkMountFile
directive to specify a mount point’s configuration file. The configuration file contains multiple URL mappings for Tomcat forwarding.-
Navigate to
JBCS_HOME/httpd/conf.d/
and create a file nameduriworkermap.properties
. Using the following syntax example as a guide, specify the URL to forward and the worker name.
The syntax required takes the form:
/URL=WORKER_NAME
The example below configures mod_jk to forward requests for
/application
to the JBoss Web Server Tomcat backend.Simple worker configuration file Mount the Servlet context to the ajp13 worker
# Simple worker configuration file # Mount the Servlet context to the ajp13 worker /application=loadbalancer /application/*=loadbalancer
Copy to Clipboard Copied! Toggle word wrap Toggle overflow In
JBCS_HOME/httpd/conf.d/mod_jk.conf
, append the following directive:Use external file for mount points. It will be checked for updates each 60 seconds. The format of the file is: /url=worker /examples/*=loadbalancer
# Use external file for mount points. # It will be checked for updates each 60 seconds. # The format of the file is: /url=worker # /examples/*=loadbalancer JkMountFile conf.d/uriworkermap.properties
Copy to Clipboard Copied! Toggle word wrap Toggle overflow
-
Navigate to
Optional: Configure Apache HTTP Server Logging
You can configure the Apache HTTP Server that is doing the load balancing to log which worker node handled a request. This may be useful when troubleshooting your load balancer.
To enable this for mod_jk, you can either:
-
include
%w
in yourJkRequestLogFormat
(which is configured by default in the suggestion above) ; or -
log the name of the mod_jk worker used by including
%{JK_WORKER_NAME}n
in your Apache HTTP ServerLogFormat
(s).
For more information on
JkRequestLogFormat
, see the Apache Tomcat connector documentation. For more information on Apache HTTP Server logging (including log rotation), see the Apache HTTP Server documentation on log files.-
include
2.2.2. Configuring Worker Nodes in mod_jk 复制链接链接已复制到粘贴板!
This procedure demonstrates two mod_jk worker node definitions in a weighted round robin configuration with sticky sessions active between two servlet containers.
Prerequisites
-
Understand the format of the
workers.properties
directives. - Configure mod_jk.
To configure mod_jk worker nodes:
-
Navigate to
JBCS_HOME/httpd/conf.d/
, and create a file namedworkers.properties
. Add the following configuration into
workers.properties
, customizing it to your environment:Copy to Clipboard Copied! Toggle word wrap Toggle overflow
2.2.3. Configuring Tomcat to work with mod_jk 复制链接链接已复制到粘贴板!
Tomcat is configured to receive AJP traffic from mod_jk by default; however, there is one additional step required before you can use a worker with mod_jk. The AJP connector is configured by default in the JBCS_HOME/tomcat<VERSION>/conf/server.xml
:
<Connector port="8009" protocol="AJP/1.3" redirectPort="8443" />
<Connector port="8009" protocol="AJP/1.3" redirectPort="8443" />
In addition to the AJP enabled Connector you also need to configure a unique value for the jvmRoute
attribute in the Engine of each worker node:
<Engine name="Catalina" jvmRoute="node1" >
<Engine name="Catalina" jvmRoute="node1" >
The jvmRoute
attribute value must match the worker name set in workers.properties
.