apache和tomcat整合问题? 400 报错
我整合的apache和tomcat 负载出了一个很头疼的问题
我的apache版本是 2.2.15 ,tomcat版本是6.0
我的 worker.properties
# In Unix, we use forward slashes:
ps=/
# list the workers by name
worker.list=tomcat4, loadbalancer
worker.loadbalancer.type=lb
worker.loadbalancer.balance_workers=tomcat4
worker.loadbalancer.sticky_session=true
worker.loadbalancer.sticky_session_force=true
worker.tomcat4.type=ajp13
worker.tomcat4.port=7029
worker.tomcat4.host=127.0.0.1
worker.tomcat4.lbfactor=1
worker.tomcat4.connection_pool_size=500
worker.tomcat4.connection_pool_timeout=60
worker.tomcat4.socket_keepalive=1
worker.tomcat4.socket_timeout=60
我的TOMCAT,AJP端口
<Connector port="7029"
protocolHandlerClassName="org.apache.jk.server.JkCoyoteHandler"
maxThreads="800" minSpareThreads="100" maxSpareThreads="200"
minProcessors="20" maxProcessors="800"
redirectPort="8443" acceptCount="2000"
connectionTimeout="200000"
protocol="AJP/1.3" />
那是我刚整合一两天的时候,有人反映网站打开很慢,到后来就一片空白。
我去看了服务器
首先我用 watch -n 1 -d 'pgrep httpd | wc-l'3
统计并发,平时并发是400左右,那时查了下达到了1300多,我停止apache,再启动还会涨到1300,最后我重启tomcat恢复正常。
我估计问题出在tomcat那里,我就查了下tomcat出问题时候的日志,如下。
==============================================================================================================日志开始
Last packet sent to the server was 1 ms ago.
at com.mysql.jdbc.Connection.createNewIO(Connection.java:2643)
at com.mysql.jdbc.Connection.<init>(Connection.java:1485)
at com.mysql.jdbc.NonRegisteringDriver.connect(NonRegisteringDriver.java:266)
at java.sql.DriverManager.getConnection(DriverManager.java:525)
at java.sql.DriverManager.getConnection(DriverManager.java:171)
at com.jb.base.cacheHelpBean.SaleInfoBean.salerinfo_num(SaleInfoBean.java:429)
at com.jb.base.cacheHelpBean.RevertUserSale.run(RevertUserSale.java:26)
at java.util.TimerThread.mainLoop(Timer.java:512)
at java.util.TimerThread.run(Timer.java:462)
com.mysql.jdbc.CommunicationsException: Communications link failure due to underlying exception:
** BEGIN NESTED EXCEPTION **
java.net.SocketException
MESSAGE: java.net.ConnectException: Connection refused
STACKTRACE:
java.net.SocketException: java.net.ConnectException: Connection refused
at com.mysql.jdbc.StandardSocketFactory.connect(StandardSocketFactory.java:156)
at com.mysql.jdbc.MysqlIO.<init>(MysqlIO.java:284)
at com.mysql.jdbc.Connection.createNewIO(Connection.java:2569)
at com.mysql.jdbc.Connection.<init>(Connection.java:1485)
at com.mysql.jdbc.NonRegisteringDriver.connect(NonRegisteringDriver.java:266)
at java.sql.DriverManager.getConnection(DriverManager.java:525)
at java.sql.DriverManager.getConnection(DriverManager.java:171)
at com.jb.base.cacheHelpBean.SaleInfoBean.salerinfo_num_cjbs(SaleInfoBean.java:493)
at com.jb.base.cacheHelpBean.RevertUserSale.run(RevertUserSale.java:27)
at java.util.TimerThread.mainLoop(Timer.java:512)
at java.util.TimerThread.run(Timer.java:462)
** END NESTED EXCEPTION **
...............................
..............................
2010-8-8 11:56:34 org.apache.jk.common.ChannelSocket processConnection
警告: processCallbacks status 2
2010-8-8 11:56:34 org.apache.jk.common.ChannelSocket processConnection
警告: processCallbacks status 2
2010-8-8 11:56:34 org.apache.jk.common.ChannelSocket processConnection
警告: processCallbacks status 2
更新成功2010-8-8 11:56:42 org.apache.jk.common.ChannelSocket processConnection
警告: processCallbacks status 2
2010-8-8 11:56:42 org.apache.jk.common.ChannelSocket processConnection
警告: processCallbacks status 2
...................................
....................................
2010-8-8 11:58:22 org.apache.tomcat.util.threads.ThreadPool$ControlRunnable run
严重: Caught exception (java.lang.OutOfMemoryError: Java heap space) executing org.apache.jk.common.ChannelSocket$SocketAcceptor@3c792b, terminating thread
2010-8-8 11:58:25 org.apache.jk.common.ChannelSocket processConnection
======================================================================================================日志结束
再查看JK的日志
=======================================================================================================日志开始
[Sun Aug 08 11:57:58.360 2010] [16103:3085982592] [info] service::jk_lb_worker.c (1388): service failed, worker tomcat4 is in local error state
[Sun Aug 08 11:57:58.360 2010] [16171:3085982592] [info] ajp_connection_tcp_get_message::jk_ajp_common.c (1230): (tomcat4) can't receive the response header message from tomcat, network problems or tomcat (127.0.0.1:7029) is down (errno=11)
[Sun Aug 08 11:57:58.360 2010] [16171:3085982592] [error] ajp_get_reply::jk_ajp_common.c (2055): (tomcat4) Tomcat is down or refused connection. No response has been sent to the client (yet)
[Sun Aug 08 11:57:58.360 2010] [16171:3085982592] [info] ajp_service::jk_ajp_common.c (2540): (tomcat4) sending request to tomcat failed (recoverable), (attempt=1)
[Sun Aug 08 11:57:58.850 2010] [16125:3085982592] [info] ajp_connection_tcp_get_message::jk_ajp_common.c (1230): (tomcat4) can't receive the
。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。
[Sun Aug 08 11:58:38.969 2010] [16655:3085982592] [info] ajp_connect_to_endpoint::jk_ajp_common.c (959): Failed opening socket to (127.0.0.1:7029) (errno=115)
[Sun Aug 08 11:58:38.969 2010] [16655:3085982592] [error] ajp_send_request::jk_ajp_common.c (1585): (tomcat4) connecting to backend failed. Tomcat is probably not started or is listening on the wrong port (errno=115)
[Sun Aug 08 11:58:38.969 2010] [16655:3085982592] [info] ajp_service::jk_ajp_common.c (2540): (tomcat4) sending request to tomcat failed (recoverable), because of error during request sending (attempt=1)
[Sun Aug 08 11:58:39.197 2010] [16658:3085982592] [info] jk_open_socket::jk_connect.c (622): connect to 127.0.0.1:7029 failed (errno=115)
=======================================================================================================日志结束
这个问题好像每过几天就会出现一次
问题明显了是tomcat的AJP端口7029出了问题 可能这个端口死掉了,但是怎么死的呢?
我初步估计是不是数据库连接失效造成的,我这里用的是 c3po连接池,因为在发生严重错误前有这个信息
Last packet sent to the server was 1 ms ago.
at com.mysql.jdbc.Connection.createNewIO(Connection.java:2643)
是不是tomcat一直连接不上数据库,所以没有回应客户端,造成AJP端口线程堆积堵死。
由于小弟技术有限,这个问题不能圆满解决,还希望各位帮忙解决下了,我这里先谢谢了。
可能的情况是mysql的性能不行,造成tomcat不行,然后apache连tomcat不行。也可能是tomcat连接apache不行。简单的测试方法是在有人反应网页打开不了时,直接访问tomcat的http端口(不是ajp端口),如果能正常看网页,说明tomcat连apache不行,如果不能说明mysql性能不行.如果是tomcat+apache不行可以在workers.properties里设置相应的负载机器的recovery_options=3就可以了,如果是mysql不行,只能换数据库了,如mssqlserver或oracle之类的。很多大公司用的mysql都是自己改代码的,原版的性能不行,有点压力一天即挂,做过测试了。
注情况一的解释:
recovery_options属性说明了web server在检测到Tomcat失败后如何进行恢复工作。默认情况下,web server将转发请求给处于负载平衡模式中的另一个Tomcat。属性值为0,说明全部恢复;属性值为1,说明如果在Tomcat接到请求后出现失败状况,则不进行恢复;属性值为2,说明如果在Tomcat发送http头给客户端后出现失败状况,则不进行恢复;属性值为3,说明如果在Tomcat接到请求后出现失败状况或者在Tomcat发送http头给客户端后出现失败状况,则不进行恢复。此属性在jk 1.2.6版本被增加进来,以求避免Tomcat的死机和在支持ajp13的servlet引擎上发生的问题。此属性默认为全部恢复。
因在默认的情况下,JK检测tomcat的工作情况,所以浪费了很多资源,这个资源多到比tomcat正常工作所需的资源的1.6倍还多。如果不检测恢复,则效率高了,处理的请求数可以是原来的2.6倍多,而且tomcat还不死--没响应,反而使出错的数量比检测恢复之后出错的数量还少,性能还加强了,如果原来用这种的集群78台机器,有一阵就挂掉,改成这个配置只要30台机器,一般在同样的时间段内运行无反应或出错的情况比recovery_options使用默认值的少。
recovery_options的最新参考
http://tomcat.apache.org/connectors-doc/reference/workers.html
版权声明:本文内容由阿里云实名注册用户自发贡献,版权归原作者所有,阿里云开发者社区不拥有其著作权,亦不承担相应法律责任。具体规则请查看《阿里云开发者社区用户服务协议》和《阿里云开发者社区知识产权保护指引》。如果您发现本社区中有涉嫌抄袭的内容,填写侵权投诉表单进行举报,一经查实,本社区将立刻删除涉嫌侵权内容。