免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
最近访问板块 发新帖
查看: 14114 | 回复: 4
打印 上一主题 下一主题

[Web] 请教Apache和Tomcat的关系? [复制链接]

论坛徽章:
0
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2005-11-22 10:57 |只看该作者 |倒序浏览
1、为什么要整合Apache和Tomcat?
2、没有Apache,Tomcat会出现什么问题?
3、Tomcat对静态网页的处理相对于Apache难道真的非常差吗?差多少?有没有哪位朋友有这方面的数据可以提供。

谢谢!

论坛徽章:
0
2 [报告]
发表于 2005-11-22 14:23 |只看该作者
Why should I integrate Apache with Tomcat? (or not)


There are many reasons to integrate Tomcat with Apache. And there are reasons why it should not be done too. Needless to say, everyone will disagree with the opinions here. With the upcoming performance of Tomcat 5, performance reasons become harder to justify. So here are the issues to discuss in integrating vs not.


1.Clustering. By using Apache as a front end you can let Apache act as a front door to your content to multiple Tomcat instances. 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


2.Clustering/Security. You can also use Apache as a front door to different Tomcats for different URL namespaces (/app1/, /app2/, /app3/, or virtual hosts). 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. Essentially, Apache becomes a smart proxy server.




3.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. 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.


4.Add-ons. Adding on CGI, perl, PHP is very natural to Apache. Its slower and more of a kludge for Tomcat. 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.



5.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. 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?




6.Speed. Apache is faster at serving static content than Tomcat. But unless you have a high traffic site, this point is useless. But in some scenarios, tomcat can be faster than apache. So benchmark YOUR site.



7.Socket handling/system stability. Apache has better socket handling with respect to error conditions than Tomcat. The main reason is Tomcat must perform all its socket handling via the JVM which needs to be cross platform. 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. (YMMV)



8.Here is a great response from Craig R. McClanahan. If you have free time, read emails by him in any of the list archives. You'll learn a lot.










原文http://tomcat.apache.org/faq/connectors.html#integrate

论坛徽章:
0
3 [报告]
发表于 2005-11-22 14:25 |只看该作者
主要目的

1. tomcat不建议用root跑,而linux下面不可以用非root帐号跑80端口 (除了apache外,也可以用iptables)
2. 用mod_jk做软负载均衡
3. tomcat是单一的java servlet container,如果没有apache则不可以运行php, perl等程序
4. 简单的IMAGE/HTML/ARCHIVE文件在tomcat上也是经过java线程处理,比较浪费资源

论坛徽章:
0
4 [报告]
发表于 2005-11-22 22:20 |只看该作者

谢谢两位

我把Why should I integrate Apache with Tomcat? (or not) 大概翻译了一下,由于没有接触过大的web站点,对一些专有名词可能不正确,并且我的英语确实很烂,紧紧只是稍稍看懂罢了,请各位指正。

给我个集成(或者不集成)Apache和Tomcat的理由

有很多的理由将Tomcat和Apache集成,同样也有很多的理由不这样做。在Tomcat 5中,性能不在是决定性因素。以下就是集成与不集成的讨论:

1、聚合。使用Apache做为前端大门,后端部署多个Tomcat实例,如果一个实例出现问题,Apache将忽略这个实例,让系统管理员高枕无忧。当然如果在硬件负载均衡设备的基础上利用Tomcat的聚合能力就没有必要进行集成了。

2、聚合/安全。当然如果使用Apache做为门户来区分拥有不同URL命名空间的不同的Tomcat。每个Tomcat都成为一个保护区域,从安全角度讲,仅仅需要主要Apache 服务器。在这个方案中,Apache已经变成一个轻量级的代理服务器。

3、安全。就安全来讲,集成和不集成都是争论双方的焦点。Java有安全管理功能,Apache对安全考虑的也是比较周道的。可以使用Google来查阅这方面的资料。在某个场合中,集成是上上策,但是另外一个场合,可能不集成略胜一筹。但是如果集成Apache和Tomcat,一定要记住:你需要同时关注Apache和Tomcat的安全,而不是一个。

4、附加因素。在Apache上运行perl,PHP和CGI都是很普通的事情。但是对Tomcat来说,不仅速度忙,而且不太正式。Apache可以任意添加上百个附加软件,当然Tomcat也有这个能力,但是这样的模块还没有开发出来。

5、装饰。当Apache做为Tomcat前端时,你可以完成大量Tomcat不支持或没有现成代码的装饰工作。没有必要重新为Tomcat开发一套类似为Apache的mod_headers,mod_rewrite, and mod_alias。

6、速度。Apache的静态网页处理速度高于Tomcat。但是除非你的流量很大,这一点时没有意义的。在另外一些情况下,Tomcat要比Apache快。所以两者结合可以加速你的站点。

7、Socket handling(姑且认为是连接)/系统稳定性。Apache在处理错误链接上优于Tomcat。主要原因是Tomcat所有的连接都交给JVM来处理,而JVM是跨平台的,问题是跨平台的优化是一个严峻的考验。大部分时间java程序都是正常的,但是当情况非常恶劣时,例如:非常频繁的掉线,无效数据包,无效IP的无效请求。Apache比基于JVM的程序要好。


因为我所有的页面都是html(xml+xslt=html+css=我的站点)。所以Apache是最优选择了。

[ 本帖最后由 puma_soft 于 2005-11-22 22:46 编辑 ]

论坛徽章:
0
5 [报告]
发表于 2005-11-22 23:52 |只看该作者
原帖由 jhsea3do 于 2005-11-22 14:25 发表
主要目的

1. tomcat不建议用root跑,而linux下面不可以用非root帐号跑80端口 (除了apache外,也可以用iptables)
2. 用mod_jk做软负载均衡
3. tomcat是单一的java servlet container,如果没有apache则不可以 ...


同意.
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP