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目录下
#tarzxvfapache-tomcat-7.0.2.tar.gz
四、启动Tomcat
#cd/usr/local/apache-tomcat-7.0.2/bin
#./startup.sh
如果启动成功,shell终端会出现如下提示:
UsingCATALINA_BASE:/usr/local/apache-tomcat-7.0.2
UsingCATALINA_HOME:/usr/local/apache-tomcat-7.0.2
UsingCATALINA_TMPDIR:/usr/local/apache-tomcat-7.0.2/temp
UsingJRE_HOME:/usr/local/jdk1.6.0_21
如果终端报错,基本上可以肯定是Jdk环境变量没有配置好,仔细在检查一下Jdk环境变量的配置
五、测试Tomcat
打开火狐浏览器,地址栏输入http://localhost:8080,回车后看到Tomcat的LOGO,表示一切正常。也可以更改Tomcat目录下的conf文件夹,里面有一个server.xml文件,修改成使用80端口,这样浏览器只要输入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
exportJAVA_HOMECLASSPATHPATH
exportCATALINA_HOME=/usr/local/apache-tomcat-7.0.2
/usr/local/tomcat/bin/catalina.shstart
在/etc/rc.d/rc.local中加入:
/usr/local/apache-tomcat-7.0.2/bin/startup.sh
方法二:
1、把下面的代码保存为tomcat文件,并让它成为可执行文件chmod755tomcat.
#!/bin/bash
#
#/etc/rc.d/init.d/tomcat
#initscriptfortomcatprecesses
#
#processname:tomcat
#description:tomcatisaj2seserver
#chkconfig:23458616
#description:StartuptheTomcatservletengine.
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:unabletolocatefunctionslib.Cannotcontinue."
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$"StartingTomcat"
$CATALINA_HOME/bin/startup.sh
fi
;;
stop)
if[-f$CATALINA_HOME/bin/shutdown.sh];
then
echo$"StoppingTomcat"
$CATALINA_HOME/bin/shutdown.sh
fi
;;
*)
echo$"Usage:$0{start|stop}"
exit1
;;
esac
exit$RETVAL
2、将tomcat文件拷贝到/etc/init.d/下,并运行:chkconfig--addtomcat
3、在apache-tomcat-7.0.2/bin/catalina.sh文件中加入以下语句:
exportJAVA_HOME=/home/fwx/jdk1.6.0_14
exportCATALINA_HOME=/usr/local/apache-tomcat-7.0.2
exportCATALINA_BASE=/usr/local/apache-tomcat-7.0.2
exportCATALINA_TMPDIR=/usr/local/apache-tomcat-7.0.2/temp
启动tomcat:servicetomcatstart
停止tomcat:servicetomcatstop