/ 中存储网

Linux系统下Apache2.2.* + tomcat 6.0整合及优化配置

2013-12-07 08:48:15 来源:kejihao

一、整合

1、首先下载apache,以及tomcat 对应的版本,并下载相关版本的jk文件

apache2.2.15

tomcat6.0

mod_jk-1.2.30-httpd-2.2.3.so

在tomcat下新建文件workers.properties 复制内容

workers.tomcat_home=E:Tomcat6.0 #让mod_jk模块知道Tomcat的位置

workers.java_home=E:Javajre1.6.0 #让mod_jk模块知道jre的位置

ps=

worker.list=ajp13 #模块版本

worker.ajp13.port=8009 #工作端口,若没占用则不用修改

worker.ajp13.host=localhost #本机,若上面的Apache主机不为localhost,作相应修改

worker.ajp13.type=ajp13 #类型

worker.ajp13.lbfactor=1 #代理数,不用修改

2、修改httpd.conf

将jk拷入apache的modules中

在httpd.conf最后加上

#设置Apache与Tomcat之间的连接,让Apache遇到jsp文件时,在后台将其交由Tomcat去处理

LoadModule jk_module modules/mod_jk-1.2.30-httpd-2.2.3.so

#此处mod_jk的文件为你下载的文件

JkWorkersFile "E:/Tomcat6.0/conf/workers.properties"

#指定tomcat监听配置文件地址

JkLogFile "E:/Tomcat6.0/logs/mod_jk2.log"

#指定日志存放位置

JkLogLevel info

JkOptions +ForwardKeySize +ForwardURICompat -ForwardDirectories

JkMount /*/servlet/* ajp13

JkMount /*.jsp ajp13

JkMount /*.do ajp13

JkMount /*.action ajp13

二、优化

1、tomcat优化

<Connector port="8080" protocol="HTTP/1.1" maxHttpHeaderSize="8192" useBodyEncodingForURI="true"

connectionTimeout="20000" maxThreads="2048" minSpareThreads="125" maxSpareThreads="256"

redirectPort="8443" enableLookups="false" URIEncoding="UTF-8" acceptCount="1000" />

<Connector port="8009" protocol="AJP/1.3" maxHttpHeaderSize="8192" useBodyEncodingForURI="true"

connectionTimeout="20000" maxThreads="2048" minSpareThreads="125" maxSpareThreads="256"

redirectPort="8443" enableLookups="false" URIEncoding="UTF-8" acceptCount="1000" />

2、apache

在httpd.conf中找到这两个插件(mod_deflate.so,mod_expires.so),把注释去掉

#设置缓存的时间

<IfModule mod_expires.c>

ExpiresActive On

ExpiresDefault A0

# 1 年

<FilesMatch ".(flv|ico|pdf|avi|mov|ppt|doc|mp3|wmv|wav)$">

ExpiresDefault A9030400

</FilesMatch>

# 1 星期

<FilesMatch ".(jpg|jpeg|png|gif|swf)$">

ExpiresDefault A604800

</FilesMatch>

# 3 小时

<FilesMatch ".(txt|xml|js|css)$">

ExpiresDefault A10800

</FilesMatch>

</IfModule>

#利用apache压缩传输数据

<IfModule mod_deflate.c>

DeflateCompressionLevel 7

AddOutputFilterByType DEFLATE text/html text/plain text/xml application/x-httpd-php

AddOutputFilter DEFLATE css js

#DeflateFilterNote Input instream

#DeflateFilterNote Output outstream

#DeflateFilterNote Ratio ratio

#LogFormat '"%r" %{outstream}n/%{instream}n (%{ratio}n%%)' deflate

#CustomLog logs/deflate_log.log deflate

</IfModule>

压力测试(ab)下提高并发数

# Server-pool management (MPM specific)

Include conf/extra/httpd-mpm.conf

在windows下配置

# WinNT MPM

# ThreadsPerChild: constant number of worker threads in the server process

# MaxRequestsPerChild: maximum number of requests a server process serves

<IfModule mpm_winnt_module>

ThreadsPerChild 450

MaxRequestsPerChild 0

</IfModule>

在linux下

配置一下prefork 或者 worker的参数,这两种区别你可以上网差。用worker方式,混合进程+线程,吃cpu和内存小,支撑的量大不少