Linux 环境下tomcat 开机启动设置
程序员文章站
2022-05-09 08:09:11
...
1,安装jdk
安装方式有三种:
1.1 在线安装
yum install jdk1.7
1.2 下载rpm软件安装
rpm -ivh jdk-7u4-linux-i586.rpm
1.3 解压缩安装
下载解压缩版本的jdk
2,解压缩tomcat
tar zxvf /soft/apache-tomcat-7.0.55.tar.gz
3,vim /etc/profile
# jdk config
JAVA_HOME=/soft/jdk1.7.0_79/
JRE_HOME=/soft/jdk1.7.0_79/jre/
PATH=$JAVA_HOME/bin:$JRE_HOME/bin:$PATH
CLASSPATH=.:$JAVA_HOME/lib/dt.jar:$JAVA_HOME/lib/tools.jar
export JAVA_HOME
export JRE_HOME
export PATH
export CLASSPATH
#tomcat config
export TOMCAT_HOME=/soft/apache-tomcat-7.0.63
export CATALINA_HOME=/soft/apache-tomcat-7.0.63
#path config
export PATH=$PATH:$TOMCAT_HOME/bin
4,tomcat 授权可执行权限
chmod +x /soft/apache-tomcat-7.0.63/bin/*.sh
5,设置开机启动脚本
执行指令vi /etc/rc.d/init.d/tomcat生成脚本文件,内容如下
#!/bin/bash
#
# /etc/rc.d/init.d/tomcat
# init script for tomcat precesses
#
# processname: tomcat
# description: tomcat is a j2se server
# chkconfig: 2345 86 16
# description: Start up the Tomcat servlet engine.
if [ -f /etc/init.d/functions ]; then
. /etc/init.d/functions
elif [ -f /etc/rc.d/init.d/functions ]; then
. /etc/rc.d/init.d/functions
else
echo -e "\atomcat: unable to locate functions lib. Cannot continue."
exit -1
fi
RETVAL=$?
CATALINA_HOME="/soft/apache-tomcat-7.0.63" #tomcat安装目录
case "$1" in
start)
if [ -f $CATALINA_HOME/bin/startup.sh ];
then
echo $"Starting Tomcat"
$CATALINA_HOME/bin/startup.sh
fi
;;
stop)
if [ -f $CATALINA_HOME/bin/shutdown.sh ];
then
echo $"Stopping Tomcat"
$CATALINA_HOME/bin/shutdown.sh
fi
;;
*)
echo $"Usage: $0 {start|stop}"
exit 1
;;
esac
exit $RETVAL
6、添加权限chmod 755 /etc/rc.d/init.d/tomcat,使得脚本文件可执行
7、运行:chkconfig --add /etc/rc.d/init.d/tomcat #将其加到服务中
8、在vim /usr/local/tomcat7/bin/catalina.sh文件中加入以下语句:
#auto startup tomcat config
export JAVA_HOME=/soft/jdk1.7.0_79/
export CATALINA_HOME=/soft/apache-tomcat-7.0.63
export CATALINA_BASE=/soft/apache-tomcat-7.0.63
export CATALINA_TMPDIR=/soft/apache-tomcat-7.0.63/temp
启动tomcat服务: service tomcat start
停止tomcat服务: service tomcat stop