linux下完全停止tomcat的方法
使用shutdown.sh并不能完全停止tomcat,因为如果有用户在停止的时候还在访问网页,就会把端口锁住,解决方法就是通过命令 lsof -i :8080|grep -v "PID"|awk '{print "kill -9",$2}' (8080为tomcat端口)把含有tomcat端口的进程都kill了。以下是脚本文件
bear 写道
#!/bin/sh
CATALINA_BASE=/usr/local/tomcat
CATALINA_HOME=/usr/local/tomcat
CATALINA_PORT=8080
CATALINA_TMPDIR=/usr/local/tomcat/temp
CATALINA_OPTS="-Djava.awt.headless=true"
JAVA_HOME=/usr/local/jdk1.5.0_12
PATH=$PATH:$JAVA_HOME/common/lib:$CATALINA_HOME/jre/lib/ext
export CATALINA_BASE CATALINA_HOME CATALINA_TMPDIR CATALINA_OPTS JAVA_HOME PATH
start() {
echo "tomcat starting..."
$CATALINA_HOME/bin/startup.sh
}
stop() {
echo "tomcat stopping..."
$CATALINA_HOME/bin/shutdown.sh
echo "sleep 3 seconds waiting for tomcat shutdown..."
sleep 3
echo "killing all tomcat port..."
lsof -i :$CATALINA_PORT|grep -v "PID"|awk '{print "kill -9",$2}'
}
restart() {
echo "tomcat restarting..."
stop()
sleep 2
start()
}
case $1 in
start) start();;
stop) stop();;
restart) restart();;
*);;
esac
CATALINA_BASE=/usr/local/tomcat
CATALINA_HOME=/usr/local/tomcat
CATALINA_PORT=8080
CATALINA_TMPDIR=/usr/local/tomcat/temp
CATALINA_OPTS="-Djava.awt.headless=true"
JAVA_HOME=/usr/local/jdk1.5.0_12
PATH=$PATH:$JAVA_HOME/common/lib:$CATALINA_HOME/jre/lib/ext
export CATALINA_BASE CATALINA_HOME CATALINA_TMPDIR CATALINA_OPTS JAVA_HOME PATH
start() {
echo "tomcat starting..."
$CATALINA_HOME/bin/startup.sh
}
stop() {
echo "tomcat stopping..."
$CATALINA_HOME/bin/shutdown.sh
echo "sleep 3 seconds waiting for tomcat shutdown..."
sleep 3
echo "killing all tomcat port..."
lsof -i :$CATALINA_PORT|grep -v "PID"|awk '{print "kill -9",$2}'
}
restart() {
echo "tomcat restarting..."
stop()
sleep 2
start()
}
case $1 in
start) start();;
stop) stop();;
restart) restart();;
*);;
esac
在tomcat中运行的项目配置了log4j,但是日志文件却无法生成
原因是在TOMCAT_HOME/common/classes中有log4j的配置文件,接管了所有项目log4j输出的信息,自定义的日志文件就无法生成,把TOMCAT_HOME/common/classes中的log4j.xml或者log4j.properties删除即可。
出现java.lang.OutOfMemoryError: PermGen space错误
原因是JVM默认的class加载内存只有4M,当项目中使用proxool等使用cglib的框架或项目的文件太多,重新加载项目时就会出现这种错误,解决方法是加大JVM的内存
修改TOMCAT_HOME/bin/catalina.sh
在echo “Using CATALINA_BASE: $CATALINA_BASE”上面加入以下行:
JAVA_OPTS="-server -XX:PermSize=64M -XX:MaxPermSize=128m"
详细说明:http://www.5e8.org/archives/71