Dieser Inhalt ist in der von Ihnen ausgewählten Sprache nicht verfügbar.
Chapter 2. Load balancing with the Apache Tomcat connector (mod_jk)
The Apache Tomcat Connector, mod_jk, is a plug-in that allows the Apache HTTP Server to forward web requests to a back-end servlet container. The mod_jk module also allows the Apache HTTP Server to load-balance requests to a set of servlet containers, while maintaining sticky sessions.
2.1. Mod_jk installation Link kopierenLink in die Zwischenablage kopiert!
The mod_jk module is included in the Apache HTTP Server part of a JBoss Core Services installation.
You can follow the procedures in the Red Hat JBoss Core Services Apache HTTP Server Installation Guide to download and install the Apache HTTP Server for your operating system.
2.2. Apache HTTP Server load-balancing configuration when using mod_jk Link kopierenLink in die Zwischenablage kopiert!
You can configure the Apache HTTP Server to use mod_jk to load-balance requests to a set of servlet containers. This setup includes the configuration of back-end worker nodes.
Red Hat JBoss Core Services provides example configuration files for mod_jk in the JBCS_HOME/httpd/conf.d/ directory. These example configuration files are named mod_jk.conf.sample, workers.properties.sample, and uriworkermap.properties.sample. To use these examples instead of creating your own configuration files, you can remove the .sample extension, and modify the file content as needed.
You can also use the Load Balancer Configuration tool on the Red Hat Customer Portal to generate optimal configuration templates quickly for mod_jk and Tomcat worker nodes.
When you use the Load Balancer Configuration tool for JBoss Web Server 5.6, ensure that you select 2.4.x as the Apache version, and select Tomcat as the back-end configuration.
2.3. Configuring the Apache HTTP Server to load mod_jk Link kopierenLink in die Zwischenablage kopiert!
You can configure the Apache HTTP Server to load mod_jk, by specifying configuration settings in the mod_jk.conf file.
You can also perform the following optional configuration steps:
-
In addition to the
JkMountdirective, you can use theJkMountFiledirective to specify the configuration file for a mount point. The configuration file contains multiple URL mappings for Tomcat forwarding. - You can configure the Apache HTTP Server that is functioning as the load balancer to log details of each worker node that handles a request. This can be useful if you need to troubleshoot your load balancer.
Procedure
-
Go to the
JBCS_HOME/httpd/conf.ddirectory. Create a new file named
mod_jk.confand enter the following configuration details:# 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.d/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 SSL KEY SIZE JkOptions +ForwardKeySize +ForwardURICompat -ForwardDirectories # JkRequestLogFormat JkRequestLogFormat "%w %V %T" # Mount your applications JkMount /application/* loadbalancer # Add shared memory. # This directive is present with 1.2.10 and # later versions of mod_jk, and is needed for # for load balancing to work properly JkShmFile logs/jk.shm # Add jkstatus for managing runtime data <Location /jkstatus/> JkMount status Require ip 127.0.0.1 </Location>ImportantEnsure that the
LoadModuledirective references themod_jknative binary that you have installed.NoteThe
JkMountdirective specifies the URLs that the Apache HTTP Server can forward to themod_jkmodule. Based on the configuration for theJkMountdirective,mod_jkforwards the received URL to the correct servlet containers.To enable the Apache HTTP Server to serve static content (or PHP content) directly, and only use the load balancer for Java applications, the preceding configuration example specifies that the Apache HTTP Server sends only requests with the URL
/application/*to themod_jkload balancer.Alternatively, you can configure the Apache HTTP Server to forward all URLs to
mod_jkby specifying/*in theJkMountdirective.Optional: To use the
JkMountFiledirective to specify the configuration file for a mount point, perform the following steps:-
Go to the
JBCS_HOME/httpd/conf.d/directory. -
Create a file named
uriworkermap.properties. Specify the URL that you want to forward and the worker name.
For example:
# Simple worker configuration file # Mount the Servlet context to the ajp13 worker /application=loadbalancer /application/*=loadbalancerNoteThe required syntax is in the format:
/URL=WORKER_NAMEThe preceding example configures
mod_jkto forward requests for/applicationto the JBoss Web Server Tomcat back end.In the
JBCS_HOME/httpd/conf.d/mod_jk.conffile, enter 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 JkMountFile conf.d/uriworkermap.properties
-
Go to the
Optional: To enable Apache HTTP Server logging, perform either of the following steps:
-
Include
%win yourJkRequestLogFormatdirective, as shown in the preceding step aboutmod_jk.confsettings. -
Log the name of the
mod_jkworker that you want to use, by including%{JK_WORKER_NAME}nin your Apache HTTP ServerLogFormat(s).
-
Include
2.4. Configuring worker nodes in mod_jk Link kopierenLink in die Zwischenablage kopiert!
You can configure multiple worker nodes to handle the requests that the Apache HTTP Server forwards to the servlet containers.
The example in this procedure shows how to define two mod_jk worker nodes in a weighted round-robin configuration that uses sticky sessions between two servlet containers.
Prerequisites
-
You are familiar with the format of the
workers.propertiesdirectives. -
You have configured the Apache HTTP Server to load
mod_jk.
Procedure
-
Go to the
JBCS_HOME/httpd/conf.d/directory. -
Create a file named
workers.properties. Enter the following configuration details:
# Define list of workers that will be used # for mapping requests worker.list=loadbalancer,status # Define Node1 # 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.ping_mode=A worker.node1.lbfactor=1 # Define Node2 # modify the host as your host IP or DNS name. worker.node2.port=8009 worker.node2.host=node2.mydomain.com worker.node2.type=ajp13 worker.node2.ping_mode=A worker.node2.lbfactor=1 # Load-balancing behavior worker.loadbalancer.type=lb worker.loadbalancer.balance_workers=node1,node2 worker.loadbalancer.sticky_session=1 # Status worker for managing load balancer worker.status.type=statusNoteIn the preceding example, ensure that you replace
host,port, andsecretsettings with values that are relevant for your environment.
2.5. Configuring Tomcat to work with mod_jk Link kopierenLink in die Zwischenablage kopiert!
Tomcat is configured to receive Apache JServ Protocol (AJP) traffic from mod_jk by default. However, before you can use a worker node with mod_jk, you must perform one additional configuration step.
The AJP connector is configured by default in the JBCS_HOME/tomcat<VERSION>/conf/server.xml file:
<Connector port="8009" protocol="AJP/1.3" redirectPort="8443" />
In addition to the AJP-enabled connector, you must also configure a unique value for the jvmRoute attribute in the Engine of each worker node:
Procedure
To configure a unique value for the
jvmRouteattribute in the Engine of each worker node, enter the following details:<Engine name="Catalina" jvmRoute="node1" >ImportantEnsure that the
jvmRouteattribute value matches the worker name that is specified in theworkers.propertiesfile.