`

httpd+tomcat

 
阅读更多
整合起来就是apache 的httpd.conf调用了workers.properties文件,然后apache根据这个workers.properties文件用 mod_jk.so连接调用TOMCAT来处理应用程序,以我这么菜来说,只能想到这些了。

1、首先安装JDK、APACHE2和TOMCAT5,我觉得在DEBIAN下面装的话还是从源代码编译的好,不然都找不到各个文件放在什么地方。安装就不说了,特别是TOMCAT,可以说简单,直接解压放到/use/local/就完事了,在这里假定这些软件都是用源代码安装的。

2、还要装jakarta-tomcat-connectors-1.2.14,其实就是mod_jk.so,这个我用源码安装:
[user@host] ~ $ ./configure --with-apxs=/path/to/your/apache/bin/apxs
[user@host] ~ $ make
[user@host] ~ $ cp ./apache-2.0/mod_jk.so /path/to/your/apache/modules/

3、在apache的配置文件最后面加上
#add for jsp
#Add Module
LoadModule jk_module modules/mod_jk.so

# Where to find workers.properties
JkWorkersFile /path/to/your/apache/conf/workers.properties

# Where to put jk logs
JkLogFile /path/to/your/apache/logs/mod_jk.log

# Set the jk log level [debug/error/info]
JkLogLevel info

# Select the log format
JkLogStampFormat "[%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"

# Send servlet for context / /servlet /application to worker
# named ajp13_worker
JkMount /*.jsp ajp13_worker
JkMount /servlet/* ajp13_worker
JkMount /application/* ajp13_worker

在这里我是这样理解的:
APACHE首先在启动时载入mod_jk.so模块
LoadModule jk_module modules/mod_jk.so

当APACHE收到后缀为JSP的请求时,转交由名字为ajp13_worker的"worker"处理,工作人员?呵呵
JkMount /*.jsp ajp13_worker
JkMount /servlet/* ajp13_worker
JkMount /application/* ajp13_worker

而这个"工作人员"是在文件名为workers.properties的配置文件中定义的,那么这个文件在什么地方呢,需要给APACHE指出来
JkWorkersFile /path/to/your/apache/conf/workers.properties

上面的代码其它基本上就是这个jakarta-tomcat-connectors的LOG文件的格式呀什么的。需要注意的是对APACHE指出的LOG文件
JkLogFile /path/to/your/apache/logs/mod_jk.log

不存在时,apachectl configtest会显示语法正确,当你apachectl start,APACHE并不会启动也不会在控制台上显示错误信息,只会在erro.log里面显示,所以安装时注意当指定的JkLogFile不存在时,就touch一个吧,接下来我们跳到workers.properties去。

4、workers.properties文件如下。
workers.tomcat_home=/path/to/your/tomcat5

# workers.java_home should point to your Java installation. Normally
# you should have a bin and lib directories beneath it.

workers.java_home=/usr/lib/j2sdk1.4-sun

# You should configure your environment slash... ps= on NT and / on UNIX
# and maybe something different elsewhere.

ps=/

# The workers that your plugins should create and work with

worker.list=ajp13_worker

# Defining a worker named ajp13_worker and of type ajp13
# Note that the name and the type do not have to match.

worker.ajp13_worker.port=8009
worker.ajp13_worker.host=localhost
worker.ajp13_worker.type=ajp13

# Specifies the load balance factor when used with
# a load balancing worker.
# Note:
# ----> lbfactor must be > 0
# ----> Low lbfactor means less work done by the worker.
worker.ajp13_worker.lbfactor=1

# The loadbalancer (type lb) workers perform wighted round-robin
# load balancing with sticky sessions.
# Note:
# ----> 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.balanced_workers=ajp13_worker

在这里可以看到前面httpd.conf里面的ajp13_worker就是在这里定义的,这里还指出了TOMCAT和JDK的目录等等,其实,只要COPY完就可以用了。

5、总结

想整合APACHE和TOMCAT,或者说在80端口下使用JSP,那就需要在httpd.conf文件里面加上一些语句,需要一个mod_jk.so,还需要创建一个workers.properties文件。
分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics