16.1 Tomcat介绍
·Tomcat是Apache软件基金会(Apache Software Foundation)的Jakarta项目中的一个核心项目,由Apache、Sun和其他一些公司及个人共同开发而成。
·java程序写的网站用tomcat+jdk来运行
·tomcat是一个中间件,真正起作用的,解析java脚本的是jdk
·jdk(java development kit)是整个java的核心,它包含了java运行环境和一堆java相关的工具以及java基础库。
·最主流的jdk为sun公司发布的jdk,除此之外,其实IBM公司也有发布JDK,CentOS上也可以用yum安装openjdk
16.2 安装jdk
进入官网下载安装包:http://www.oracle.com/technetwork/java/javase/downloads/jdk8-downloads-2133151.html
选择正确的安装包,下载到windows本地
使用xftp上传到虚拟机中
[[email protected] ~]# cd /usr/local/src/ [[email protected] src]# ls httpd-2.2.34 jdk-8u161-linux-x64.tar.gz nginx-1.12.2 php-5.6.30 httpd-2.2.34.tar.gz mysql-5.6.36-linux-glibc2.5-x86_64.tar.gz nginx-1.12.2.tar.gz php-5.6.30.tar.bz2 [[email protected] src]# vi /etc/profile ##增加环境变量
JAVA_HOME=/usr/local/jdk1.8/
JAVA_BIN=/usr/local/jdk1.8/bin
JRE_HOME=/usr/local/jdk1.8/jre
PATH=$PATH:/usr/local/jdk1.8/bin:/usr/local/jdk1.8/jre/bin
CLASSPATH=/usr/local/jdk1.8/jre/lib:/usr/local/jdk1.8/lib:/usr/local/jdk1.8/jre/lib/charsets.jar
[[email protected] src]# source /etc/profile##source生效 [[email protected] src]# java -version ##查看jdk有没有生效,下方出现版本号就已生效 java version "1.8.0_161" Java(TM) SE Runtime Environment (build 1.8.0_161-b12) Java HotSpot(TM) 64-Bit Server VM (build 25.161-b12, mixed mode)
(但是如果版本号和安装的不符,则rpm -qa |grep openjdk,看是否安装了openjdk,yum list |grep openjdk把openjdk对应版本的包全部安装)
16.3 安装Tomcat
安装过程:
[[email protected] src]# wget http://mirrors.hust.edu.cn/apache/tomcat/tomcat-8/v8.5.29/bin/apache-tomcat-8.5.29.tar.gz (安装过程省略,安装包地址如果失效可以去官网找) [[email protected] src]# mv apache-tomcat-8.5.29 /usr/local/tomcat ##更改二进制包位置并改名 [[email protected] src]# /usr/local/tomcat/bin/startup.sh ##启动tomcat 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 Using CLASSPATH: /usr/local/tomcat/bin/bootstrap.jar:/usr/local/tomcat/bin/tomcat-juli.jar Tomcat started. [[email protected] src]# ps aux |grep java root 1467 1.6 8.6 2294712 85984 pts/0 Sl 21:57 0:05 /usr/local/jdk1.8/bin/java -Djava.util.logging.config.file=/usr/local/tomcat/conf/logging.properties -Djava.util.logging.manager=org.apache.juli.ClassLoaderLogManager -Djdk.tls.ephemeralDHKeySize=2048 -Djava.protocol.handler.pkgs=org.apache.catalina.webresources -Dignore.endorsed.dirs= -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 1534 0.0 0.0 112676 984 pts/0 R+ 22:02 0:00 grep --color=auto java
(tomcat不支持restart,如果需要重启,/usr/local/tomcat/bin/shutdown.sh 后,在执行 startup.sh)
[[email protected] src]# netstat -lntp |grep java tcp6 0 0 :::8080 :::* LISTEN 1467/java tcp6 0 0 127.0.0.1:8005 :::* LISTEN 1467/java tcp6 0 0 :::8009 :::* LISTEN 1467/java
三个端口:8080为提供web服务的端口,8005为管理端口,8009端口为第三方服务调用的端口,比如httpd和Tomcat结合时会用到
浏览器访问本机8080端口:http://192.168.65.128:8080/
原文地址:http://blog.51cto.com/11530642/2092213