tomcat和apache整合

我们为了提高静态页面的访问速度,需要把tomcat专门集成进web服务器,如apache或在IIS。

·集成的考虑因素

·集成技术的选择

·JK插件

·Tomcat体系接口与JK插件的工作原理

·Tomcat与IIS服务器的继承

·Tomcat与Apache服务器集成

 

 

 

集成的考虑因素:

集成的理由很多,不集成的理由也有很多,特别是5.0以后Tomcate的性能已经有了很大的改善。

是否集成要看具体的应用情况:

如:http://wiki.apache.org/tomcat/FAQ/Connectors 所述

我为什么要与Tomcat Apache的结合? (or not) (或不)

 

 

 

 

 

流行的和apache整合技术:

JK是目前的首选技术

JK2目前也不被支持

mod_proxy简单但不能实现有会话状态的负载均衡

什么是JK(或AJP)?

 

 

 

 

 

 

 

AJP is a wire protocol. AJP是一个有线协议。 It an optimized version of the HTTP protocol to allow a standalone web server such as Apache talk to Tomcat.这是HTTP协议的优化版本,让一个独立的Web服务器,例如Apache Tomcat的交谈。 Historically, Apache has always been much faster than Tomcat at serving static content.从历史上看,阿帕奇一直远远快于Tomcat的服务于静态内容。 The idea is to let Apache serve the static content when possible, then proxy the request back to Tomcat for Tomcat related content.这样做是为了让Apache的静态内容服务时,可能的话,那么代理的Tomcat的相关内容的请求到Tomcat的。

Which connector: mod_jserv, JK, JK2, mod_webapp or mod_proxy?

远离mod_webapp,又名经。 It is deprecated and unsupported due to lack of developer interest and there are better options such as jk and mod_proxy.它是过时和不支持,由于缺乏兴趣的发展商也有诸如JK和mod_proxy来更好的选择。 It WILL NOT run on windows. Do not use mod_webapp or warp.它不能运行在Windows上。 请不要使用mod_webapp或变形。

  • mod_jserv is unsupported and will not be supported in Tomcat 5. mod_jserv是不受支持的,不会在Tomcat 5的支持。 mod_jserv was the original connector which supported the ajp protocol. Do not use mod_jserv. mod_jserv是原来的连接器,其中支持ajp协议。mod_jserv不要使用。

  • jk2 is a refactoring of mod_jk and uses the Apache Portable Runtime (apr). jk2是mod_jk的重构,并使用Apache可移植运行(4月)。 But due to lack of developer interest, it is unsupported.但是,由于开发商缺乏兴趣,这是不受支持的。 The alternative is mod_jk or mod_proxy_ajp. Do not use jk2.另一种是mod_jk的或mod_proxy_ajp。 不要使用jk2。

  • mod_jk is great and should be used for production . mod_jk的是伟大的应当用于生产It is still under active development and also works for the apache 2.X series for cases where you do not want to use mod_proxy_ajp.目前还正在积极发展,也为Apache 2.X的一系列工程的案件,您不希望使用mod_proxy_ajp。

  • mod_proxy. mod_proxy的。 A cheap way to proxy without the hassles of configuring JK.阿廉价的方法,代理没有配置JK的麻烦。 This solution lacks sticky session load balancing.该解决方案缺乏粘性会议负载平衡。 If you don't need some of the features of jk - this is a very simple alternative.如果你没有的JK需要的一些功能-这是一个非常简单的选择。
  • mod_proxy_ajp. mod_proxy_ajp。 With apache 2.2, mod_proxy was rewritten to support load balancing as well as a new transport called mod_proxy_ajp.与Apache 2.2,mod_proxy的被重写以支持负载平衡,以及新的运输称为mod_proxy_ajp。 This module is distributed with the Apache http server, not the Tomcat server.该模块分布与Apache HTTP服务器,而不是Tomcat服务器。
  •  

    There are many reasons to integrate Tomcat with Apache.原因是多方面的集成到Apache Tomcat的。 And there are reasons why it should not be done too.并且有为什么不应该做太多的理由。 Needless to say, everyone will disagree with the opinions here.不用说,每个人会不同意的意见在这里。 With the performance of Tomcat 5 and 6, performance reasons become harder to justify.随着Tomcat的5和6的性能,性能的原因变得难以判断。 So here are the issues to discuss in integrating vs not.因此,这里的问题的讨论没有纳入队。

    • Clustering.聚类。 By using Apache as a front end you can let Apache act as a front door to your content to multiple Tomcat instances.通过使用一个前端,您可以让一个前门内容到多个Tomcat实例阿帕奇阿帕奇的行为。 If one of your Tomcats fails, Apache ignores it and your Sysadmin can sleep through the night.如果您的雄猫一个失败,阿帕奇忽略它和您的系统管理员可以睡一个晚上。 This point could be ignored if you use a hardware loadbalancer and Tomcat's clustering capabilities.这一点可以忽略不计,如果您使用硬件负载均衡器和Tomcat的集群功能。
    • Clustering/Security.集群/安全。 You can also use Apache as a front door to different Tomcats for different URL namespaces (/app1/, /app2/, /app3/, or virtual hosts).您还可以用作前门不同的URL命名空间(/程序App1 /,/ app2 /,/ app3 /或虚拟主机不同雄猫阿帕奇)。 The Tomcats can then be each in a protected area and from a security point of view, you only need to worry about the Apache server.在雄猫然后可以每一个保护区,从安全角度来看,你只需要担心Apache服务器。 Essentially, Apache becomes a smart proxy server.从本质上讲,阿帕奇成为一个聪明的代理服务器。
    • Security.安全。 This topic can sway one either way.这个题目可支配一个痛苦。 Java has the security manager while Apache has a larger mindshare and more tricks with respect to security. Java的安全管理,同时阿帕奇有较大的心理份额和安全方面的更多的招数。 I won't go into this in more detail, but let Google be your friend.我不打算对此进行了更详细,但让谷歌成为你的朋友。 Depending on your scenario, one might be better than the other.根据您的情况下,人们可能会好于其他。 But also keep in mind, if you run Apache with Tomcat - you have two systems to defend, not one.但也请记住,如果你运行Tomcat的阿帕奇-你有两个系统的维护,而不是一个。
    • Add-ons.附加组件。 Adding on CGI, perl, PHP is very natural to Apache.基于CGI,Perl一样,PHP是很自然的添加到Apache。 Its slower and more of a kludge for Tomcat.它的速度和更多的是为Tomcat kludge。 Apache also has hundreds of modules that can be plugged in at will.阿帕奇也有数百个的模块,可以插入随意英寸 Tomcat can have this ability, but the code hasn't been written yet. Tomcat可以有这个能力,但代码还没有写呢。
    • Decorators!装饰! With Apache in front of Tomcat, you can perform any number of decorators that Tomcat doesn't support or doesn't have the immediate code support.随着前面的Tomcat是Apache,你可以执行任何的装饰数量Tomcat不支持或不具有直接的代码支持。 For example, mod_headers, mod_rewrite, and mod_alias could be written for Tomcat, but why reinvent the wheel when Apache has done it so well?例如,mod_headers,mod_rewrite的,并mod_alias可用于Tomcat的写,但为什么另起炉灶当Apache做得这么好?
    • Speed.速度。 Apache is faster at serving static content than Tomcat. Apache是在服务速度比Tomcat的静态内容。 But unless you have a high traffic site, this point is useless.但是,除非你有一个高流量的网站,这一点是没有用处的。 But in some scenarios, tomcat can be faster than Apache httpd.但是,在某些情况下,Tomcat可以更快比Apache httpd的。 So benchmark YOUR site. Tomcat can perform at httpd speeds when using the proper connector (APR with sendFile enabled).因此,基准您的网站。Tomcat可以在httpd的速度进行发送文件时使用正确的连接器(4月启用)。 Speed should not be considered a factor when choosing between Apache httpd and Tomcat 速度不应该考虑因素时选择与阿帕奇的httpd和Tomcat

    • Socket handling/system stability.插座处理/系统的稳定性。 Apache has better socket handling with respect to error conditions than Tomcat.阿帕奇已经就比Tomcat的错误条件处理好插座。 The main reason is Tomcat must perform all its socket handling via the JVM which needs to be cross platform.主要原因是通过Tomcat的必须执行的JVM需要加以跨平台处理所有的插座。 The problem is socket optimization is a platform specific ordeal.问题是插座优化是一个特定于平台的考验。 Most of the time the java code is fine, but when you are also bombarded with dropped connections, invalid packets, invalid requests from invalid IP's, Apache does a better job at dropping these error conditions than JVM based program.大多数情况下,Java代码是好的,但是当你也有下降的连接,无效的数据包,从无效的IP的,阿帕奇确实在下降超过JVM的这些错误的程序更好的工作条件,无效请求的轰炸。 (YMMV) (情况因人而异)

     

     

     ------------------------------------------------------------------------------------

    JK插件:

    ·IIS和apache等专门服务器都支持插件技术,可以将符合各种条件的请求交给插件区处理,IIS和apache能与tomcat集成的关键原因就是这种插件技术。

    ·如果在JK插件预先配置好的URL映射信息中,所有“/*.jsp”形式的URL都由Tomcat服务器处理,那么,当用户请求时,WEB服务器讲调用JK插件来处理,JK插件又把这个请求转发给tomcat服务器处理,tomcat服务器最后将相应的结果经JK插件传递给WEB服务器

    ·不同的web服务器查的插件形式是不同的,tomcat开发小组为不同的web服务器提供了相应的JK插件

    ·不同版本的tomcat与其他的web服务器的各种版本的集成时的JK插件也有可能不同

     

     

     

    下载JK插件

    http://tomcat.apache.org/

    Tomcat Connectors

    http://tomcat.apache.org/download-connectors.cgi

     

    我用的是:Apache HTTP Server 2.2
    apache-tomcat-6.0.18

    mod_jk-1.2.28-httpd-2.2.3.so

    放入apache modules 中,

    创建文件:

    workers.properties

    配置apache需要转发到的服务器的端口、地址、类型

    worker.list=worker1,worker2
    worker.worker1.type=ajp13
    worker.worker1.host=localhost
    worker.worker1.port=8009
    worker.worker1.type=ajp13
    worker.worker1.host=192.168.0.33
    worker.worker1.port=8009

    可以如上配置两个转发接收的服务器,也可以配置一个

    worker.list=worker1
    worker.worker1.type=ajp13
    worker.worker1.host=localhost
    worker.worker1.port=8009
    这三个参数不是随意配置的,一定要于我们tomcat server文件里面的

     <Connector port="8009" protocol="AJP/1.3" redirectPort="8443" />

    ajp监听配置一致

     

     

     

    我们的workers.properties 还可以配置如下:

     

    worker.list=ajp13w
    worker.worker1.type=ajp13
    worker.worker1.host=localhost
    worker.worker1.port=8009
    worker.ajp13w.type=lb
    worker.ajp13w.balance_workers=worker1

    负载均衡的配置,这样worker1就不能配置在list里面了,而在加入到ajp13w里

     

     

    放入apache conf目录中

     

     

    配置httpd.conf文件:

    加入Include conf/mod_jk.conf 或在,直接在httpd.conf加入mod_jk.conf的内容,如下:

     

    # Load mod_jk module
    LoadModule jk_module modules/mod_jk-1.2.28-httpd-2.2.3.so
    # Where to find workers.properties
    JkWorkersFile conf/workers.properties

    # Send JSPs for context /examples to worker named worker1
    JkMount /*.jsp worker1
    JkMount /*.do worker1

    注意这里的worker1不是乱写的,是我们上面workers.properties配置过的

     

     

     

     

     

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值