tomcat的安装配置

一. tomcat安装配置

 1. 什么是tomcat

 Tomcat就是用来解析jsp程序的一个软件

Tomcat是Apache 软件基金会(Apache Software Foundation)的Jakarta项目中的一个核心项目,由Apache、Sun和其他一些公司及个人共同开发而成。  

 Tomcat是一个轻量级应用服务器,在中小型系统和并发访问用户不是很多的场合下被普遍使用,是开发和调试JSP程序的首选。


2.安装GDK

JDK(Java Development Kit) 是 Java 语言的软件开发工具包(SDK)。没有JDK的话,无法编译Java程序。


下载jdk    本篇使用的版本为jdk-8u45-linux-i586.tar.gz


[root@webserver ~]# tar zxvf jdk-8u45-linux-i586.tar.gz

[root@webserver ~]# mv jdk1.8.0_45 /usr/local/

[root@webserver ~]# vi /etc/profile.d/java.sh   


JAVA_HOME=/usr/local/jdk1.8.0_45

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

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

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

CLASSPATH=/usr/local/jdk1.8.0_45/jre/lib:/usr/local/jdk1.8.0_45/lib:/usr/local/jdk1.8.0_45/jre/lib/charsets.jar

[root@webserver ~]# . /etc/profile.d/java.sh

[root@webserver ~]# java -version   //查看安装java的版本
java version "1.8.0_45"
Java(TM) SE Runtime Environment (build 1.8.0_45-b14)
Java HotSpot(TM) Client VM (build 25.45-b02, mixed mode)

 

3.安装tomcat

[root@webserver ~]# cd /usr/local/src/

[root@webserver src]# wget http://apache.fayea.com/tomcat/tomcat-7/v7.0.62/bin/apache-tomcat-7.0.62.tar.gz

[root@webserver src]# tar zxf apache-tomcat-7.0.62.tar.gz

[root@webserver src]# mv apache-tomcat-7.0.62 /usr/local/tomcat
[root@webserver src]# cp -pv /usr/local/tomcat/bin/catalina.sh /etc/init.d/tomcat
"/usr/local/tomcat/bin/catalina.sh" -> "/etc/init.d/tomcat"
[root@webserver src]# vi /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

 
[root@webserver src]# chmod 755 /etc/init.d/tomcat 
[root@webserver src]# chkconfig --add tomcat
[root@webserver src]# chkconfig tomcat on

[root@webserver src]# service tomcat start
Using CATALINA_BASE:   /usr/local/tomcat
Using CATALINA_HOME:   /usr/local/tomcat
Using CATALINA_TMPDIR: /usr/local/tomcat/temp
Using JRE_HOME:        /usr/local/jdk1.8.0_45
Using CLASSPATH:       /usr/local/tomcat/bin/bootstrap.jar:/usr/local/tomcat/bin/tomcat-juli.jar
Tomcat started.

[root@webserver src]# ps aux |grep tomcat
root      1518 10.0  4.7 339000 48932 pts/1    Sl   04:03   0:04 /usr/local/jdk1.8.0_45/bin/java -Djava.util.logging.config.file=/usr/local/tomcat/conf/logging.properties -Djava.util.logging.manager=org.apache.juli.ClassLoaderLogManager -Djava.endorsed.dirs=/usr/local/tomcat/endorsed -classpath /usr/local/tomcat/bin/bootstrap.jar:/usr/local/tomcat/bin/tomcat-juli.jar -Dcatalina.base=/usr/local/tomcat -Dcatalina.home=/usr/local/tomcat -Djava.io.tmpdir=/usr/local/tomcat/temp org.apache.catalina.startup.Bootstrap start
root      1536  0.0  0.0   5980   728 pts/1    S+   04:03   0:00 grep tomcat

wKiom1Vpr4nhbBDOAARyhKl1dso778.jpg

spacer.gif


4.配置tomcat

 更改默认启动端口:

[root@webserver src]# cd /usr/local/tomcat

[root@webserver conf]# vim conf/server.xml   //把Connector port=“8080”  改为 Connector port="80"

 

 -->

    <Connector port="80" protocol="HTTP/1.1"

               connectionTimeout="20000"

               redirectPort="8443" />

    <!-- A "Connector" using the shared thread pool-->

    <!--


5.配置新虚拟主机:

[root@webserver conf]# vi /usr/local/tomcat/conf/server.xml     //找到</Host>下一行插入新的<Host>内容如下: 


     <Host name="www.111.com" appBase="/data/tomcatweb"
        unpackWARs="false" autoDeploy="true" xmlValidation="false"
        xmlNamespaceAware="false">
        <Context path="" docBase="./" debug="0" reloadable="true" crossContext="true"/>
    </Host>

[root@webserver conf]# mkdir /data/tomcatweb

[root@webserver conf]# /etc/init.d/tomcat stop
Using CATALINA_BASE:   /usr/local/tomcat
Using CATALINA_HOME:   /usr/local/tomcat
Using CATALINA_TMPDIR: /usr/local/tomcat/temp
Using JRE_HOME:        /usr/local/jdk1.8.0_45
Using CLASSPATH:       /usr/local/tomcat/bin/bootstrap.jar:/usr/local/tomcat/bin/tomcat-juli.jar
[root@webserver conf]# /etc/init.d/tomcat start
Using CATALINA_BASE:   /usr/local/tomcat
Using CATALINA_HOME:   /usr/local/tomcat
Using CATALINA_TMPDIR: /usr/local/tomcat/temp
Using JRE_HOME:        /usr/local/jdk1.8.0_45
Using CLASSPATH:       /usr/local/tomcat/bin/bootstrap.jar:/usr/local/tomcat/bin/tomcat-juli.jar
Tomcat started.
[root@webserver conf]# netstat -lnp |grep 80
tcp        0      0 ::ffff:127.0.0.1:8005       :::*                        LISTEN      2966/java           
tcp        0      0 :::8009                     :::*                        LISTEN      2966/java           
tcp        0      0 :::80                       :::*                        LISTEN      2966/java           

[root@webserver conf]# cd /data/tomcatweb/
[root@webserver tomcatweb]# vi time.jsp


<html><body><center>

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

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


[root@webserver tomcatweb]# curl -xlocalhost:80 www.111.com/time.jsp
<html><body><center> 
Now time is: Fri May 29 05:14:48 CST 2015 
</center></body></html>
[root@webserver tomcatweb]# date
2015年 05月 29日 星期五 05:14:54 CS

你可能感兴趣的:(tomcat,安装,配置)