一、下载免安装版Tomcat
打开Tomcat主页,下载Tomcat免安装版,我这里下载的是apache-tomcat-7.0.2.tar.gz。
二、配置Java环境变量
三、解压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
打开火狐浏览器,地址栏输入:8080,回车后看到Tomcat的LOGO,表示一切正常。也可以更改Tomcat目录下的conf文件夹,里面有一个server.xml文件,修改成使用80端口,这样浏览器只要输入就可以直接进入你的主页了。
六、停止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
#LinuxIDC.com
#
# /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