Tomcat8 is configured to start under centos7.5

This article refers to this article

1. Create a new file tomcat under /etc/init.d and add the following content:

#!/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=/usr/local/tomcat #这里修改成实际的位置
export CATALINA_BASE=/usr/local/tomcat #这里修改成实际的位置
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

Note that the location of the relevant environment variables in the script needs to be modified here

2. Add executable permission to the script just now

chmod +x /etc/init.d/tomcat

3.
Mounting Connect the link of the shell file to the /etc/rc2.d/ directory. The numbers in the /etc/rcX.d/ directory of linux represent different run levels at startup, that is, the order of startup. There are six levels from 0 to 5 under Ubuntu 9.10, which cannot be linked to other directories. Some libraries required by Tomcat have not been loaded when the program in that directory is started. Use the ln command to link the tomcat link: sudo ln -s /etc/init.d/tomcat /etc/rc2.d/S16Tomcat. The naming rules in the rcX.d directory are very particular. For different needs, it may start with S or K. The numbers after that represent their startup order. See the Readme files in their respective directories for details.

ln -s /etc/init.d/tomcat /etc/rc2.d/S16Tomcat

4. Start up

chkconfig --add tomcat

At this point, you can use the command to start tomcat

service tomcat start
service tomcat stop
service tomcat restart

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325997878&siteId=291194637