前言:測试过程中,须要在Linux环境下配置免安装版本号的Tomcat。以下列出具体步骤,希望对大家有帮助。
一、下载免安装版Tomcat
打开Tomcat主页http://tomcat.apache.org/。下载Tomcat免安装版。我这里下载的是apache-tomcat-7.0.2.tar.gz。
二、配置Java环境变量
Java的环境变量有了概述,具体见:http://www.fengwenxuan.com/index.php/red-hat-enterprise-linux/238.html
三、解压Tomcat
将Tomcat解压缩到/usr/local文件夹下
# tar zxvf apache-tomcat-7.0.2.tar.gz
四、启动Tomcat
# cd /usr/local/apache-tomcat-7.0.2/bin
# ./startup.sh
假设启动成功,shell终端会出现例如以下提示:
Using CATALINA_BASE: /usr/local/apache-tomcat-7.0.2
Using CATALINA_HOME: /usr/local/apache-tomcat-7.0.2
Using CATALINA_TMPDIR: /usr/local/apache-tomcat-7.0.2/temp
Using JRE_HOME: /usr/local/jdk1.6.0_21
假设终端报错,基本上能够肯定是Jdk环境变量没有配置好,细致在检查一下Jdk环境变量的配置
五、測试Tomcat
打开火狐浏览器,地址栏输入http://localhost:8080,回车后看到Tomcat的LOGO,表示一切正常。也能够更改Tomcat文件夹下的conf文件夹。里面有一个server.xml文件。改动成使用80port。这样浏览器仅仅要输入http://localhost/就能够直接进入你的主页了。
六、停止Tomcat
# cd /usr/local/apache-tomcat-7.0.2/bin
# ./shutdown.sh
七、设置开机自己主动启动Tomcat
方法一:
在/usr/local/apache-tomcat-7.0.2/bin/startup.sh 为:
JAVA_HOME=/home/fwx/jdk1.6.0_14
CLASSPATH=.:$JAVA_HOME/lib/tools.jar
PATH=$JAVA_HOME/bin:$PATH
export JAVA_HOME CLASSPATH PATH
export CATALINA_HOME=/usr/local/apache-tomcat-7.0.2
/usr/local/tomcat/bin/catalina.sh start
在/etc/rc.d/rc.local中增加:
/usr/local/apache-tomcat-7.0.2/bin/startup.sh
方法二:
1、把以下的代码保存为tomcat文件,并让它成为可运行文件 chmod 755 tomcat.
#!/bin/bash
#
# [email protected]
# /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="/usr/local/apache-tomcat-7.0.2"
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
2、将tomcat文件复制到/etc/init.d/下,并执行:chkconfig –add tomcat
3、在apache-tomcat-7.0.2/bin/catalina.sh文件里增加下面语句:
export JAVA_HOME=/home/fwx/jdk1.6.0_14
export CATALINA_HOME=/usr/local/apache-tomcat-7.0.2
export CATALINA_BASE=/usr/local/apache-tomcat-7.0.2
export CATALINA_TMPDIR=/usr/local/apache-tomcat-7.0.2/temp
启动tomcat: service tomcat start
停止tomcat: service tomcat stop
谢谢关注破晓博客