1.创建tomcat普通用户
useradd tomcat
2.用tomcat普通用户启动
3.tomcat安装目录在/home/tomcat_abc
4.编写tomcat启动脚本
vi /opt/abc.sh
if [ $# -eq 0 ]
then
echo "Ustage $0 [start|stop] [tomcat_dir:/home/tomcat_abc]"
exit 1
fi
export CATALINA_HOME=$2
export JAVA_OPTS="-server -d64 -Djava.awt.headless=true -Xms2048m -Xmx2048m -Xmn1024m -XX:PermSize=128m -XX:MaxPermSize=512m -XX:+UseConcMarkSweepGC -XX:+UseCMSCompactAtFullCollection -XX:CMSMaxAbortablePrecleanTime=5000 -XX:CMSInitiatingOccupancyFraction=80 -XX:+DisableExplicitGC -XX:+CMSClassUnloadingEnabled -XX:+PrintGCDetails -XX:+PrintGCTimeStamps -Djava.net.preferIPv4Stack=true "
case $1 in
start)
$CATALINA_HOME/bin/startup.sh
;;
stop)
$CATALINA_HOME/bin/shutdown.sh
;;
*)
echo "I do not know where to go..."
;;
esac
5.启动命令
su - tomcat -c "/opt/abc.sh start /home/tomcat_abc"
6.写定时任务检测nginx日志分割和tomcat服务,如果tomcat服务停了自动启动
~]
*/1 * * * * /opt/check_start_nginx.sh >> /opt/check_start_nginx.log 2>&1
~]
tomcat=abc
count=`ps -ef |grep /home/tomcat_${tomcat} | grep -v grep | awk '{print $2}'`
nginx=/home/nginx/sbin/nginx
count1=`ps -ef |grep ${nginx} | grep -v grep| awk '{print $2}'`
echo `date`
if [ -n "${count}" ]
then
echo "${tomcat} runing ....."
else
echo "start ${tomacat} ....."
su - tomcat -c "/opt/${tomcat}.sh start /home/tomcat_${tomcat}"
fi
sleep 30
echo `date`
if [ -n "${count1}" ]
then
echo "${nginx} runing ....."
else
echo "start ${nginx} ....."
${nginx}
fi