tomcat

Tomcat

Tomcat是Apache 软件基金会(Apache Software Foundation)的Jakarta 项目中的一个核心项目,由Apache、Sun 和其他一些公司及个人共同开发而成。由于有了Sun 的参与和支持,最新的Servlet 和JSP 规范总是能在Tomcat 中得到体现,Tomcat 5支持最新的Servlet 2.4 和JSP 2.0 规范。

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

诀窍是,当配置正确时,Apache 为HTML页面服务,而Tomcat 实际上运行JSP 页面和Servlet。另外,Tomcat和IIS等Web服务器一样,具有处理HTML页面的功能,另外它还是一个Servlet和JSP容器,独立的Servlet容器是Tomcat的默认模式。不过,Tomcat处理静态HTML的能力不如Apache服务器。

1. 安装JDK

在oracel官网下载jdk并安装

#首先安装gcc
[root@localhost ~]# yum -y install gcc
#安装openjdk1.8或者安装指定版本
`yum -y install java-1.8.0-openjdk java-1.8.0-openjdk-devel`

#安装指定版本:
#将软件包上传、解压、并移至指定位置
[root@localhost ~]# ls
anaconda-ks.cfg  jdk-14.0.2_linux-x64_bin.tar.gz
[root@localhost ~]# tar xf jdk-14.0.2_linux-x64_bin.tar.gz 
[root@localhost ~]# ls
anaconda-ks.cfg  jdk-14.0.2  jdk-14.0.2_linux-x64_bin.tar.gz
[root@localhost ~]# cp -r jdk-14.0.2 /usr/local/jdk14.0

#配置JD看环境变量
export JAVA_HOME=/usr/local/jdk14.0
export JAVA_BIN=/usr/local/jdk14.0/bin
export CLASSPATH=.:$JAVA_HOME/lib/dt.jar:$JAVA_HOME/lib/tools.jar
export PATH=$PATH:$JAVA_HOME/bin


#查看java是否安装成功
[root@localhost ~]# java -version
java version "14.0.2" 2020-07-14
Java(TM) SE Runtime Environment (build 14.0.2+12-46)
Java HotSpot(TM) 64-Bit Server VM (build 14.0.2+12-46, mixed mode, sharing)



2. 安装tomcat

官网上下载tomcat

#下载tomcat
[root@localhost ~]# wget https://archive.apache.org/dist/tomcat/tomcat-9/v9.0.37/bin/apache-tomcat-9.0.37.tar.gz

[root@localhost ~]# tar xf apache-tomcat-9.0.37.tar.gz 
[root@localhost ~]# mv apache-tomcat-9.0.37 /usr/local/tomcat

#启动tomcat
[root@localhost ~]# /usr/local/tomcat/bin/catalina.sh 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/jdk14.0
Using CLASSPATH:       /usr/local/tomcat/bin/bootstrap.jar:/usr/local/tomcat/bin/tomcat-juli.jar
Tomcat started.
[root@localhost ~]# ss -tanl
State      Recv-Q Send-Q Local Address:Port               Peer Address:Port              
LISTEN     0      100      127.0.0.1:25                           *:*                  
LISTEN     0      128              *:22                           *:*                  
LISTEN     0      100          [::1]:25                        [::]:*                  
LISTEN     0      1       [::ffff:127.0.0.1]:8005                      [::]:*                  
LISTEN     0      100           [::]:8080                      [::]:*                  
LISTEN     0      128           [::]:22                        [::]:*   



3. 配置管理页面

#配置用户
[root@localhost ~]# vim /usr/local/tomcat/conf/tomcat-users.xml
#加上下面三行
<role rolename="manager-gui"/>
<role rolename="admin-gui"/>
<user username="tomcat" password="123456" roles="manager-gui,admin-gui"/>

</tomcat-users>


#配置manager访问来源
[root@localhost ~]# vim /usr/local/tomcat/webapps/manager/META-INF/context.xml 
#找到
         allow="127\.\d+\.\d+\.\d+|::1|0:0:0:0:0:0:0:1" />
#修改为192.168.32网段能访问
         allow="192\.168\.32\.\d+|127\.\d+\.\d+\.\d+|::1|0:0:0:0:0:0:0:1" />

#配置host manager访问来源
[root@localhost ~]# vim /usr/local/tomcat/webapps/host-manager/META-INF/context.xml
#找到
         allow="127\.\d+\.\d+\.\d+|::1|0:0:0:0:0:0:0:1" />
#修改为192.168.32网段能访问
         allow="192\.168\.32\.\d+|127\.\d+\.\d+\.\d+|::1|0:0:0:0:0:0:0:1" />


#重启tomcat
[root@localhost ~]# /usr/local/tomcat/bin/catalina.sh 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/jdk14.0
Using CLASSPATH:       /usr/local/tomcat/bin/bootstrap.jar:/usr/local/tomcat/bin/tomcat-juli.jar
NOTE: Picked up JDK_JAVA_OPTIONS:  --add-opens=java.base/java.lang=ALL-UNNAMED --add-opens=java.base/java.io=ALL-UNNAMED --add-opens=java.rmi/sun.rmi.transport=ALL-UNNAMED
[root@localhost ~]# /usr/local/tomcat/bin/catalina.sh 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/jdk14.0
Using CLASSPATH:       /usr/local/tomcat/bin/bootstrap.jar:/usr/local/tomcat/bin/tomcat-juli.jar
Tomcat started.
[root@localhost ~]# ss -tanl
State      Recv-Q Send-Q Local Address:Port               Peer Address:Port              
LISTEN     0      100      127.0.0.1:25                           *:*                  
LISTEN     0      128              *:22                           *:*                  
LISTEN     0      100          [::1]:25                        [::]:*                  
LISTEN     0      1       [::ffff:127.0.0.1]:8005                      [::]:*                  
LISTEN     0      100           [::]:8080                      [::]:*                  
LISTEN     0      128           [::]:22                        [::]:*     




posted @ 2020-08-01 18:44  EverEternity  阅读(150)  评论(0编辑  收藏  举报