Apache与Tomcat整合问题的新方法
2024-08-27 18:29:11
供稿:网友
中国最大的web开发资源网站及技术社区,
配置目的:
将apache作为两个tomcat server的前端,负责转发client request和server reponse。
apache地址:10.194.0.131
tomcat server地址:10.11.1.29、10.11.1.2
配置步骤如下:
一、下载新版本的apache 2.0.54和tomcat connector 1.2.14.1源代码,编译安装apache和connector:
1.在apache的源代码目录中运行buildconf、configure --prefix=/usr/local/apache2.0.54、make、make install,将apache安装到/usr/local/apache2.0.54目录中。
2.在connector源代码目录的jk/native/运行buildconf、configure --with-apxs=/usr/local/apache2.0.54/bin/apxs、make、make install,将mod_jk.so安装到/usr/local/apache2.0.54/modules目录。
二、配置apache:
1.配置workers属性文件:在apache的conf目录中建立workers.properties文件,内容如下:
ps=/worker.list=worker1,jvm1worker.worker1.port=8009worker.worker1.host=10.11.1.29worker.worker1.type=ajp13worker.worker1.socket_keepalive=trueworker.jvm1.port=8009worker.jvm1.host=10.11.1.2worker.jvm1.type=ajp13worker.jvm1.socket_keepalive=true
2.配置httpd.conf:
在loadmodule配置部分加入一下内容:
loadmodule jk_module modules/mod_jk.so# where to find workers.propertiesjkworkersfile /usr/local/apache2.0.54/conf/workers.properties# where to put jk logsjklogfile
/usr/local/apache2.0.54/mod_jk.log# set the jk log level [debug/error/info]jkloglevel
info# select the log formatjklogstampformat "[%a %b %d %h:%m:%s %y] "# jkoptions indicate to send ssl key size, jkoptions
+forwardkeysize +forwarduricompat -forwarddirectories# jkrequestlogformat set the request format jkrequestlogformat "%w %v %t"
在virtualhost配置如下内容:
namevirtualhost *:80<virtualhost 10.194.0.131:80>
serveradmin [email protected]
servername 10.11.1.29
directoryindex index.jsp index.html
<location "/">
</location>
jkmount /* worker1</virtualhost><virtualhost 10.194.0.132:80>
serveradmin [email protected]
servername 10.11.1.2
<location "/">
</location>
jkmount /* jvm1</virtualhost>
三、配置tomcat:
1.修改10.11.1.29的server.xml文件:
找到<engine>…</engine>增加jvmroute属性:
<engine jvmroute="worker1" classname="org.apache.catalina.core.standardengine" backgroundprocessordelay="10" basedir="e:/tomcat 5.0" debug="0" defaulthost="localhost" domain="catalina" name="catalina">…</engine>
2.修改10.11.1.2的server.xml文件:
找到<engine>…</engine>增加jvmroute属性:
<engine jvmroute="jvm1" classname="org.apache.catalina.core.standardengine" backgroundprocessordelay="10" basedir="e:/tomcat 5.0" debug="0" defaulthost="localhost" domain="catalina" name="catalina">…</engine>
四、扩展功能:
可以配置多个tomcat作为相同web application的多个server,并使用apache的负载均衡特性,已做到相同web application的多个server之间的负载均衡,提高web访问效率。本文中例子并没有实现此特性。大家自己按着文档试试吧。