通过JK配置Apache与Tomcat的ajp连接

来源:互联网 发布:opportunity cost算法 编辑:程序博客网 时间:2024/04/29 13:35

 关于Apache 与 Tomcat 的连接方式,在一篇文章中已经进行了详细的介绍:http://www.ibm.com/developerworks/cn/opensource/os-lo-apache-tomcat/index.html

 

以下是本人参照网上资料做的情况:

(1) 下载Tomcat 6.0.20并安装;

(2) 下载Apache 2.2并安装;

(3) 下载JK module改名为mod_jk.so并安置到apache 2.2/modules目录下(http://labs.xiaonei.com/apache-mirror/tomcat/tomcat-connectors/jk/binaries/win32/jk-1.2.28/);

 

(4) 修改apache 2.2/conf/httpd.conf文件,增加行"Include conf/mod_jk.conf"

 

(5) 在apache 2.2/conf下增加mod_jk.conf,文件内容为:

#加载mod_jk模块
LoadModule jk_module modules/mod_jk.so
#集群配置
JkWorkersFile conf/workers.properties

#JkLogFile logs/mod_jk.log
#按时间分割日志
JkLogFile "|C:/apache2.2/bin/rotatelogs.exe C:/apache2.2/logs/mod_jk.%Y-%m-%d-%H.log 7200 480"
#
JkMountFile conf/uriworkermap.properties

JkLogLevel info
JkLogStampFormat "[%a %b %d %H:%M:%S %Y]"
JkOptions +ForwardKeySize +ForwardURICompat -ForwardDirectories
JkRequestLogFormat "%w %V %T"

#关掉主机Lookup,如果为on,很影响性能,可以有10多秒钟的延迟。
HostnameLookups Off

 

(6) 在apache 2.2/conf下增加workers.properties,文件内容为:

worker.list=worker1
# Set properties for worker1 (ajp13)
worker.worker1.type=ajp13
worker.worker1.host=127.0.0.1
worker.worker1.port=8009
worker.worker1.lbfactor=50
worker.worker1.cachesize=10
worker.worker1.cache_timeout=600
worker.worker1.socket_keepalive=1
worker.worker1.socket_timeout=300

 

注:如果需要配置集群的话,可以将workers.properties文件内容修改如下:

#
# workers.properties
#


# list the workers by name

worker.list=DLOG4J, status

# localhost server 1
# ------------------------
worker.s1.port=8109
worker.s1.host=localhost
worker.s1.type=ajp13

# localhost server 2
# ------------------------
worker.s2.port=8209
worker.s2.host=localhost
worker.s2.type=ajp13
worker.s2.stopped=1

worker.DLOG4J.type=lb
worker.retries=3
worker.DLOG4J.balanced_workers=s1, s2
worker.DLOG4J.sticky_session=1

worker.status.type=status

(7) 在apache 2.2/conf下增加uriworkermap.properties文件,内容如下:

#监测集群状态
#/jkstatus=status
#jsp文件通过负载平衡分发
/*.jsp=worker1
/*.action=worker1
/*.dwr=worker1
#jpg文件不通过负载平衡分发
!/*.jpg=worker1
!/*.gif=worker1
!/*.css=worker1
!/*.js=worker1
!/*.swf=worker1
!/*.htm=worker1
!/*.html=worker1

 

注:集群的配置则需修改如下:

/*=DLOG4J
/jkstatus=status

!/*.gif=DLOG4J
!/*.jpg=DLOG4J
!/*.png=DLOG4J
!/*.css=DLOG4J
!/*.js=DLOG4J
!/*.htm=DLOG4J
!/*.html=DLOG4J

(8) 修改tomcat/conf/server.xml文件,将ajp连接打开,具体配置如下:

<Connector port="8009" proxyPort="443" scheme="https" secure="true" protocol="AJP/1.3" redirectPort="8443" maxThreads="300" />

 

另外,如果是配置https,则可以增加如下配置:

<Connector port="8443" protocol="HTTP/1.1" SSLEnabled="true" maxHttpHeaderSize="3500"
               maxThreads="150" scheme="https" secure="true"
               clientAuth="false" sslProtocol="TLS" keystoreFile="C:/apache-tomcat-6.0.20/bin/server.keystore" keystorePass="changeit" />

原创粉丝点击