一、前言
关于tomcat在centos的linux操作环境下, 通过设置/etc/rc.d/rc.local和/etc/init.d/tomcat两种不同方式进行开机启动服务配置。
二、配置步骤
1. 方式一 : 通过/etc/rc.d/rc.local配置,具体步骤如下,重启系统
[root@centos6 tomcat7]# cd /home/app/tomcat7/bin@b@[root@centos6 bin]# vi auto_startup.sh@b@[root@centos6 bin]# vi auto_startup.sh @b@@b@export JAVA_HOME=/home/app/jdk7@b@export CLASSPATH=.:$JAVA_HOME/lib/dt.jar:$JAVA_HOME/lib/tools.jar:$JRE_HOME/lib@b@export PATH=$PATH:$JAVA_HOME/bin:$JRE_HOME/bin:$CATALINA_HOME/bin@b@export CATALINA_HOME=/home/app/tomcat7@b@@b@/home/app/tomcat7/bin/catalina.sh start@b@@b@[root@centos6 bin]# vi /etc/rc.d/rc.local @b@#!/bin/sh@b@#@b@# This script will be executed *after* all the other init scripts.@b@# You can put your own initialization stuff in here if you don't@b@# want to do the full Sys V style init stuff.@b@@b@touch /var/lock/subsys/local@b@ @b@/home/app/tomcat7/bin/auto_startup.sh@b@@b@[root@centos6 bin]# chmod 755 /home/app/tomcat7/bin/auto_startup.sh
2. 方式二:通过/etc/init.d/tomcat配置,具体步骤如下
[root@centos6 bin]# vim /etc/init.d/tomcat @b@@b@#!/bin/bash@b@#@b@# kenny kenny.zhou@tom.com@b@# /etc/rc.d/init.d/tomcat@b@# init script for tomcat precesses@b@#@b@# processname: tomcat@b@# description: tomcat is a j2se server@b@# chkconfig: 2345 86 16@b@# description: Start up the Tomcat servlet engine.@b@@b@if [ -f /etc/init.d/functions ]; then@b@. /etc/init.d/functions@b@elif [ -f /etc/rc.d/init.d/functions ]; then@b@. /etc/rc.d/init.d/functions@b@else@b@echo -e "/atomcat: unable to locate functions lib. Cannot continue."@b@exit -1@b@fi@b@@b@RETVAL=$?@b@CATALINA_HOME="/home/app/tomcat7"@b@@b@case "$1" in@b@start)@b@if [ -f $CATALINA_HOME/bin/startup.sh ];@b@then@b@echo $"Starting Tomcat"@b@$CATALINA_HOME/bin/startup.sh@b@fi@b@;;@b@stop)@b@if [ -f $CATALINA_HOME/bin/shutdown.sh ];@b@then@b@echo $"Stopping Tomcat"@b@$CATALINA_HOME/bin/shutdown.sh@b@fi@b@;;@b@*)@b@echo $"Usage: $0 {start|stop}"@b@exit 1@b@;;@b@esac@b@@b@exit $RETVAL @b@@b@[root@centos6 bin]# chmod 755 /etc/init.d/tomcat@b@[root@centos6 bin]# chkconfig --add tomcat@b@[root@centos6 bin]# chkconfig tomcat on@b@[root@centos6 bin]# service tomcat start@b@Starting Tomcat@b@Using CATALINA_BASE: /home/app/tomcat7@b@Using CATALINA_HOME: /home/app/tomcat7@b@Using CATALINA_TMPDIR: /home/app/tomcat7/temp@b@Using JRE_HOME: /usr@b@Using CLASSPATH: /home/app/tomcat7/bin/bootstrap.jar:/home/app/tomcat7/bin/tomcat-juli.jar@b@Tomcat started.@b@[root@centos6 bin]# ps -ef|grep tomcat@b@root 7969 1 23 23:13 pts/0 00:00:02 /usr/bin/java -Djava.util.logging.config.file=/home/app/tomcat7/conf/logging.properties -Djava.util.logging.manager=org.apache.juli.ClassLoaderLogManager -Djava.endorsed.dirs=/home/app/tomcat7/endorsed -classpath /home/app/tomcat7/bin/bootstrap.jar:/home/app/tomcat7/bin/tomcat-juli.jar -Dcatalina.base=/home/app/tomcat7 -Dcatalina.home=/home/app/tomcat7 -Djava.io.tmpdir=/home/app/tomcat7/temp org.apache.catalina.startup.Bootstrap start@b@root 7997 3509 0 23:13 pts/0 00:00:00 grep tomcat