我在Tomcat中部署了一个webapp,我发现它随机关闭 ,时间从2或3小时到2或3天不等。登录catalina.out
是:
26224 2015-06-10 13:59:04.110 {http-nio-8080-exec-3} INFO com.timediff.controller.user.UserProfileController#getUserHome - /user/profile/home done, curUid: 889
26225 10-Jun-2015 14:15:35.050 INFO [Thread-11] org.apache.coyote.AbstractProtocol.pause Pausing ProtocolHandler ["http-nio-8080"]
26226 10-Jun-2015 14:15:35.052 INFO [Thread-11] org.apache.coyote.AbstractProtocol.pause Pausing ProtocolHandler ["ajp-nio-8009"]
26227 10-Jun-2015 14:15:35.053 INFO [Thread-11] org.apache.catalina.core.StandardService.stopInternal Stopping service Catalina
26228 10-Jun-2015 14:15:35.058 INFO [localhost-startStop-2] org.springframework.web.context.support.XmlWebApplicationContext.doClose Closing WebApplicationContext for namespace 'timediff-dispatcher-servlet': startup date [Wed Jun 10 13:38:14 CST 2015]; root of context hierarchy
26229 10-Jun-2015 14:15:35.059 INFO [localhost-startStop-2] org.springframework.context.support.DefaultLifecycleProcessor.stop Stopping beans in phase 2147483647
26230 2015-06-10 14:15:35.061 {localhost-startStop-2} INFO org.quartz.core.QuartzScheduler#standby - Scheduler TimediffScheduler_$_iZu1skaofy1Z1433914696931 paused.
26231 10-Jun-2015 14:15:35.072 INFO [localhost-startStop-2] org.springframework.scheduling.quartz.SchedulerFactoryBean.destroy Shutting down Quartz Scheduler
26232 2015-06-10 14:15:35.072 {localhost-startStop-2} INFO org.quartz.core.QuartzScheduler#shutdown - Scheduler TimediffScheduler_$_iZu1skaofy1Z1433914696931 shutting down.
26233 2015-06-10 14:15:35.075 {localhost-startStop-2} INFO org.quartz.core.QuartzScheduler#standby - Scheduler TimediffScheduler_$_iZu1skaofy1Z1433914696931 paused.
26234 2015-06-10 14:15:35.077 {localhost-startStop-2} INFO org.quartz.core.QuartzScheduler#shutdown - Scheduler TimediffScheduler_$_iZu1skaofy1Z1433914696931 shutdown complete.
26235 10-Jun-2015 14:15:35.082 INFO [localhost-startStop-2] org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor.shutdown Shutting down ExecutorService 'quartzThreadPool'
26236 2015-06-10 14:15:35.103 {localhost-startStop-2} INFO com.timediff.listener.StopMemoryLeakListener#lambda$contextDestroyed$0 - driver: com.mysql.jdbc.Driver@7657b26d is de-registered.
26237 2015-06-10 14:15:35.104 {localhost-startStop-2} INFO com.timediff.listener.StopMemoryLeakListener#contextDestroyed - AbandonedConnectionCleanupThread shutdown.
26238 10-Jun-2015 14:15:35.150 INFO [Thread-11] org.apache.coyote.AbstractProtocol.stop Stopping ProtocolHandler ["http-nio-8080"]
26239 10-Jun-2015 14:15:35.152 INFO [Thread-11] org.apache.coyote.AbstractProtocol.stop Stopping ProtocolHandler ["ajp-nio-8009"]
26240 10-Jun-2015 14:15:35.154 INFO [Thread-11] org.apache.coyote.AbstractProtocol.destroy Destroying ProtocolHandler ["http-nio-8080"]
26241 10-Jun-2015 14:15:35.156 INFO [Thread-11] org.apache.coyote.AbstractProtocol.destroy Destroying ProtocolHandler ["ajp-nio-8009"]
stackoverflow上的,this question和this question与我的情况非常相似,但我仍然绊倒。
现在我将详细介绍我的问题:
2.1 tomcat和jdk版
Tomcat: 8.0.22
JDK: 1.8.0_45
catalina.sh中的2.2 jvm选项:
CATALINA_OPTS="-server -Xms1g -Xmx1g -XX:MaxMetaspaceSize=512m -Xmn512m
-XX:SurvivorRatio=8
-XX:+UseConcMarkSweepGC -XX:+CMSParallelRemarkEnabled
-XX:+UseCMSInitiatingOccupancyOnly
-XX:CMSInitiatingOccupancyFraction=70 -XX:+ScavengeBeforeFullGC
-XX:+CMSScavengeBeforeRemark
-XX:+PrintGCDateStamps -verbose:gc -XX:+PrintGCDetails
-Xloggc:/opt/logs/gc/timediff-gc.log
-XX:+UseGCLogFileRotation -XX:NumberOfGCLogFiles=10 -XX:GCLogFileSize=10M
-Dsun.net.inetaddr.ttl=120 -XX:+HeapDumpOnOutOfMemoryError
-XX:HeapDumpPath=/opt/logs/gc/timediff-oom.hprof
-Djava.rmi.server.hostname=**.**.**.**
-Dcom.sun.management.jmxremote.port=1099
-Dcom.sun.management.jmxremote.authenticate=false
-Dcom.sun.management.jmxremote.ssl=false"
2.3我的webapp中没有与tomcat中止相关的异常日志,我确定我从未调用过System.exit(),并且没有像以下代码块:
try {
} catch(Exception e) {
// do nothing
}
2.4虽然我在gc log中发现分配失败:
2015-06-10T15:36:28.589+0800: 3099.795: [GC (Allocation Failure) 3099.795: [ParNew: 419780K->382K(471872K), 0.0125816 secs] 469721K->50348K(996160K), 0.0126820 secs] [Times: user=0.01 sys=0.00, real=0.01 secs]
2015-06-10T15:37:30.141+0800: 3161.347: [GC (Allocation Failure) 3161.347: [ParNew: 419838K->372K(471872K), 0.0062445 secs] 469804K->50338K(996160K), 0.0063629 secs] [Times: user=0.01 sys=0.00, real=0.01 secs]
2015-06-10T15:38:41.680+0800: 3232.886: [GC (Allocation Failure) 3232.886: [ParNew: 419828K->369K(471872K), 0.0064920 secs] 469794K->50356K(996160K), 0.0066009 secs] [Times: user=0.01 sys=0.00, real=0.01 secs]
2015-06-10T15:39:43.222+0800: 3294.428: [GC (Allocation Failure) 3294.428: [ParNew: 419825K->384K(471872K), 0.0058772 secs] 469812K->50372K(996160K), 0.0059823 secs] [Times: user=0.01 sys=0.00, real=0.01 secs]
2015-06-10T15:40:54.758+0800: 3365.964: [GC (Allocation Failure) 3365.964: [ParNew: 419840K->388K(471872K), 0.0056674 secs] 469828K->50395K(996160K), 0.0069850 secs] [Times: user=0.02 sys=0.00, real=0.00 secs]
我想也许这就是原因,但是TOP和jvisualVM的结果让人不清楚:
web@iZu1skaofy1Z:/usr/local/apache-tomcat-8.0.22/logs$ free -m
total used free shared buffers cached
Mem: 3951 3087 864 0 190 553
-/+ buffers/cache: 2343 1608
Swap: 0 0 0
top - 15:50:05 up 16 days, 5:11, 2 users, load average: 0.33, 0.17, 0.09
Tasks: 128 total, 2 running, 126 sleeping, 0 stopped, 0 zombie
%Cpu(s): 0.8 us, 0.5 sy, 0.0 ni, 98.5 id, 0.0 wa, 0.2 hi, 0.0 si, 0.0 st
KiB Mem: 4046820 total, 3161260 used, 885560 free, 194880 buffers
KiB Swap: 0 total, 0 used, 0 free. 566984 cached Mem
PID USER PR NI VIRT RES SHR S %CPU %MEM TIME+ COMMAND
27307 web 20 0 2068604 865872 22048 S 0.7 21.4 20:20.28 java
16557 web 20 0 3680756 801708 13740 S 0.0 19.8 2:02.99 java
15597 mysql 20 0 1800972 526220 6636 S 0.0 13.0 36:26.08 mysqld
2.4我在同一台服务器上部署了另一台tomcat,但我更改了关机端口和连接器端口,我不认为它们是冲突的。
我已经尽了最大的努力,也许我在分析过程中忘记了一些事情,请提前给我一些提示,谢谢!
更新(2015-07-04):在运行tomcat后从用户web
切换到用户root
后,问题永远不会发生。所以我怀疑tomcat是因为用户权限被系统杀死了,如果你有任何想法,请告诉我,谢谢!
答案 0 :(得分:2)
This answer(来自您找到的一个问题)似乎很好。
有事告诉Tomcat停止。因为当Tomcat作为root
运行时不会发生,我认为原因是其他(非系统)进程(可能是脚本或cron作业)发送信号(可能是SIGTERM
}}到Tomcat,就像kill <tomcat pid>
一样。也许其他进程也以用户web
运行 - 这可以解释为什么该进程无法杀死root
的Tomcat。或者也许其他进程只搜索要杀死的进程,其中一个标准是“web
拥有的进程”。
我建议您仔细阅读用户root
和web
,系统范围的crontab以及/etc/cron.*/
文件夹中的所有内容的crontabs。您还可以检查web
拥有的任何其他进程是否突然终止。并且从源代码构建Tomcat,添加了一些跟踪(正如我在上面提到的答案中所建议的那样),这似乎是一个好主意。
答案 1 :(得分:0)
你的Tomcat是如何开始的?父进程可能正在停止Tomcat,如我在此处所述:Tomcat randomly shuts down with an AbstractProtocol pause after mild usage
答案 2 :(得分:0)
在我的情况下,我更改了startup.sh以使用authbind,然后exec永远不会完成,因为这个,工作定期重新启动。
您是否要删除所有启动行或重新启动,然后自行调用startup.sh或者运行tomcat start。就我而言,我得到了:
Job for tomcat.service failed because a timeout was exceeded. See "systemctl status tomcat.service" and "journalctl -xe" for details.
答案 3 :(得分:0)
在我的情况下,由于在HTML和Webservlet的操作中滥用URL模式而发生了相同的错误 在java中 action =“ ABC” @webserlet =“ / ABC”。 对我来说效果很好