配置方法只适合tomcat7版本
一、安装JDK
##下载jdk1.6包,编译,移动目录
chmod a+x jdk-6u45-linux-x64.bin
../jdk-6u45-linux-x64.bin
mv jdk1.6.0_45/ /usr/local/jdk
##修改全局环境配置
vim /etc/profile
最后加入代码:
JAVA_HOME=/usr/local/jdk/JAVA_BIN=/usr/local/jdk/binJRE_HOME=/usr/local/jdk/jrePATH=$PATH:/usr/local/jdk/bin:/usr/local/jdk/jre/binCLASSPATH=/usr/local/jdk/jre/lib:/usr/local/jdk/lib:/usr/local/jdk/jre/lib/charsets.jarexport JAVA_HOME JAVA_BIN JRE_HOME PATH CLASSPATH
##使配置生效
source /etc/profile
##显示jdk信息
java -version
##显示以下内容表示成功
java version "1.6.0_45"
Java(TM) SE Runtime Environment (build 1.6.0_45-b06)
Java HotSpot(TM) 64-Bit Server VM (build 20.45-b01, mixed mode)
二、安装Tomcat
##下载源码包,解压,移动
cd /usr/local/src
wget http://mirrors.cnnic.cn/apache/tomcat/tomcat-7/v7.0.64/bin/apache-tomcat-7.0.64.tar.gz
tar zxvf apache-tomcat-7.0.64.tar.gz
mv apache-tomcat-7.0.64 /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.6.0_23/CATALINA_HOME=/usr/local/tomcat
##修改配置文件权限,并添加自动启动服务
chmod 755 /etc/init.d/tomcatchkconfig --add tomcatchkconfig tomcat on
##启动Tomcat
service tomcat start
三、配置Tomcat
1.配置Tomcat端口
##修改配置文件
vim /usr/local/tomcat/conf/server.xml
##找到<Connector port="8080" protocol="HTTP/1.1"
把8080修改为80,即端口变为80
2.配置虚拟主机
cd /usr/local/tomcat/conf/
vim server.xml
##找到</Host>下一行插入新的<Host>内容如下:
<Host name="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