1、進入/etc/init.d
2、新建檔案tomcat,內容如下:
#!/bin/sh # chkconfig: 345 99 10 # description: Auto-starts tomcat # /etc/init.d/tomcat # Tomcat auto-start # Source function library. #. /etc/init.d/functions # source networking configuration. #. /etc/sysconfig/network RETVAL=0 export JRE_HOME=/usr/lib/jvm/jre export CATALINA_HOME=/usr/local/tomcat/apache-tomcat-7.0.64 export CATALINA_BASE=/usr/local/tomcat/apache-tomcat-7.0.64 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 tomcat | grep apache-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、新增執行許可權
sudo chmod +x /etc/init.d/tomcat
4、隨系統啟動
chkconfig --add tomcat
檢視,在服務列表裡就會出現自定義的服務了。
chkconfig --list
5、開啟tomcat系統服務
chkconfig tomcat on
6 啟動
tomcat:service tomcat start
7 停止
tomcat: service tomcat stop
其他:
java -version:檢視JDK版本
linux:
whereis java
which java (java執行路徑)
echo $JAVA_HOME
echo $PATH
參考
http://www.cnblogs.com/AloneSword/p/3417812.html
http://blog.csdn.net/jason5186/article/details/7317253