您的位置:首页 > 运维架构 > Tomcat

临时处理tomcat僵死问题

2014-10-22 11:23 225 查看
现场的同事遇到一个Tomcat僵死的问题,隔三差五的服务器就会挂掉,向我寻求解决方案,服务器正常,没有发现问题。可能是应用程序本身的问题导致,先取一个临时的办法,先服务器跑起来,然后慢慢找原因:
1、 编写一个重启tomcat的shell脚本,脚本内容如下:restart.sh
vi restart.sh注意“.”和 /etc/profile 之间有空格(. /etc/profile 注意, "."和"/etc/profile" 之间有空格.)
#!/bin/sh
. /etc/profile
pid=`ps aux | grep tomcat | grep -vgrep | grep -v retomcat | awk '{print $2}'`
echo $pid
if [ -n "$pid" ]
then
{
echo -------shutdown---------
/opt/wstk/tomcat6/bin/shutdown.sh
sleep 1
pid=`ps aux | grep tomcat | grep -v grep | grep -v retomcat | awk'{print $2}'`
if [ -n "$pid" ]
then
{
sleep 1
echo -------kill tomcat--------
kill -9 $pid
}
fi
sleep 1
echo --------startup.sh----------
/opt/wstk/tomcat6/bin/startup.sh
}
else
echo --------startup.sh---------
/opt/wstk/tomcat6/bin/startup.sh

fi
2、 给脚本赋予权限
#chmod u+x restart.sh或者chmod 777 restart.sh
3、 编写定时任务脚本
#crontab -e添加如下脚本内容:30 04 * * * /home/retwo/restart.sh >>/home/retwo/logs/restart.log 2>&1



4、重启定时任务脚本
(1)查看定时任务状态
service crond status
(2)停止定时任务
service crond stop
(3)启动定时任务
service crond start
(4)或者使用service crond restart命令



这只是临时的解决办法,要从根本解决问,还要认真分析出现问题的原因。找出问题根源,开着水龙头拖地,永远是拖不干净的。
本文出自 “zsls” 博客,请务必保留此出处http://qqianwan.blog.51cto.com/8015812/1566627
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: