前言:
在設定好Tomcat後,大多數人都會希望開機後自動啟動。但是如果把啟動路徑加到/etc/rc.d/rc.local是不會生效的。因此必須在做一些設定。其實設定的方式有很多種,在這邊介紹設定為Service的方式。然後在設定開機啟動這樣就可以了。
設定Tomcat開機啟動
1. 設定啟動腳本
以下加入的內容,黃色字體的部份請依個人tomcat安裝路徑設定。
[root@localhost ~]# cd /etc/init.d [root@localhost ~]# vim tomcat #加入以下內容 tartup script for jakarta tomcat # # chkconfig: – 85 20 # description: Tomcat running # processname: tomcat6 # pidfile: /var/run/tomcat.pid # config:# Source function library. . /etc/rc.d/init.d/functions # Source networking configuration. . /etc/sysconfig/network # Check that networking is up. [ ${NETWORKING} = "no" ] && exit 0# Set Tomcat environment. export JAVA_HOME=/usr/java/jdk export CATALINA_HOME=/opt/apache-tomcat-6.0.33 export CATALINA_OPTS=”-Dbuild.compiler.emacs=true” export CLASSPATH=.:$JAVA_HOME/lib/dt.jar:$JAVA_HOME/lib/tools.jar:$CATALINA_HOME/lib/servlet-api.jar export PATH=$JAVA_HOME/bin:$PATH [ -f /opt/apache-tomcat-6.0.33/bin/startup.sh ] || exit 0 [ -f /opt/apache-tomcat-6.0.33/bin/shutdown.sh ] || exit 0 export PATH=$PATH:/usr/bin:/usr/lib/bin # See how we were called. case “$1″ in start) # Start daemon. echo -n “Starting Tomcat: “ /opt/apache-tomcat-6.0.33/bin/startup.sh RETVAL=$? echo [ $RETVAL = 0 ] && touch /var/lock/subsys/tomcat ;; stop) # Stop daemons. echo -n “Shutting down Tomcat: “ /opt/apache-tomcat-6.0.33/bin/shutdown.sh RETVAL=$? echo [ $RETVAL = 0 ] && rm -f /var/lock/subsys/tomcat ;; restart) $0 stop $0 start ;; condrestart) [ -e /var/lock/subsys/tomcat ] && $0 restart ;; status) status tomcat ;; *) echo “Usage: $0 {start|stop|restart|status}” exit 1 esac exit 0 |
2. 修改執行權限
[root@localhost ~]# chmod 755 tomcat |
3. 添加tomcat啟動服務
[root@localhost ~]# chkconfig –add tomcat |
4. 設定開機自動啟動
[root@localhost ~]# chkconfig tomcat on |
5. 服務開啟關閉方式
[root@localhost ~]# service tomcat start #啟動服務
[root@localhost ~]# /etc/init.d/tomcat start #啟動服務 [root@localhost ~]# service tomcat stop #停止服務 [root@localhost ~]#/etc/init.d/tomcat stop #停止服務 |
設定好後可以重開機試試看。
評論
此文章尚無評論。