The first way
1. Modify the script file rc.local:vim/etc/rc.d/rc.local
This script is a user-defined start-up program that can add scripts or scripts that you want to execute after the system starts.
2. Add the following:
Export java_home=/usr/local/jdk1.8.0_171
/usr/local/apache-tomcat-7.0.88/bin/startup.sh start
3.esc exit Edit,: Wq Save changes
4. Change the rc.local to executable
chmod 777/etc/rc.d/rc.local
The second way:
- Vi/etc/init.d/tomcat
#!/bin/sh 345 # 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/local/jdk1.8.0_171
export jre_home=/usr/local/jdk1.8.0_171/JRE
Export Catalina_home=/usr/local/apache-tomcat-7.0.88Export Catalina_base=/usr/local/apache-tomcat-7.0.88start () {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=$?Sleep1PS-FWWU Root | grep tomcat|grep-v grep | Grep-v PID | awk ' {print $} ' |xargs kill-9Echo"OK"# [$RETVAL-eq 0] && rm-f/var/lock/... return$RETVAL fi} Case"$"In start) start; stop) stop;; Restart) echo $"Restaring Tomcat" $0Stop Sleep1 $0start;; *) echo $"Usage: $ {Start|stop|restart}"Exit1 ;; ESAC Exit $RETVAL
Set permissions:
chmod 755/etc/init.d/tomcat
Set Boot start service
- sudo chkconfig tomcat on
Start, stop Tomcat
- Service Tomcat start #或者/etc/init.d/tomcat start
- Service Tomcat stop #或者/etc/init.d/tomcat stop
Linux self-booting tomcat