Tomcat的安装分为两个步骤:安装JDK和安装Tomcat.
一、安装JDK:
cd /usr/local/src/
wget http://download.oracle.com/otn/java/jdk/7u80-b15/jdk-7u80-linux-x64.tar.gz
tar –zvxf jdk-7u80-linux-x64.tar.gz
mv jdk1.67.0_80 /usr/local/
设置环境变量
vim /etc/profile
JAVA_HOME=/usr/local/jdk1.7.0_80/
JAVA_BIN=/usr/local/jdk1.7.0_80/bin
JRE_HOME=/usr/local/jdk1.7.0_80/jre
PATH=$PATH:/usr/local/jdk1.7.0_80/bin:/usr/local/jdk1.7.0_80/jre/bin CLASSPATH=/usr/local/jdk1.7.0_80/jre/lib:/usr/local/jdk1.7.0_80/lib:/usr/local/jdk1.7.0_80/jre/lib/charsets.jar
保存文件后,使其生效:
source /etc/profile
检测是否设置正确:
java -version
二、安装Tomcat
cd /usr/local/src/
wget http://mirrors.cnnic.cn/apache/tomcat/tomcat-8/v8.0.30/bin/apache-tomcat-8.0.30.tar.gz
tar zxvf apache-tomcat-8.0.30.tar.gz
mv apache-tomcat-8.0.30 /usr/local/tomcat
cp -p /usr/local/tomcat/bin/catalina.sh/etc/init.d/tomcat
vim /etc/init.d/tomcat
在第二行加入以下内容:
#chkconfig: 112 63 37
#description: tomcat server init script
#Source Function Library
./etc/init.d/functions
JAVA_HOME=/usr/local/jdk1.7.0_80/
CATALINA_HOME=/usr/local/tomcat
保存文件后,执行以下操作:
chmod 755 /etc/init.d/tomcat
chkconfig --add tomcat
chkconfig tomcat on
启动tomcat:
service tomcat start
三、配置tomcat
1、tomcat默认启动的是8080,如果你想修改为80,则需要修改server.xml文件:
vim /usr/local/tomcat/conf/server.xml
找到:
<Connectorport="8080" protocol="HTTP/1.1"
修改为:
<Connectorport="80" protocol="HTTP/1.1"
2、配置新的虚拟主机
cd /usr/local/tomcat/conf/
vim server.xml
找到</Host>下一行插入新的<Host>内容如下:
<Hostname="www.123.cn" appBase="/data/tomcatweb"
unpackWARs="false"autoDeploy="true"
xmlValidation="false"xmlNamespaceAware="false">
<Context path=""docBase="./" debug="0" reloadable="true"crossContext="true"/>
</Host>
保存后,重启tomcat:
service tomcat stop
service tomcat start
四、测试
vim /data/tomcatweb/111.jsp
<html><body><center>
Now time is: <%=new java.util.Date()%>
</center></body></html>
保存后,使用curl测试:
curl -xlocalhost:80 www.123.cn/111.jsp
看看运行结果是否是:
<html><body><center>
Now time is: Thu Jun 13 15:26:03 CST 2013
</center></body></html>
本文出自 “Linux” 博客,请务必保留此出处http://syklinux.blog.51cto.com/9631548/1737313
原文地址:http://syklinux.blog.51cto.com/9631548/1737313