Linux starts a single tomcat as a service

1. Download tomcat
apache-tomcat-8.0.26.tar.gz
 
2. Upload to the remote server
scp Downloads/apache-tomcat-8.0.26.tar.gz [email protected]:/home/wumart
 
3. Move tomcat to the /usr/local directory:
[wumart@dmallsol10007 local]$ sudo mv  ~/apache-tomcat-8.0.26  /usr/local/tomcat
 
4. Unzip tomcat
tar -xzvf apache-tomcat-8.0.26.tar.gz 
Location of tomcat: /usr/local/
 
5. Create the tomcat file under /etc/init.d
$sudo touch tomcat
Write the content in the tomcat file:
#!/bin/bash
# chkconfig: 2345 10 90
# description: Starts and Stops the Tomcat daemon.
TOMCAT_HOME=/usr/local/tomcat                                #tomcat目录
TOMCAT_START=$TOMCAT_HOME/bin/startup.sh
TOMCAT_STOP=$TOMCAT_HOME/bin/shutdown.sh
# necessary environment variables export
CATALINA_HOME=$TOMCAT_HOME
export JAVA_HOME=/usr/local/java/jdk1.7.0_80                #JDK目录
# source function library.
. /etc/rc.d/init.d/functions
# check that networking is up.
[ "${NETWORKING}" = "no" ] && exit 0
# check for tomcat script
if [ ! -f $TOMCAT_HOME/bin/catalina.sh ]; then
        echo "Tomcat not valilable..."
        exit
be
start(){
        echo -n "Starting Tomcat: "
        daemon $TOMCAT_START
        echo
        touch /var/lock/subsys/tomcat
}
stop(){
        echo -n $"Shutting down Tomcat: "
        daemon $TOMCAT_STOP
        rm -f /var/lock/subsys/tomcat.pid echo
}
restart(){
        stop
        start
}
status(){
        ps ax --width=1000 | grep "[o]rg.apache.catalina.startup.Bootstrap start" | awk '{printf $1 " "}' \
| wc | awk '{print $2}' > /tmp/tomcat_process_count.txt
        read line < /tmp/tomcat_process_count.txt
        if [ $line -gt 0 ]; then
                echo -n "tomcat ( pid "
                ps ax --width=1000 | grep "org.apache.catalina.startup.Bootstrap start" | awk '{printf $1 " "}'
                echo -n ") is running..."
                echo
        else
                echo "Tomcat is stopped"
        be
}
case "$1" in
        start)
                start ;;
        stop)
                stop ;;
        restart)
                stop
                sleep 3
                start ;;
        status)
                status ;;
        *)
                echo "Usage: tomcatd {start|stop|restart|status}"
                exit 1
esac
exit 0
  
6. Set the access permissions of the tomcat file
[wumart@dmallsol10007 init.d]$ sudo chmod a+x tomcat
 
7.  用 chkconfig 设置以服务方式运行 tomcat:
[wumart@dmallsol10007 init.d]$ sudo chkconfig --add tomcat
 
用 chkconfig --list 查看,在服务列表里是否出现自定义的服务。
[wumart@dmallsol10007 init.d]$ chkconfig --list
tomcat         0:关闭 1:关闭 2:启用 3:启用 4:启用 5:启用 6:关闭
 
8.  使用 service tomcat start 启动 tomcat 服务
[wumart@dmallsol10007 init.d]$ service tomcat start
Starting tomcat
Using CATALINA_BASE:   /usr/local/tomcat
Using CATALINA_HOME:   /usr/local/tomcat
Using CATALINA_TMPDIR: /usr/local/tomcat/temp
Using JRE_HOME:        /usr/local/java/jdk1.7.0_80
Using CLASSPATH:       /usr/local/tomcat/bin/bootstrap.jar:/usr/local/tomcat/bin/tomcat-juli.jar
Tomcat started.
touch: cannot touch `/var/lock/subsys/tomcat': Permission denied

Guess you like

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