3.2. Configure Load Balancing Using Apache HTTP Server and mod_cluster
Note
2.4.x
as the Apache version, and select Tomcat
as the back end configuration.
3.2.1. Configure a Basic Proxy Server
3.2.1.1. Basic Proxy Configuration Overview
- Configure a Proxy Server listener to receive worker node connection requests and worker node feedback.
- Optional: Disable server advertisement.
The proxy server advertises itself using UDP multicast. When UDP multicast is available between the proxy server and the worker nodes, Server Advertisement adds worker nodes without further configuration required on the proxy server, and minimal configuration on the worker nodes.
3.2.1.2. Configure a Load-balancing Proxy Using mod_cluster
- Install JBoss Web Server, and configure the mod_cluster modules for your installation. See the JBoss Web Server Installation Guide for details.
Procedure 3.1. Configure a Load-balancing Proxy Using mod_cluster
Create a Listen Directive for the Proxy Server
Edit your mod_cluster configuration file (usuallyJWS_HOME/httpd/conf.d/mod_cluster.conf
), and add the following:Listen IP_ADDRESS:PORT_NUMBER
Where IP_ADDRESS is the address of the server network interface to communicate with the worker nodes, and PORT_NUMBER is the port on that interface to listen on.Note
The port must be open for incoming TCP connections.Example 3.1. Example Listen Directive
Listen 10.33.144.3:6666
Create a Virtual Host
Add the following to your mod_cluster configuration file:<VirtualHost IP_ADDRESS:PORT_NUMBER> <Directory /> Require ip IP_ADDRESS </Directory> KeepAliveTimeout 60 MaxKeepAliveRequests 0 ManagerBalancerName mycluster AdvertiseFrequency 5 EnableMCPMReceive On </VirtualHost>
Where IP_ADDRESS and PORT_NUMBER are the values from the Listen directive.Optional: Disable Server Advertisement
TheAdvertiseFrequency
directive makes the server to periodically send server advertisement messages via UDP multicast. By default, this occurs every 5 seconds.These server advertisement messages contain the IP_ADDRESS and PORT_NUMBER specified in the VirtualHost definition. Worker nodes configured to respond to server advertisements use this information to register themselves with the proxy server.To disable server advertisement, add the following directive to theVirtualHost
definition:ServerAdvertise Off
If server advertisements are disabled, or UDP multicast is not available on the network between the proxy server and the worker nodes, configure worker nodes with a static list of proxy servers. See Section 3.2.2.2, “Configuring a Worker Node with a Static Proxy List”.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_cluster, you can add the following to your Apache HTTP ServerLogFormat
directive(s):- %{BALANCER_NAME}e
- The name of the balancer that served the request.
- %{BALANCER_WORKER_NAME}e
- The name of the worker node that served the request.
For more information on Apache HTTP Server logging (including log rotation), see http://httpd.apache.org/docs/2.4/logs.html.Stop and Start the JBoss Web Server Apache Service
See the JBoss Web Server Installation Guide for detailed instructions.
3.2.2. Configuring Worker Nodes
3.2.2.1. Configuring a Tomcat Worker Node
Note
Supported Worker Node types
- Red Hat JBoss Web Server Tomcat service
mod_cluster JBoss Web Server Node Limitations
- Non-clustered mode only.
- Only one load metric can be used at a time when calculating the load balance factor.
- Install a supported JBoss Web Server.
- Understand the Proxy Configuration parameters discussed in Appendix B, Java Properties Reference.
Procedure 3.2. Configure a Tomcat Worker Node
Add a Listener to Tomcat
Add the followingListener
element beneath the other Listener elements inJWS_HOME/tomcat<VERSION>/conf/server.xml
.<Listener className="org.jboss.modcluster.container.catalina.standalone.ModClusterListener" advertise="true" stickySession="true" stickySessionForce="false" stickySessionRemove="true" />
Give the Worker a Unique Identity
EditJWS_HOME/tomcat<VERSION>/conf/server.xml
and add thejvmRoute
attribute and value to theEngine
element, as shown below:<Engine name="Catalina" defaultHost="localhost" jvmRoute="worker01">
Configure STATUS MCMP Message Frequency
Tomcat worker nodes periodically send status messages containing their current load status to the Apache HTTP Server balancer. The default frequency of these messages is 10 seconds. If you have hundreds of worker nodes, the STATUS MCMP Messages can increase traffic congestion on your Apache HTTP Server network.You can configure the MCMP message frequency by modifying theorg.jboss.modcluster.container.catalina.status-frequency
Java property. By default, the property accepts values in seconds*10. For example, setting the property to1
means 10 seconds. The example below demonstrates the frequency set to 60 seconds.-Dorg.jboss.modcluster.container.catalina.status-frequency=6
Optional Step: Configure Firewall for Proxy Server Advertisements
A proxy server using mod_cluster can advertise itself via UDP multicast. Most operating system firewalls block this by default. To enable server advertising and receive these multicast messages, open port 23364 for UDP connections on the worker node's firewall.For Red Hat Enterprise Linux 6
/sbin/iptables -A INPUT -m state --state NEW -m udp -p udp --dport 23364 -j ACCEPT -m comment -comment "receive mod_cluster proxy server advertisements"
If Automatic Proxy Discovery is not used, configure worker nodes with a static list of proxies. In this case you can safely ignore the following warning message:[warning] mod_advertise: ServerAdvertise Address or Port not defined, Advertise disabled!!!
For Red Hat Enterprise Linux 7
firewall-cmd --permanent --zone=public --add-port=23364/udp
For Microsoft Windows, using PowerShell
Start-Process "$psHome\powershell.exe" -Verb Runas -ArgumentList '-command "NetSh Advfirewall firewall add rule name="UDP Port 23364" dir=in action=allow protocol=UDP localport=23364"' Start-Process "$psHome\powershell.exe" -Verb Runas -ArgumentList '-command "NetSh Advfirewall firewall add rule name="UDP Port 23364" dir=out action=allow protocol=UDP localport=23364"'
3.2.2.2. Configuring a Worker Node with a Static Proxy List
- JBoss Web Server worker node configured. See Section 3.2.2.1, “Configuring a Tomcat Worker Node”.
- Understand the Proxy Configuration parameters, detailed in Appendix B, Java Properties Reference.
Procedure 3.3. Configure JBoss Web Server Worker Node with a Static Proxy List
Define a mod_cluster listener, and Disable Dynamic Proxy Discovery
EditJWS_HOME/tomcat<VERSION>/conf/server.xml
, and add a <Listener> element to theserver.xml
file. Set theadvertise
property of the ModClusterListener to false. For example:<Listener className="org.jboss.modcluster.container.catalina.standalone.ModClusterListener" advertise="false" stickySession="true" stickySessionForce="false" stickySessionRemove="true"/>
Create a static proxy server list
Add a comma separated list of proxies in the form of IP_ADDRESS:PORT as theproxyList
property. For example:Example 3.2. Example Static Proxy List
<Listener className="org.jboss.modcluster.container.catalina.standalone.ModClusterListener" advertise="false" stickySession="true" stickySessionForce="false" stickySessionRemove="true" proxyList="10.33.144.3:6666,10.33.144.1:6666"/>