一、为Apache Web服务器安装mod_cluster插件
1安装文件
JBoss官方提供了mod_cluster的下载地址:
http://mod-cluster.jboss.org/downloads
直接把插件文件解压,拷贝到/opt/app/apache2/modules/mod_cluster-1.1.3目录:
当然,也可以把这些so文件,直接拷贝到/opt/app/apache2/modules目录。
注意:
下载的新版本的mod_cluster压缩文件里面的so可能不全,估计是因为那些so没有更新,所以没提供。
应该可以下载老版本的那些so文件代替。比如mod_cluster-1.2.0.Final-linux2-x64-so.tar.gz里面就没有mod_proxy_ajp.so,我就用1.1.3版本里面的so代替了。
2配置插件
打开/opt/app/apache2/conf/httpd.conf文件,
1、找到LoadModule配置模块所在的位置,添加如下配置项:(共6个so文件)
# Load the mod_cluster modules to support jboss cluster with uses ajp proxy
LoadModule proxy_module /opt/app/apache2/modules/mod_cluster-1.1.3/mod_proxy.so
LoadModule proxy_ajp_module /opt/app/apache2/modules/mod_cluster-1.1.3/mod_proxy_ajp.so
LoadModule slotmem_module /opt/app/apache2/modules/mod_cluster-1.1.3/mod_slotmem.so
LoadModule manager_module /opt/app/apache2/modules/mod_cluster-1.1.3/mod_manager.so
LoadModule proxy_cluster_module /opt/app/apache2/modules/mod_cluster-1.1.3/mod_proxy_cluster.so
LoadModule advertise_module /opt/app/apache2/modules/mod_cluster-1.1.3/mod_advertise.so
2、查找mod_proxy_balancer,如果启用了,则注释掉mod_proxy_balancer模块,因为此模块与mod_cluster相关模块不兼容:
#LoadModule proxy_balancer_module modules/mod_proxy_balancer.so
注:集群一般用的是ajp协议,如果是http协议,则将mod_proxy_ajp.so换成如下:
LoadModule proxy_http_module /opt/app/apache2/modules/mod_cluster-1.1.3/mod_proxy_ajp.so
二、Configure Apache httpd and mod_cluster
1详细配置mod_cluster
打开/opt/app/apache2/conf/httpd.conf文件,添加如下配置项:
# MOD_CLUSTER_ADDS
# Adjust to you hostname and subnet.
<IfModule manager_module>
Listen 122.119.122.163:6666
ManagerBalancerName dcmCluster
<VirtualHost 122.119.122.163:6666>
<Location />
Order deny,allow
Deny from all
Allow from 10.6
</Location>
KeepAliveTimeout 300
MaxKeepAliveRequests 0
ServerAdvertise On
AdvertiseFrequency 5
EnableMCPMReceive
AllowDisplay On
<Location /mod_cluster_manager>
SetHandler mod_cluster-manager
Order deny,allow
Deny from all
Allow from 172.26
</Location>
</VirtualHost>
</IfModule>
1、其中122.119.122.163:6666为Web服务器本机的IP+6666端口(一般都是配置6666端口,可以修改),本地测试时,可以配置为:127.0.0.1:6666
2、第一个Allow from是设置谁能访问:http://122.119.122.163:6666/
第二个Allow from是设置谁能访问:http://122.119.122.163:6666/mod_cluster_manager
注意:Allow from的IP可以只写前几位。
3、KeepAliveTimeout,顾名思义,指连接122.119.122.163:6666的最长存活时间。
4、MaxKeepAliveRequests,这个一般都是设置的0,估计是代表“不限制”最大连接数。
5、ServerAdvertise,广播(advertise)机制,说明如下:
ServerAdvertise On: Use the advertise mechanism to tell the JBoss AS/JBossWeb/Tomcat to whom it should send the cluster information.
ServerAdvertise On http://hostname:port: Tell the hostname and port to use. Only needed if the VirtualHost is not defined correctly, if the VirtualHost is a Name-based Virtual Host or when VirtualHost is not used.
ServerAdvertise Off: Don't use the advertise mechanism.
Default: Off. (Any Advertise directive in a VirtualHost sets it to On in the VirtualHost)
6、AdvertiseFrequency,一般都是配置的5分钟,默认是10分钟。
7、EnableMCPMReceive,一般都是这么配置的,说明如下:
Allow the VirtualHost to receive MCPM. Allow the VirtualHost to receive the MCPM from the nodes. You need one EnableMCPMReceive in your httpd configuration to allow mod_cluster to work, put it in the VirtualHost where you configure advertise.
2启动Apache,访问mod_cluster_manager
启动Apache后,用浏览器访问http://122.119.122.163:6666/mod_cluster_manager,能看到以下页面,说明web服务器mod_cluster配置成功: