Set up tomcat to start automatically under CentOS/Linux

1. Method 1
1. Modify the /bin/startup.sh file under the Tomcat directory:
 export JAVA_HOME=/usr/local/JDK7
 export CLASSPATH=$CLASSPATH:$JAVA_HOME/lib/tools.jar:$JAVA_HOME/lib/dt.jar:.
 export PATH=$PATH:$JAVA_HOME/bin
 export CATALINA_HOME=/usr/local/tomcat7_1
 /usr/local/tomcat7_1/bin/catalina.sh start
2. Add to /etc/rc.d/rc.local:
 /usr/local/tomcat7_1/bin/startup.sh
2. Method 2
1. Create a new file vi tomcat
2. Add the following command
#!/bin/bash
#
# starguo  [email protected]
# /etc/rc.d/init.d/tomcat
# init script for tomcat precesses
#
# processname: tomcat
# description: tomcat is a j2se server
# chkconfig: 2345 86 16
# description:  Start up the Tomcat servlet engine.
if [ -f /etc/init.d/functions ]; then
        . /etc/init.d/functions
elif [ -f /etc/rc.d/init.d/functions ]; then
        . /etc/rc.d/init.d/functions
else
        echo -e "\atomcat: unable to locate functions lib. Cannot continue."
        exit -1
fi
RETVAL=$?
CATALINA_HOME="/usr/local/tomcat7_1"
case "$1" in
start)
        if [ -f $CATALINA_HOME/bin/startup.sh ];
          then
            echo $"Starting Tomcat"
            $CATALINA_HOME/bin/startup.sh
        fi
        ;;
stop)
        if [ -f $CATALINA_HOME/bin/shutdown.sh ];
          then
            echo $"Stopping Tomcat"
            $CATALINA_HOME/bin/shutdown.sh
        fi
        ;;
*)
        echo $"Usage: $0 {start|stop}"
        exit 1
        ;;
esac
exit $RETVAL
3.chmod 755 tomcat 添加可执行权限
4.cp tomcat /etc/init.d/tomcat
5. chkconfig --add tomcat
6. Add in the bin/catalina.sh file under the tomcat directory
export JAVA_HOME=/usr/local/JDK7
export CATALINA_HOME=/usr/local/tomcat7_1
export CATALINA_BASE=/usr/local/tomcat7_1
export CATALINA_TMPDIR=/usr/local/tomcat7_1/temp
7.service tomcat start/stop

Guess you like

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