Linux操作系统下Tomcat自启动的设置技巧

来源:微学计算机考试频道发布时间:2008-08-28
安装了Tomcat,很简单,将下载下来的安装文件包解压,放入相应的目录中,然后在Linux环境中设置相应的如:JAVA_HOME、CATALINA_HOME等环境变量后,在Tomcat的bin目录下执行./catalina.sh run就能在终端方式上启动tomcat的服务。如果需要将tomcat加入自启动队列中,则需要进行如下的操作:

以root用户登录系统:

cd /etc/rc.d/init.d/

vi tomcat

文件内容参考如下:

  #!/bin/sh 

  # 

  # tomcat: Start/Stop/Restart tomcat 

  # 

  # chkconfig: 2345 80 20 

  # description: Tomcat is a Java Servlet Container 

  # 

  # 

  # match these values to your environment: 

  export CATALINA_BASE=/usr/local/tomcat 

  export CATALINA_HOME=/usr/local/tomcat 

  export CATALINA_TMPDIR=/usr/local/tomcat/temp 

  export JRE_HOME=/usr/java/jdk15 

  # Source function library. 

  . /etc/rc.d/init.d/functions 

  TOMCAT=/usr/local/tomcat 

  start() { 

  echo -n ___FCKpd___0quot;Starting Tomcat: " 

  $TOMCAT/bin/catalina.sh start 

  } 

  stop() { 

  echo -n ___FCKpd___0quot;Stopping Tomcat: " 

  $TOMCAT/bin/catalina.sh stop 

  } 

  # See how we were called. 

  case "$1" in 

  start) 

  start 

  ;; 

  stop) 

  stop 

  ;; 

  status) 

  ;; 

  status) 

  ;; 

  restart) 

  stop 

  start 

  ;; 

  *) 

  echo ___FCKpd___0quot;Usage: $0 {start stop restart}" 

  ;; 

  esac 

  exit $RETVAL

把 tomcat 修改为可运行的文件,命令参考如下:

chmod a+x tomcat

使用chkconfig命令把 tomcat 命令加入到系统启动队列中:

chkconfig --add tomcat

查看apachectl的状态:

chkconfig --list tomcat

好了,全部完成!