Chapter 3. Configure load balancing using Apache HTTP Server and mod_jk
Follow the tasks in this chapter to correctly configure load balancing using Apache HTTP Server and the mod_jk connector.
Task: Configure Apache HTTP Server to Load mod_jk
Complete this task to configure Apache HTTP Server to load mod_jk.
HTTPD_DIST/conf/httpd.confand add the following text at the end of the file.
# Include mod_jk's specific configuration file Include conf/mod-jk.conf
- Create a new file named
- Add the following configuration block to
# 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 +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 Order deny,allow Deny from all Allow from 127.0.0.1 </Location>
- Confirm that the
LoadModuledirective references the right path for the mod_jk library. If not, edit the path.
- The default configuration specifies that static content is served directly by Apache HTTP Server and all requests with URL path
/application/*are sent to the load balancer. If mod_jk is only to be used as a load balancer, change the directive to
Optional: JKMountFile DirectiveIn addition to the
JkMountdirective, you can use the
JkMountFiledirective to specify a mount point's configuration file. The configuration file contains multiple Tomcat forwarding URL mappings.
- Navigate to
- Create a file named
- Specify the URL whose requests are to be forwarded and the name of the worker node to which they are to be forwarded, using the following syntax example as a guide.The example block will configure mod_jk to forward requests to
/web-consoleto Apache HTTP Server.The syntax required takes the form
# Simple worker configuration file # Mount the Servlet context to the ajp13 worker /jmx-console=loadbalancer /jmx-console/*=loadbalancer /web-console=loadbalancer /web-console/*=loadbalancer
HTTPD_DIST/conf/mod-jk.conf, append the following directive.
# 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/*=loadbalancer JkMountFile conf/uriworkermap.properties
3.1. Configure worker nodes in mod_jk
Task: Configure mod_jk Worker Nodes
Complete this task to configure two mod_jk worker node definitions in a weighted round-robin configuration with sticky sessions active between two servlet containers.
Understand the format of the
workers.propertiesdirectives, as specified in Appendix A, Reference: workers.properties.
- Navigate to
- Create a file named
- Append the following information to
# 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=status