Apache2.2.11+Tomcat6.0.20集群配置
Apache2.x和Tomcat配置可以采用反向代理的方式(mod proxy),也可以采用JK模块,最终采用了JK模块,JK模块的效率要比反向代理高,这是Apache官方网站上说的,我没有测试过。JK配置虽然复杂,但更加灵活。
首先,下载Apache2.2.11,Tomcat6.0.20解压版,以及mod_jk-1.2.28-httpd-2.2.3.so
安装Apache服务器,将mod_jk-1.2.28-httpd-2.2.3.so重命名为mod_jk.so并拷贝到Apache安装目录下的modules文件夹中。
在Apache2.2安装目录的conf文件夹下,建立以下3个文件:
mod_jk.conf、workers.properties、uriworkermap.properties
在httpd.conf最后加上:
-
#?JK?module?settings ??
-
Include?conf/mod_jk.conf??
# JK module settings Include conf/mod_jk.conf
表示将mod_jk.conf配置文件包含进来,以下是mod_jk.conf文件的内容:
-
#?Load?JK?Module ??
-
LoadModule?jk_module?modules/mod_jk.so ??
-
??
-
#?Configure?mod_jk ??
-
JkWorkersFile?conf/workers.properties ??
-
JkMountFile?conf/uriworkermap.properties ??
-
JkShmFile?logs/mod_jk.shm ??
-
JkLogFile?logs/mod_jk.log ??
-
JkOptions?+ForwardKeySize?+ForwardURICompat?-ForwardDirectories ??
-
JkLogLevel?warn ??
-
JkLogStampFormat?"[%a?%b?%d?%H:%M:%S?%Y]"??
-
HostnameLookups?Off ??
-
??
-
<Location?/jkmanager/> ??
-
????JkMount?jkstatus ??
-
????Order?deny,allow ??
-
????Deny?from?all ??
-
????Allow?from?127.0.0.1??
-
</Location>??
# Load JK Module LoadModule jk_module modules/mod_jk.so # Configure mod_jk JkWorkersFile conf/workers.properties JkMountFile conf/uriworkermap.properties JkShmFile logs/mod_jk.shm JkLogFile logs/mod_jk.log JkOptions +ForwardKeySize +ForwardURICompat -ForwardDirectories JkLogLevel warn JkLogStampFormat "[%a %b %d %H:%M:%S %Y]" HostnameLookups Off <Location /jkmanager/> JkMount jkstatus Order deny,allow Deny from all Allow from 127.0.0.1 </Location>
?接下来配置workers.properties文件:
-
#?environment?slash?for?Windows(反斜杠代表Windows系统) ??
-
ps=\ ??
-
??
-
worker.retries=3??
-
??
-
#?此处定义了一个负载均衡器和状态监视器 ??
-
worker.list=loadbalancer,jkstatus ??
-
??
-
worker.tomcatA.type=ajp13 ??
-
worker.tomcatA.host=localhost ??
-
worker.tomcatA.port=9001??
-
worker.tomcatA.lbfactor=1??
-
worker.tomcatA.connection_pool_timeout=600??
-
worker.tomcatA.socket_keepalive=true??
-
worker.tomcatA.socket_timeout=60??
-
??
-
worker.tomcatB.type=ajp13 ??
-
worker