Setup
Apache HTTPD Server 2.2.8
3 Tomcat 6.0.16
Windows XP
No FIREWALL!!!
Load Balancer Choice
The mod_proxy_ajp was chosen as the load balancer because it provides good performance and easy setup. AJP is a simplified HTTP protocol that Tomcat and Httpd can use to communicate. You can also use the HTTP proxy module if you'd like.
Required httpd.conf Changes
[... ]
LoadModule proxy_module modules/mod_proxy.so
LoadModule proxy_ajp_module modules/mod_proxy_ajp.so
LoadModule proxy_balancer_module modules/mod_proxy_balancer.so
LoadModule proxy_connect_module modules/mod_proxy_connect.so
LoadModule rewrite_module modules/mod_rewrite.so
LoadModule status_module modules/mod_status.so
[...]
<location>
SetHandler balancer-manager
Order Deny,Allow
Deny from all
Allow from localhost
</location>
<proxy>
Order Deny,Allow
Allow from all
</proxy>
<ifmodule>
<virtualhost>
# Don't allow server to allow spam proxy usage
ProxyRequests Off
# Give all possible load balancing information
ProxyStatus Full
# Allow access to the balancer-manager using httpd instead of tomcat
ProxyPass /balancer-manager !
ProxyPass /logs !
# Setup pass to balancer for tomcat calls
# ProxyPass / balancer://mycluster stickysession=JSESSIONID nofailover=Off lbmethod=bytraffic timeout=1
ProxyPassMatch ^(/.*)$ balancer://mycluster stickysession=JSESSIONID nofailover=Off lbmethod=bytraffic timeout=1
# Fix redirects
ProxyPassReverse / ajp://10.1.0.113:7009/
ProxyPassReverse / ajp://10.1.0.113:8009/
ProxyPassReverse / ajp://10.1.0.113:9009/
# Make sure cookies are still going to work
#ProxyPassReverseCookieDomain localhost localhost:6080
#ProxyPassReverseCookieDomain localhost:8009 localhost:6080
#ProxyPassReverseCookieDomain localhost:9009 localhost:6080
#ProxyPassReverseCookiePath / /
# Define cluster
<proxy>
BalancerMember ajp://10.1.0.113:7009 loadfactor=1 route=jvm1
BalancerMember ajp://10.1.0.113:8009 loadfactor=1 route=jvm2
BalancerMember ajp://10.1.0.113:9009 loadfactor=1 route=jvm3
</proxy>
</virtualhost>
</ifmodule>
NOTES:
- The 'route' parameter is necessary unlike I originally thought. It is appended onto the session idea in tomcat and the name must correspond to the tomcat instance being referenced by the balancer.
Tomcat Server.xml file
This cluster configuration requires minor tweaks in each tomcat instance and fields like 'jvmRoute' must match the 'route' parameter in the httpd.conf.
[...]
<Engine name="Catalina2" defaultHost="localhost" jvmRoute="jvm2">
<Cluster className="org.apache.catalina.ha.tcp.SimpleTcpCluster"
channelSendOptions="7" clusterName="mgstTomcatCluster">
<Manager className="org.apache.catalina.ha.session.DeltaManager"
expireSessionsOnShutdown="false"
notifyListenersOnReplication="true"/>
<Channel className="org.apache.catalina.tribes.group.GroupChannel">
<Membership className="org.apache.catalina.tribes.membership.McastService"
address="228.0.0.4"
port="45564"
frequency="500"
dropTime="3000"/>
<Receiver className="org.apache.catalina.tribes.transport.nio.NioReceiver"
address="auto"
port="4002"
autoBind="100"
selectorTimeout="5000"
maxThreads="6"/>
<Sender className="org.apache.catalina.tribes.transport.ReplicationTransmitter"
waitforAck="true" replicationMode="pooled">
<Transport className="org.apache.catalina.tribes.transport.nio.PooledParallelSender"/>
</Sender>
<Interceptor className="org.apache.catalina.tribes.group.interceptors.TcpFailureDetector"/>
<Interceptor className="org.apache.catalina.tribes.group.interceptors.MessageDispatch15Interceptor"/>
</Channel>
<Valve className="org.apache.catalina.ha.tcp.ReplicationValve"
filter="" statistics="true"/>
<ClusterListener className="org.apache.catalina.ha.session.ClusterSessionListener"/>
</Cluster>
[...]
Questions/Comments
Feel free to post questions in the comments section, or email me if you want some help setting up a cluster like this.
No comments:
Post a Comment