1、Tomcat是Apache软件基金会(Apache software foundation),的Jakarta项目中的一个核心项目,由Apache、Sun和其他一些公司及个人共同开发而成。
Tomcat服务器是一个免费的开放源代码的Web应用服务器,属于轻量级应用服务器,在中小型系统和并发访问用户不是很多的场合下被普遍使用,实际上tomcat是apache的一个扩展,但运行时它是独立运行的,所有当运行tomcat时,它是作为一个与apache独立的进程单独运行的:
java程序写的网站用Tomcat+JDK来运行,
Tomcat是一个中间件,真正起作用的,解析Java脚本的是JDK。JDK(Java development kit)是整个Java的核心,它包含了Java运行环境和一堆Java相关的工具以及Java基础库。
最主流的JDK是由sun公司发布的JDK,除此之外,IBM公司也有发布JDK,centos上也可以使用yum安装openjdk。
2、安装jdk:jdk常用版本有1.6 1.7 1.8:简称 6 7 8:本次我们使用的是8:
需要打开官网地址:http://www.oracle.com/technetwork/java/javase/downloads/jdk8-downloads-2133151.html
手动下载到本机器,并借助xshell的rz工具上传到/usr/local/src目录下:如下:
[root@localhost_002 111.com]# cd /usr/local/src/
[root@localhost_002 src]# ls jdk-8u181-linux-x64.tar.gz
jdk-8u181-linux-x64.tar.gz
解压:
[root@localhost_002 src]# tar zxvf jdk-8u181-linux-x64.tar.gz
挪目录位置:
[root@localhost_002 src]# cp -r jdk1.8.0_181/ /usr/local/jdk1.8
[root@localhost_002 src]# cd /usr/local/jdk1.8/
设置环境变量,在文本最下面添加如下内容: vim /etc/profile
[root@localhost_002 jdk1.8]#vim /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
[root@localhost_002 jdk1.8]# source /etc/profile #刷新配置生效:
坚持jdk是否安装成功: java -version
[root@localhost_002 jdk1.8]# java -version
java version "1.8.0_181"
Java(TM) SE Runtime Environment (build 1.8.0_181-b13)
Java HotSpot(TM) 64-Bit Server VM (build 25.181-b13, mixed mode)
安装步骤:
下载步骤略过:
[root@localhost_002 src]# tar zxvf jdk-8u181-linux-x64.tar.gz
[root@localhost_002 src]# cp -r jdk1.8.0_181/ /usr/local/jdk1.8
[root@localhost_002 src]# cd /usr/local/jdk1.8/
[root@localhost_002 jdk1.8]# vim /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
[root@localhost_002 jdk1.8]# source /etc/profile #刷新配置生效:
[root@localhost_002 jdk1.8]# java -version
java version "1.8.0_181"
Java(TM) SE Runtime Environment (build 1.8.0_181-b13)
Java HotSpot(TM) 64-Bit Server VM (build 25.181-b13, mixed mode)
2、安装Tomcat:tomcat是一个中间件,真正起作用的是jdk,而访问80 需要有一个webserver,需要依赖jdk:
1:下载: wget http://apache.fayea.com/tomcat/tomcat-8/v8.5.33/bin/apache-tomcat-8.5.33.tar.gz
解压并挪目录:
tar zxvf apache-tomcat-8.5.33.tar.gz
mv apache-tomcat-8.5.33 /usr/local/tomcat
然后直接启动tomcat即可: /usr/local/tomcat/bin/startup.sh
[root@localhost_002 tomcat]# /usr/local/tomcat/bin/startup.sh
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.
#详细安装步骤:
[root@localhost_002 src]# wget http://apache.fayea.com/tomcat/tomcat-8/v8.5.20/bin/apache-tomcat-8.5.20.tar.gz
[root@localhost_002 src]# tar zxvf apache-tomcat-8.5.33.tar.gz #解压:
[root@localhost_002 src]# mv apache-tomcat-8.5.33 /usr/local/tomcat #挪位置:
[root@localhost_002 tomcat]# /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.
2:查看tomcat是否启动: ps aux |grep tomcat : 有java字眼则启动了:
[root@localhost_002 tomcat]# ps aux |grep tomcat
root 1430 2.8 8.6 2294196 86696 pts/0 Sl 19:07 0:04 /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 -Dorg.apache.catalina.security.SecurityListener.UMASK=0027 -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 1478 0.0 0.0 112720 972 pts/0 R+ 19:10 0:00 grep --color=auto tomcat
3:关闭tomcat,有时当修改了配置文件,需要先关闭在启动:
[root@localhost_002 tomcat]# /usr/local/tomcat/bin/shutdown.sh
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
4:查看其监听的端口(8005): netstat -lntp
[root@localhost_002 tomcat]# netstat -lntp
Active Internet connections (only servers)
Proto Recv-Q Send-Q Local Address Foreign Address State PID/Program name
tcp 0 0 0.0.0.0:52588 0.0.0.0:* LISTEN 871/sshd
tcp 0 0 127.0.0.1:25 0.0.0.0:* LISTEN 1081/master
tcp6 0 0 :::52588 :::* LISTEN 871/sshd
tcp6 0 0 :::8080 :::* LISTEN 1430/java
tcp6 0 0 :::80 :::* LISTEN 1212/httpd
tcp6 0 0 ::1:25 :::* LISTEN 1081/master
tcp6 0 0 127.0.0.1:8005 :::* LISTEN 1430/java
tcp6 0 0 :::8009 :::* LISTEN 1430/java
tcp6 0 0 :::3306 :::* LISTEN 1094/mysqld
[root@localhost_002 tomcat]# netstat -lntp |grep java
tcp6 0 0 :::8080 :::* LISTEN 1528/java
tcp6 0 0 127.0.0.1:8005 :::* LISTEN 1528/java
tcp6 0 0 :::8009 :::* LISTEN 1528/java
然后我们发现java启动的端口有3个: 8080 8009 8005
8080:提供web服务的端口:
8005:为管理管理端口:
8009:为第三方服务调用的端口:比如httpd和tomcat结合时会使用:
来源:oschina
链接:https://my.oschina.net/u/3711371/blog/1936838