如下步驟默認已安裝好tomcat。java
第一步:編寫腳本文件,具體文件格式參照chkconfig
web
說明:chkconfig: [runlevel[runlevel]] [number1] [number2]shell
runlevel : 啓動等級 0-5tomcat
number1 : 啓動順序 (01-99)bash
number2 : 關閉順序 (01-99)ide
#!/bin/bash # chkconfig: 35 99 01 # description: Starts and stops servers of IMIS ( Intergrated Management Infomation System ). \ # used to provide web services. # Author : 87008170@163.com # Version : 1.0 PATH=/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin:~/bin JAVA_HOME=/usr/java/jdk1.6.0_21 JRE_HOME=/usr/java/jdk1.6.0_21 CLASSPATH=$JAVA_HOME/lib:$JAVA_HOME/jre/lib PATH=$JAVA_HOME/bin:$CLASSPATH:$JRE_HOME:$PATH export PATH # source function library . /etc/init.d/functions # SHELL HOME SHELLHOME=/usr/local/tomcat6/bin start(){ $SHELLHOME/startup.sh } stop(){ $SHELLHOME/shutdown.sh } restart(){ stop sleep 5 start } case $1 in start) start ;; stop) stop ;; restart) restart ;; *) echo "Usage: $0 { start | stop | restart }" ;; esac
第二步:設置腳本文件rest
一、進入/etc/init.d目錄,而後創建啓動腳本硬連接 ln -d /usr/local/tomcat6/tomcatd.sh ./tomcatd 二、使用chkconfig命令添加tomcatd服務 chkconfig --add tomcatd 三、檢驗tomcatd服務是否添加成功 chkconfig --list | grep tomcatd tomcatd 0:off 1:off 2:off 3:on 4:off 5:on 6:off
第三步:啓動服務code
service tomcatd start
到這裏設置完成,啓動服務正常即完成。server