Tomcat介绍安装JDK安装Tomcat

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Tomcat介绍安装JDK安装Tomcat相关的知识,希望对你有一定的参考价值。

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。

安装jdk

技术分享图片

1.安装jdk
[[email protected] ~]# cd /usr/local/src/
[[email protected] src]# rz  //使用rz或xftp把下载好的jdk软件上传到目录下
[[email protected] src]# tar zxvf jdk-8u151-linux-x64.tar.gz  //解压
[[email protected] src]# mv jdk1.8.0_151 /usr/local/jdk1.8
[[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 //执行命令使其生效
[[email protected] src]# java -version  //检查配置是否正常
java version "1.8.0_151"
Java(TM) SE Runtime Environment (build 1.8.0_151-b12)
Java HotSpot(TM) 64-Bit Server VM (build 25.151-b12, mixed mode)

//如果这里显示的不一样,有可能是因为系统调用了rpm的openjdk,可以使用which java检测,结果为/usr/bin/java则说明是pm的JDK,而且执行java -version时会有openjdk字样,如果想使用自己安装的jdk,可做如下处理:

# mv /user/bin/java /usr/bin/java_bak
#source /etc/profile
再执行java -version,显示结果就会正常。

安装Tomcat

1.安装tomcat操作
[[email protected] ~]# cd /usr/local/src/
[[email protected] src]# wget https://mirrors.tuna.tsinghua.edu.cn/apache/tomcat/tomcat-8/v8.5.24/bin/apache-tomcat-8.5.24.tar.gz
[[email protected] src]# tar zxvf apache-tomcat-8.5.24.tar.gz 
[[email protected] src]# mv apache-tomcat-8.5.24 /usr/local/tomcat
2.验证安装是否成功
[[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
//查是否有java相关进程

root      21197  2.7  8.6 2294080 86692 pts/1   Sl   16:40   0:07 /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      21246  0.0  0.0 112680   976 pts/1    R+   16:45   0:00 grep --color=auto java
[[email protected] src]# ps aux |grep tomcat
root      21197 19.1  8.1 2294080 81016 pts/1   Sl   16:40   0:07 /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      21241  0.0  0.0 112680   976 pts/1    R+   16:40   0:00 grep --color=auto tomcat
[[email protected] src]# netstat -lntp |grep java
//正常会有三个端口8009、8005和8080
//其中8080为提供wed服务的端口,8005为管理端口,8009为第三方服务调用端口(如httpd和Tomcat结合时会用到)
tcp6       0      0 :::8080                 :::*                    LISTEN      21197/java          
tcp6       0      0 127.0.0.1:8005          :::*                    LISTEN      21197/java          
tcp6       0      0 :::8009                 :::*                    LISTEN      21197/java   

[[email protected] src]# /usr/local/tomcat/bin/shutdown.sh //关闭服务命令
[[email protected] src]# iptables -nvL //查看有没防火墙
[[email protected] src]# systemctl stop firewalld //关闭防火墙
[[email protected] src]# systemctl disable firewalld

浏览器验证:

技术分享图片

3.设置开机启动
[[email protected] src]# echo "/usr/local/tomcat/bin/startup.sh" >> /etc/rc.d/rc.local
[[email protected] src]# chmod a+x /etc/rc.d/rc.local //默认该文件没有x权限,需要加一下

以上是关于Tomcat介绍安装JDK安装Tomcat的主要内容,如果未能解决你的问题,请参考以下文章

五十八Tomcat介绍安装jdk安装Tomcat

Tomcat介绍安装JDK安装Tomcat

Tomcat介绍,安装JDK,安装Tomcat

16.1 Tomcat介绍 16.2 安装jdk 16.3 安装Tomcat

Tomcat介绍 安装jdk 安装Tomcat

Tomcat介绍 安装jdk 安装Tomcat