Configuring HTTP Load Balancing
7 Configuring HTTP Load Balancing
This chapter describes how to configure HTTP load balancing on Eclipse GlassFish 7.
The following topics are addressed here:
For information on other types of load balancing, see Configuring Java Message Service High Availability and RMI-IIOP Load Balancing and Failover.
Setting Up HTTP Load Balancing
This section describes how to set up load balancing for Eclipse GlassFish.
The following topics are addressed here:
Prerequisites for Setting Up HTTP Load Balancing
Before configuring your load balancer, you must:
-
Install a supported web server and configure it. If using the
mod_jkormod_proxy_ajpmodules, the only supported web server is Apache HTTP Server 2.2.x. -
Configure the
mod_jkconnector module, as described in Configuring Eclipse GlassFish with Apache HTTP Server andmod_jk, or configure themod_proxy_ajpconnector module, as described in Configuring Eclipse GlassFish with Apache HTTP Server andmod_proxy_ajp. -
Create Eclipse GlassFish clusters or server instances to participate in load balancing.
-
Deploy applications to these clusters or instances.
Configuring Eclipse GlassFish with Apache HTTP Server and mod_jk
Eclipse GlassFish 7 can be configured for load balancing with Apache
HTTP Server as a front end by enabling the Apache mod_jk connector
module. To enable the mod_jk module in Eclipse GlassFish, set the
Eclipse GlassFish jk-enabled network-listener attribute. You can also
create jk-connectors under different virtual-servers using the
jk-enabled network-listener attribute.
To Configure the mod_jk Connector Module
-
Install Apache HTTP Server (
http://httpd.apache.org/docs/2.2/install.html) and mod_jk (http://tomcat.apache.org/connectors-doc/webserver_howto/apache.html). -
Configure
workers.propertiesandhttpd.conf. For example:-
apache2/config/workers.properties# Define 1 real worker using ajp13 worker.list=worker1 # Set properties for worker1 (ajp13) worker.worker1.type=ajp13 worker.worker1.host=localhost worker.worker1.port=8009 -
apache2/conf/httpd.confLoadModule jk_module /Users/Amy/apache2/modules/mod_jk-1.2.25-httpd-2.2.4.so JkWorkersFile /Users/Amy/apache2/conf/worker.properties # Where to put jk logs JkLogFile /Users/Amy/apache2/logs/mod_jk.log # Set the jk log level [debug/error/info] JkLogLevel debug # Select the log format JkLogStampFormat "[%a %b %d %H:%M:%S %Y] " # JkOptions indicate to send SSL KEY SIZE, JkOptions +ForwardKeySize +ForwardURICompat -ForwardDirectories # JkRequestLogFormat set the request format JkRequestLogFormat "%w %V %T" # Send everything for context /examples to worker named worker1 (ajp13) JkMount /examples/* worker1
-
-
Start Apache HTTP Server.
-
Create a jk-enabled network listener by using the
create-network-listenersubcommand.asadmin> create-network-listener --protocol http-listener-1 \ --listenerport 8009 --jkenabled true jk-connector -
If you are using the
glassfish-jk.propertiesfile, set thejk-configuration-fileproperty of the network listener to the fully-qualified file name of theglassfish-jk.propertiesfile.asadmin> set server-config.network-config.network-listeners.network-listener.\ jk-connector.jk-configuration-file=domain-dir/config/glassfish-jk.properties -
If you expect to need more than five threads for the listener, increase the maximum threads in the
http-thread-poolpool:asadmin> set configs.config.server-config.thread-pools.thread-pool.\ http-thread-pool.max-thread-pool-size=value -
Restart Eclipse GlassFish.
Example 7-1 httpd.conf File for Load Balancing
This example shows an httpd.conf file that is set for load balancing.
LoadModule jk_module /usr/lib/httpd/modules/mod_jk.so
JkWorkersFile /etc/httpd/conf/worker.properties
# Where to put jk logs
JkLogFile /var/log/httpd/mod_jk.log
# Set the jk log level [debug/error/info]
JkLogLevel debug
# Select the log format
JkLogStampFormat "[%a %b %d %H:%M:%S %Y] "
# JkOptions indicate to send SSL KEY SIZE,
JkOptions +ForwardKeySize +ForwardURICompat -ForwardDirectories
# JkRequestLogFormat set the request format
JkRequestLogFormat "%w %V %T"
# Send all jsp requests to GlassFish
JkMount /*.jsp worker1
# Send all glassfish-test requests to GlassFish
JkMount /glassfish-test/* loadbalancer
Example 7-2 workers.properties File for Load Balancing
This example shows a workers.properties or glassfish-jk.properties
file that is set for load balancing. The worker.worker*.port should
match with JK ports you created.
worker.list=worker1,worker2,loadbalancer
worker.worker1.type=ajp13
worker.worker1.host=localhost
worker.worker1.port=8009
worker.worker1.lbfactor=1
worker.worker1.socket_keepalive=1
worker.worker1.socket_timeout=300
worker.worker2.type=ajp13
worker.worker2.host=localhost
worker.worker2.port=8010
worker.worker2.lbfactor=1
worker.worker2.socket_keepalive=1
worker.worker2.socket_timeout=300
worker.loadbalancer.type=lb
worker.loadbalancer.balance_workers=worker1,worker2
Configuring Eclipse GlassFish with Apache HTTP Server and mod_proxy_ajp
Eclipse GlassFish 7 can be configured for load balancing with Apache
HTTP Server as a front end by enabling the Apache mod_proxy_ajp
connector module. To enable the mod_proxy_ajp module in Eclipse GlassFish, set the Eclipse GlassFish jk-enabled network-listener
attribute. You can also create jk-connectors under different
virtual-servers using the jk-enabled network-listener attribute.
To Configure the mod_proxy_ajp Connector Module
-
Install Apache HTTP Server (
http://httpd.apache.org/docs/2.2/install.html). -
Configure
httpd.conf. For example:LoadModule proxy_module /usr/lib/httpd/modules/mod_proxy.so LoadModule proxy_ajp_module /usr/lib/httpd/modules/mod_proxy_ajp.so Listen 1979 NameVirtualHost *:1979 <VirtualHost *:1979> ServerName localhost ErrorLog /var/log/apache2/ajp.error.log CustomLog /var/log/apache2/ajp.log combined <Proxy *> AddDefaultCharset Off Order deny,allow Allow from all </Proxy> ProxyPass / ajp://localhost:8009/ ProxyPassReverse / ajp://localhost:8009/ </VirtualHost> -
Start Apache HTTP Server.
-
Create a jk-enabled network listener by using the
create-network-listenersubcommand.asadmin> create-network-listener --protocol http-listener-1 \ --listenerport 8009 --jkenabled true jk-connector -
If you expect to need more than five threads for the listener, increase the maximum threads in the
http-thread-poolpool:asadmin> set configs.config.server-config.thread-pools.thread-pool.\ http-thread-pool.max-thread-pool-size=value -
Restart Eclipse GlassFish.
HTTP Load Balancer Deployments
You can configure your load balancer in different ways, depending on your goals and environment, as described in the following sections:
Using Clustered Server Instances
The most common way to deploy the load balancer is with a cluster or clusters of server instances. By default all the instances in a cluster have the same configuration and the same applications deployed to them. The load balancer distributes the workload between the server instances and requests fail over from an unhealthy instance to a healthy one. If you’ve configured HTTP session persistence, session information persists when the request is failed over.
If you have multiple clusters, requests can be load balanced across clusters but are only failed over between the instances in a single cluster. Use multiple clusters in a load balancer to easily enable rolling upgrades of applications. For more information, see Upgrading Applications Without Loss of Availability.
|
Requests cannot be load balanced across clusters and standalone instances. |
Using Multiple Standalone Instances
It is also possible to configure your load balancer to use multiple standalone instances, and load balance and failover requests between them. However, in this configuration, you must manually ensure that the standalone instances have homogenous environments and the same applications deployed to them. Because clusters automatically maintain a homogenous environment, for most situations it is better and easier to use clusters.
|
Load balancing across multiple standalone instances only provides failover for requests, and any associated HTTP session data will not be failed over. This is another reason why using a cluster, which can provide session failover, is a more desirable load balancing configuration. |