tomcatJDK安装

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

[root@wangchaosrc]#wget http://download.oracle.com/otn-pub/java/jdk/8u51-b16/jdk-8u51-linux-i586.tar.gz?AuthParam=1437564943_0e9e4215c41bb100c587fbae5f08d8cd

[root@wangchaosrc]#mv jdk-8u51-linux-i586.tar.gz\?AuthParam\=1437564943_0e9e4215c41bb100c587fbae5f08d8cd jdk-8u51-linux-i586.tar.gz

[root@wangchao src]# tar zxvf jdk-8u51-linux-i586.tar.gz

[root@wangchao src]# ls

jdk1.8.0_51

[root@wangchao src]# mv jdk1.8.0_51/ /usr/local/

[root@wangchao src]# ls /usr/local/

jdk1.8.0_51

[root@wangchao src]# vim /etc/profile.d/java.sh

JAVA_HOME=/usr/local/jdk1.8.0_51

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

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

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

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

 

[root@wangchao src]# ls /usr/local/jdk1.8.0_51           //查看,确保这些路径存在

root@wangchao src]# ls /usr/local/jdk1.8.0_51/bin

[root@wangchao src]# ls /usr/local/jdk1.8.0_51/jre

 

[root@wangchao src]# source  /etc/profile.d/java.sh

[root@wangchao src]# java -version              //查看java版本,此版本为系统自安装的、

java version "1.7.0_65"

 

卸载

[root@wangchao src]# which java

/usr/bin/java

[root@wangchao src]# rpm -qf /usr/bin/java

file /usr/bin/java is not owned by any package

[root@wangchao src]# yum list |grep jdk

[root@wangchao src]# yum remove java-1.7.0-openjdk* java-1.6.0-openjdk*

[root@wangchao src]# java -version

-bash: /usr/bin/java: No such file or directory

//无任何版本信息了

 

[root@wangchao src]# source  /etc/profile.d/java.sh

[root@wangchao src]# java -version

java version "1.8.0_51"                 //出现此版本信息,说明jdk已安装成功了

tomcat安装

[root@wangchaosrc]#wget http://apache.fayea.com/tomcat/tomcat-7/v7.0.63/bin/apache-tomcat-7.0.63.tar.gz

[root@wangchao src]# ls

apache-tomcat-7.0.63.tar.gz

[root@wangchao src]# tar zxvf apache-tomcat-7.0.63.tar.gz

[root@wangchao src]# mv apache-tomcat-7.0.63 /usr/local/tomcat

[root@wangchao src]# ls /usr/local/tomcat/

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

[root@wangchao tomcat]# cp -v bin/catalina.sh /etc/init.d/tomcat

[root@wangchao tomcat]# chmod 755 /etc/init.d/tomcat

root@wangchao tomcat]# chkconfig --add tomcat

service tomcat does not support chkconfig              //报错不支持

 

 

[root@wangchao 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_51

CATALINA_HOME=/usr/local/tomcat

 

[root@wangchao tomcat]# chkconfig --add tomcat

[root@wangchao tomcat]# chkconfig tomcat on

[root@wangchao tomcat]# /etc/init.d/tomcat start

 

[root@wangchao tomcat]# ps aux |grep tomcat

root      2898 10.6  4.6 337584 48040 pts/0    Sl   04:19   0:03 /usr/local/jdk1.8.0_51/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@wangchao tomcat]# netstat -lnp

tcp        0   0 ::ffff:127.0.0.1:8005      :::*                LISTEN      2898/java

tcp        0   0 :::8009         :::*                        LISTEN      2898/java

tcp      0    0 :::8080          :::*                        LISTEN      2898/java

 

 

 

[root@wangchao tomcat]# /etc/init.d/tomcat stop                //重启需先stop、再start

[root@wangchao tomcat]# /etc/init.d/tomcat start

[root@wangchao tomcat]# iptables -nvL

 

windows访问192.168.137.22:8080.出现tomcat默认页面

spacer.gif

 

 

 

 

tomcat的优化

 

[root@wangchao tomcat]# cd /usr/local/tomcat/conf/

[root@wangchao conf]# ls

[root@wangchao conf]# vim server.xml

<Connector port="8080" protocol="HTTP/1.1"中的8080改成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>

 

[root@wangchao conf]# mkdir -p /data/tomcatweb

[root@wangchao conf]# /etc/init.d/tomcat stop

[root@wangchao conf]# /etc/init.d/tomcat start

[root@wangchao conf]# ps aux |grep java

root      3576 16.9  4.7 337456 48656 pts/0    Sl   04:36   0:03 /usr/local/jdk1.8.0_51/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@wangchao conf]# netstat -lnp

tcp        0      0 :::80       :::*              LISTEN      3656/java

 

//监听端口变为80

客户端访问192.168.137.22无需再加8080

spacer.gif

 

 

 

 

[root@wangchao conf]# touch /data/tomcatweb/1.txt

[root@wangchao conf]# cd /data/tomcatweb/

[root@wangchao tomcatweb]# vim 1.txt

11112

[root@wangchao tomcatweb]# curl -xlocalhost:80 www.123.com/1.txt

11112                                 

//测试可访内容

[root@wangchao tomcatweb]# vim /data/tomcatweb/1.jsp

<html><body><center>

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

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

[root@wangchao tomcatweb]# curl -xlocalhost:80 www.123.com/1.jsp

<html><body><center>

Now time is: Thu Jul 23 04:47:29 CST 2015

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

//正常解析其时间