CentOS配置Tomcat开机启动
通常我们进行服务器维护的时候需要注意点为,服务器上的容器一般都是开机启动,减少停机后应用还需要一个一个启动的麻烦。
1) 新建tomcat文件
touch /etc/rc.d/init.d/tomcat
2) 编辑文件,将下面代码复制到tomcat文件中,不过需要自己修改对应的JDK路径和Tomcat的CATALINA_HOME的路径
#!/bin/sh # chkconfig: 345 99 10 # description: Auto-starts tomcat # /etc/init.d/tomcatd # Tomcat auto-start # Source function library. #. /etc/init.d/functions # source networking configuration. #. /etc/sysconfig/network RETVAL=0 # export JAVA_HOME=/usr/java/jdk1.7.0_60 # export JRE_HOME=/usr/java/jdk1.7.0_60/jre export CATALINA_HOME=/apps/apache-tomcat-8.0.32 export CATALINA_BASE=/apps/apache-tomcat-8.0.32 start() { if [ -f $CATALINA_HOME/bin/startup.sh ]; then echo $"Starting Tomcat" $CATALINA_HOME/bin/startup.sh RETVAL=$? echo " OK" return $RETVAL fi } stop() { if [ -f $CATALINA_HOME/bin/shutdown.sh ]; then echo $"Stopping Tomcat" $CATALINA_HOME/bin/shutdown.sh RETVAL=$? sleep 1 ps -fwwu root | grep tomcat|grep -v grep | grep -v PID | awk '{print $2}'|xargs kill -9 echo " OK" # [ $RETVAL -eq 0 ] && rm -f /var/lock/... return $RETVAL fi } case "$1" in start) start ;; stop) stop ;; restart) echo $"Restaring Tomcat" $0 stop sleep 1 $0 start ;; *) echo $"Usage: $0 {start|stop|restart}" exit 1 ;; esac exit $RETVAL
3) 设置tomcat脚本权限
chmod 755 /etc/rc.d/init.d/tomcat
4) 设置脚本开机启动
chkconfig --add tomcat
5) 完成配置,重启服务
reboot
6) 验证是否启动
ps -aux | grep tomcat 或 ps -ef | grep tomcat