您的位置:首页 > 运维架构 > Tomcat

windows平台上Tomcat 6与Apache的整合步骤

2015-05-13 21:45 363 查看
假设:Tomcat6已安装在 C:Tomcat6.0,Apache2.2已安装在 C:xamppxamppapache中,
java 的 jdk(或jre)已安装到C:Program FilesJavajdk中。
若已安装 mod_jserv ,应先移除,因与 mod_jk 不兼容。下述步骤中,(三)中的3)和4)只可选其一:

(一)将Win32版本的二进制(binary)文件 mod_jk-xxx.so 从http://tomcat.apache.org/download-connectors.cgi
(或 http://labs.xiaonei.com/apache-mirror/tomcat/tomcat-connectors/jk/binaries/)下载, 复制到apache的module目录中,并改名为mod_jk.so;

(二)在tomcat安装目录的conf目录下,生成文件 workers.properties(需要更改你的Tomcat和Java的路径):

workers.tomcat_home=C:/Tomcat6.0
workers.java_home=C:/Program Files/Java/jdk
# You should configure your environment slash... ps= on NT and / on UNIX
# and maybe something different elsewhere.
ps=

# Add 'inprocess' if you want JNI connector
worker.list=ajp12, ajp13

# Defining a worker named ajp12 and of type ajp12
# Note that the name and the type do not have to match.
#
worker.ajp12.port=8007
worker.ajp12.host=localhost
worker.ajp12.type=ajp12
worker.ajp12.lbfactor=1

# Defining a worker named ajp13 and of type ajp13
# Note that the name and the type do not have to match.
#
worker.ajp13.port=8009
worker.ajp13.host=localhost
worker.ajp13.type=ajp13
worker.ajp13.lbfactor=1

# ----> If a worker dies, the load balancer will check its state
# once in a while. Until then all work is redirected to peer
# workers.
worker.loadbalancer.type=lb
worker.loadbalancer.balance_workers=ajp12, ajp13

# Defining a worker named inprocess and of type jni
# Note that the name and the type do not have to match.
#
worker.inprocess.type=jni

# Additional class path components.
#
worker.inprocess.class_path=$(workers.tomcat_home)$(ps)lib$(ps)tomcat.jar

#
# Setting the command line for tomcat.
# Note: The cmd_line string may not contain spaces.
#
worker.inprocess.cmd_line=start

# The JVM that we are about to use
#
# This is for Java2
#
# Windows
worker.inprocess.jvm_lib=$(workers.java_home)$(ps)jre$(ps)bin$(ps)classic$(ps)jvm.dll
# IBM JDK1.3
#worker.inprocess.jvm_lib=$(workers.java_home)$(ps)jre$(ps)bin$(ps)classic$(ps)libjvm.so
# Unix - Sun VM or blackdown
#worker.inprocess.jvm_lib=$(workers.java_home)$(ps)jre$(ps)lib$(ps)i386$(ps)classic$(ps)libjvm.so
#
# Setting the place for the stdout and stderr of tomcat
#
worker.inprocess.stdout=$(workers.tomcat_home)$(ps)logs$(ps)inprocess.stdout
worker.inprocess.stderr=$(workers.tomcat_home)$(ps)logs$(ps)inprocess.stderr

(三)如果Tomcat和Apache在一部电脑中,可以使用Tomcat自动生成的配置文件,用来告诉Apache使用Tomcat的指令解析jsp等动态文件。此文件自动生成方法:

1)在tomcat.xml中的Engine部分中增加一行,指向你在(一)中刚放入文件:

...
<Engine ...>
...
<Listener className="org.apache.jk.config.ApacheConfig" modJk="《路径》/mod_jk.so" />
...
</Engine>
...

2)重新启动Tomcat,会在conf目录下生成子目录auto或jk,其中包含文件mod_jk.conf;

3)在apache的conf下的配置文件httpd.conf的最后一行加入:

Include “C:/Tomcat6.0/conf/auto/mod_jk.conf”

重新启动apache,完成。

4) 如果apache服务器与Tomcat不在一部电脑中(特别地,apache后有一组Tomcat服务器),不能用此自动生成的mod_jk.conf文件,可在httpd.conf后加入:

# Load mod_jk module
LoadModule jk_module modules/mod_jk.so
# Where to find workers.properties
JkWorkersFile C:/Tomcat6.0/conf/workers.properties
# Where to put jk logs
JkLogFile c:/xampp/xampp/apache/logs/mod_jk.log
# Set the jk log level [debug/error/info]
JkLogLevel info
# Select the timestamp log format
JkLogStampFormat "[%a %b %d %H:%M:%S %Y] "

# send all requests ending in .jsp to ajp13 (see "worker.list=ajp12, ajp13" defined in workers.properties,)
JkMount /*.jsp ajp13
# send all requests ending /servlet to worker “ajp13"
JkMount /*/servlet/ ajp13
# send all requests jsp requests to files located in /otherworker will go to worker “ajp12"
JkMount /otherworker/*.jsp ajp12

重新启动apache(如你的程序需要用到数据库,请记得启动数据库服务器),完成。

参看:http://tomcat.apache.org/connectors-doc/webserver_howto/apache.html
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: