Tomcat 使用JK 集成到Apache

来源:互联网 发布:同花顺mac版下载 编辑:程序博客网 时间:2024/04/29 07:34

集成到apache的好处:

1.可以使用apache处理静态资源的优势

2.使用apache进行gzip,缓存

3.负载均衡

4.使用apache统一的端口,不需要另开端口


配置:主要参考tomcat文档,如下链接:

http://tomcat.apache.org/connectors-doc/webserver_howto/apache.html

http://tomcat.apache.org/connectors-doc/generic_howto/workers.html

jk下载地址:http://www.apache.org/dist/tomcat/tomcat-connectors/jk/binaries/windows/

注意:保证apache与jk的版本一致

在apache主目录里添加一个jk目录,将下载的mod_jk.so放在jk目录

1.在jk目录新建配置文件 jk.conf

# Load mod_jk module
LoadModule    jk_module  jk/mod_jk.so

#指向workers.properties文件
JkWorkersFile jk/workers.properties
# Where to put jk shared memory
#JkShmFile     /var/log/httpd/mod_jk.shm
# Where to put jk logs
JkLogFile     jk/log/jk.log
# Set the jk log level [debug/error/info]
JkLogLevel    error
# Select the timestamp log format
JkLogStampFormat "[%a %b %d %H:%M:%S %Y] "

2.新建 文件workers.properties (tomcat个数,负载均衡都在这里面配置)

worker.list=worker1
# worker "worker1" will talk to Tomcat listening on machine www2.x.com at port 8009 using 3 lb factor
worker.worker1.type=ajp13
worker.worker1.host=localhost
worker.worker1.port=8082
#worker.worker1.lbfactor=3
# worker "worker1" uses connections, which will stay no more than 10mn in the connection pool
worker.worker1.connection_pool_timeout=600
# worker "worker1" ask operating system to send KEEP-ALIVE signal on the connection
worker.worker1.socket_keepalive=1

3.在httpd.conf内加载jk.conf (可以在文件的最后面,注:不能在 <VirtualHost *:80> 内)

Include jk/jk.conf

4.配置httpd.conf 添加tomcat webapps内的应用

Alias /crm "D:/app/crm/apache-tomcat/webapps/crm/"
<Directory "D:/app/crm/apache-tomcat/webapps/crm/">
    DirectoryIndex index.html index.htm index.php index.jsp
    Options Indexes MultiViews
    AllowOverride None
    Order allow,deny
    Allow from all
</Directory>

5.配置URL 处理方式,除了静态资源,其他都由worker1处理

# Send servlet for context /examples to worker named worker1
JkMount  /crm/* worker1  
JkUnMount /crm/*.html worker1
JkUnMount /crm/*.jpg  worker1
JkUnMount /crm/*.gif  worker1
JkUnMount /crm/*.js  worker1
JkUnMount /crm/*.png  worker1

如果是<VirtualHost *:80>的方式则必须在VirtualHost 内,否则添加到文件末尾或者4之后



其他:

1.查看mod_jk是否加载成功 httpd -M

2.查看处理结果: 

1)jk.log 将 JkLogLevel    调整到相应级别

2)tomcat 内的access logs

3)apache logs目录内的 access.log error.log