Configure load balancing using Apache and mod_jk
1. Configure Worker Nodes in mod_jk
2. Configuring JBoss to work with mod_jk
Follow the tasks in this chapter to correctly configure load balancing using Apache and the mod_jk connector.
Task: Configure Apache to Load mod_jk
Complete this task to configure Apache to load mod_jk.
Prerequisites
Apache and mod_jk installed .
Open HTTPD_DIST/conf/httpd.conf and add a single line at the end of the file.
# Include mod_jk's specific configuration file
Include conf/mod-jk.conf
Create a new file named HTTPD_DIST/conf/mod-jk.conf
Add the following configuration to the mod-jk.conf file.
Important
The LoadModule directive must reference the mod_jk library directory location applicable to the native binary you installed.
Note :
The JkMount directive specifies which URLs Apache should forward to the mod_jk module. Based on the directive's configuration, mod_jk forwards the received URL onto the correct Servlet containers.
To enable Apache to serve static content (or PHP content) directly, and only use the load balancer for Java applications, the suggested configuration specifies all requests with URL path /application/* are sent to the mod_jk load-balancer.
If you only use mod_jk as a load balancer, forward all URLs to mod_jk by specifying /* in the directive.
# 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>
Optional: JKMountFile Directive
In addition to the JkMount directive, you can use the JkMountFile directive to specify a mount points configuration file. The configuration file contains multiple Tomcat forwarding URL mappings.
Navigate to HTTPD_DIST/conf.
Create a file named uriworkermap.properties.
Specify the URL to forward and the worker name using the following syntax example as a guide.
The example block will configure mod_jk to forward requests to /jmx-console and /web-console to Apache.
The syntax required takes the form /url=worker_name.
# Simple worker configuration file
# Mount the Servlet context to the ajp13 worker
/jmx-console=loadbalancer
/jmx-console/*=loadbalancer
/web-console=loadbalancer
/web-console/*=loadbalancer
In 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
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.
Prerequisites
Understand the format of the workers.properties directives, as specified in Appendix A, workers.properties Reference.
Task: Configure Apache to Load mod_jk
Navigate to HTTPD_DIST/conf/.
Create a file named workers.properties.
Append the following information into the workers.properties file.
# Define list of workers that will be used
# for mapping requests
worker.list=loadbalancer,status
# Define dev1
# modify the host as your host IP or DNS name.
worker.dev1.port=8009
worker.dev1.host=dev1.srinivaslinux.com
worker.dev1.type=ajp13
worker.dev1.ping_mode=A
worker.dev1.lbfactor=1
# Define dev2
# modify the host as your host IP or DNS name.
worker.dev2.port=8009
worker.dev2.host=dev2.srinivaslinux.com
worker.dev2.type=ajp13
worker.dev2.ping_mode=A
worker.dev2.lbfactor=1
# Load-balancing behavior
worker.loadbalancer.type=lb
worker.loadbalancer.balance_workers=dev1,dev2
worker.loadbalancer.sticky_session=1
# Status worker for managing load balancer
worker.status.type=status
Good Luck :)
1. Configure Worker Nodes in mod_jk
2. Configuring JBoss to work with mod_jk
Follow the tasks in this chapter to correctly configure load balancing using Apache and the mod_jk connector.
Task: Configure Apache to Load mod_jk
Complete this task to configure Apache to load mod_jk.
Prerequisites
Apache and mod_jk installed .
Open HTTPD_DIST/conf/httpd.conf and add a single line at the end of the file.
# Include mod_jk's specific configuration file
Include conf/mod-jk.conf
Create a new file named HTTPD_DIST/conf/mod-jk.conf
Add the following configuration to the mod-jk.conf file.
Important
The LoadModule directive must reference the mod_jk library directory location applicable to the native binary you installed.
Note :
The JkMount directive specifies which URLs Apache should forward to the mod_jk module. Based on the directive's configuration, mod_jk forwards the received URL onto the correct Servlet containers.
To enable Apache to serve static content (or PHP content) directly, and only use the load balancer for Java applications, the suggested configuration specifies all requests with URL path /application/* are sent to the mod_jk load-balancer.
If you only use mod_jk as a load balancer, forward all URLs to mod_jk by specifying /* in the directive.
# 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>
Optional: JKMountFile Directive
In addition to the JkMount directive, you can use the JkMountFile directive to specify a mount points configuration file. The configuration file contains multiple Tomcat forwarding URL mappings.
Navigate to HTTPD_DIST/conf.
Create a file named uriworkermap.properties.
Specify the URL to forward and the worker name using the following syntax example as a guide.
The example block will configure mod_jk to forward requests to /jmx-console and /web-console to Apache.
The syntax required takes the form /url=worker_name.
# Simple worker configuration file
# Mount the Servlet context to the ajp13 worker
/jmx-console=loadbalancer
/jmx-console/*=loadbalancer
/web-console=loadbalancer
/web-console/*=loadbalancer
In 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
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.
Prerequisites
Understand the format of the workers.properties directives, as specified in Appendix A, workers.properties Reference.
Task: Configure Apache to Load mod_jk
Navigate to HTTPD_DIST/conf/.
Create a file named workers.properties.
Append the following information into the workers.properties file.
# Define list of workers that will be used
# for mapping requests
worker.list=loadbalancer,status
# Define dev1
# modify the host as your host IP or DNS name.
worker.dev1.port=8009
worker.dev1.host=dev1.srinivaslinux.com
worker.dev1.type=ajp13
worker.dev1.ping_mode=A
worker.dev1.lbfactor=1
# Define dev2
# modify the host as your host IP or DNS name.
worker.dev2.port=8009
worker.dev2.host=dev2.srinivaslinux.com
worker.dev2.type=ajp13
worker.dev2.ping_mode=A
worker.dev2.lbfactor=1
# Load-balancing behavior
worker.loadbalancer.type=lb
worker.loadbalancer.balance_workers=dev1,dev2
worker.loadbalancer.sticky_session=1
# Status worker for managing load balancer
worker.status.type=status
Good Luck :)
No comments:
Post a Comment