Apache配置——支援JBoss叢集
一、為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
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配置成功: