tomcat安装

tomcat中JDK安装:

解压,将解压后的目录放入到/usr/local/下;

vim /etc/profile.d/java.sh

JAVA_HOME=/usr/local/jdk1.8.0_31

JAVA_BIN=/usr/local/jdk1.8.0_31/bin

JRE_HOME=/usr/local/jdk1.8.0_31/jre

PATH=$PATH:/usr/local/jdk1.8.0_31/bin:/usr/local/jdk1.8.0_31/jre/bin

CLASSPATH=/usr/local/jdk1.8.0_31/jre/lib:/usr/local/jdk1.8.0_31/lib:/usr/local/jdk1.8.0_31/

jre/lib/charsets.jar

初始化:source /etc/profile.d/java.sh

如果配置没有问题应该可以看到Java的版本信息;

java -version


tomcat安装:

下载:wget http://apache.fayea.com/tomcat/tomcat-7/v7.0.63/bin/apache-tomcat-7.0.63.tar.gz

解压:tar -zxvf apache-tomcat-7.0.65.tar.gz

mv apache-tomcat-7.0.65 /usr/local/tomcat

cp -pv /usr/local/tomcat/bin/catalina.sh /etc/init.d/tomcat

编辑配置文件:vim /etc/init.d/tomcat

从第二行加入以下配置:

# chkconfig: 2345 63 37

# description: tomcat server init script

# Source Function Library

. /etc/init.d/functions

JAVA_HOME=/usr/local/jdk1.8.0_31

CATALINA_HOME=/usr/local/tomcat

启动tomcat服务;

用浏览器访问ip:8080可以看到tomcat欢迎界面;


tomcat默认启动8080端口,可以修改为80端口:

vim /usr/local/tomcat/conf/server.xml

<Connector port="8080" protocol="HTTP/1.1" 红线部分改为80即可;


vim /usr/local/tomcat/conf/server.xml

在</Host>下面插入:

<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>

tomcat8.0配置docBase="./"这部分空着,表示根目录在appbase指定的目录下,不能写成.或者./;

如果写为./ROOT,就是/data/tomcatweb/ROOT这就要把网站脚本放在这下面了。

创建目录:mkdir /data/tomcatweb 

cp -r /usr/local/tomcat/webapps/* /data/tomcatweb/

重启tomcat;


vim /data/tomcatweb/1.jsp

<html><body><center>

Now time is: <%=new java.util.Date()%>

</center></body></html>

用curl访问:

curl -xlocalhost:80 www.123.com/1.jsp

结果显示:

<html><body><center>

Now time is: Thu Apr 07 16:06:58 CST 2016

</center></body></html>


















你可能感兴趣的:(tomcat)