一、tomcat中JDK安装
1、去tomcat官网下载程序并上传到src目录解压
tar -zxvf jdk-8u91-linux-x64.tar.gz
2、移动到local目录
mv jdk1.8.0_91 /usr/local/
3、配置环境变量
vim /etc/profile.d/java.sh
JAVA_HOME=/usr/local/jdk1.8.0_91/
JAVA_BIN=/usr/local/jdk1.8.0_91/bin
JRE_HOME=/usr/local/jdk1.8.0_91/jre
PATH=$PATH:/usr/local/jdk1.8.0_91/bin:/usr/local/jdk1.8.0_91/jre/bin
CLASSPATH=/usr/local/jdk1.8.0_91/jre/lib:/usr/local/jdk1.8.0_91/lib:/usr/local/jdk1.8.0_91/jre/lib/charsets.jar
4、卸载自带的java程序
yum remove java-1.6.0-openjdk* java-1.7.0-openjdk* java-1.5.0-gcj
5、验证是否生效
export JAVA_HOME JAVA_BIN JRE_HOME PATH CLASSPATH(或sh /etc/profile.d/java.sh)
java -version
java version "1.8.0_91"
Java(TM) SE Runtime Environment (build 1.8.0_91-b14)
Java HotSpot(TM) 64-Bit Server VM (build 25.91-b14, mixed mode)
二、安装tomcat
1、去tomcat官网下载并上传到src目录,解压
tar -zxvf apache-tomcat-7.0.69.tar.gz
2、移动到local目录
mv apache-tomcat-7.0.69 /usr/local/tomcat
3、拷贝启动文件设置开机启动
cd /usr/local/tomcat/
cp -v bin/catalina.sh /etc/init.d/tomcat
chmod 755 /etc/init.d/tomcat
编辑启动文件
添加以下内容
# chkconfig: 2345 63 37
. /etc/init.d/functions
JAVA_HOME=/usr/local/jdk1.8.0_91
CATALINA_HOME=/usr/local/tomcat
[root@redhat tomcat]# chkconfig --add tomcat
chkconfig tomcat on
/etc/init.d/tomcat start
4、使用浏览器访问
可以访问
三、tomcat配置和优化
1、修改配置文件
cd /usr/local/tomcat/conf/
vim server.xml
将<Connector port="8080"改为<Connector port="80"
添加虚拟主机
<Host name="www.123.com" appBase="/data/tomcatweb"
unpackWARs="false" autoDeploy="true"
xmlValidation="false" xmlNamespaceAware="false">
<Context path="" docBase="./" debug="0" reloadable="true" crossContext="true"/>
</Host>
2、重启
/etc/init.d/tomcat stop
/etc/init.d/tomcat start
3、查看监听端口变成80
netstat -lnp |grep java
tcp 0 0 :::80 :::* LISTEN
4、测试curl访问
mkdir -p /data/tomcatweb
vim /data/tomcatweb/1.txt
wqerwer
qwerq
wqer
curl -xlocalhost:80 www.123.com/1.txt #可以访问
5、测试解析jsp
vim /data/tomcatweb/1.jsp
<html><body><center>
Now time is: <%=new java.util.Date()%>
</center></body></html>
curl -xlocalhost:80 www.123.com/1.jsp
<html><body><center>
Now time is: Thu Jun 02 11:05:42 CST 2016
</center></body></html>
#可以解析
本文出自 “愺艮搥豩” 博客,请务必保留此出处http://riverxyz.blog.51cto.com/533303/1785411
原文地址:http://riverxyz.blog.51cto.com/533303/1785411