1. 需要准备的环境, Apache httpd server, tomcat7, mod_cluster的动态库(放在httpd里面),mod_cluster的jar包(放在tomcat里面)
jboss为了大家方便,提供了整合的一个包,包含了httpd和mod_cluster的动态库so,可以在官网下载,文件名大概这样,
mod_cluster-1.2.6.Final-linux2-x64.tar.gz,这样就不需要单独下载mod_cluster的so文件到httpd里面,只需要配置httpd.conf就好,另外tomcat连通httpd的jar包名称大概这样,mod_cluster-parent-1.2.6.Final-bin.tar.gz
2. http.conf的最末尾配置如下,192.168.91.128是web server地址,方便起见其实Allow from后面都可以填all
# MOD_CLUSTER_ADDS
# Adjust to you hostname and subnet.
<IfModule manager_module>
Listen 192.168.91.128:6666
ManagerBalancerName mycluster
<VirtualHost 192.168.91.128:6666>
<Location />
Order deny,allow
Deny from all
Allow from 192.168.91
</Location>
KeepAliveTimeout 300
MaxKeepAliveRequests 0
# ServerAdvertise on http://192.168.91.128:6666
AdvertiseFrequency 5
#AdvertiseSecurityKey secret
#AdvertiseGroup @ADVIP@:23364
EnableMCPMReceive
<Location /mod_cluster_manager>
SetHandler mod_cluster-manager
Order deny,allow
Deny from all
Allow from all
</Location>
</VirtualHost>
</IfModule>
ServerName localhost
3. tomcat的server.xml加上如下配置,
<Listener className="org.jboss.modcluster.container.catalina.standalone.ModClusterListener" proxyList="192.168.91.128:80" advertise="true"/>
4 最后访问192.168.91.128/xxxcontext/index.html就可以访问到后面几个tomcat中的一台,当然可以配置sticky session让一次会话中的多次请求都到同一个server中