Linux中安装Tomcat-二、Tomcat安装

时间:2024-10-27 08:33:12

2.1、查看可用的JDK

[root@iZbp1izvhfvbrd0mb6ktasZ ~]# yum search java|grep jdk
ldapjdk-javadoc.noarch : Javadoc for ldapjdk
openjdk-asmtools-javadoc.noarch : Javadoc for openjdk-asmtools
java-1.6.0-openjdk.x86_64 : OpenJDK Runtime Environment
java-1.6.0-openjdk-demo.x86_64 : OpenJDK Demos
java-1.6.0-openjdk-devel.x86_64 : OpenJDK Development Environment
java-1.6.0-openjdk-javadoc.x86_64 : OpenJDK API Documentation
java-1.6.0-openjdk-src.x86_64 : OpenJDK Source Bundle
java-1.7.0-openjdk.x86_64 : OpenJDK Runtime Environment
java-1.7.0-openjdk-accessibility.x86_64 : OpenJDK accessibility connector
java-1.7.0-openjdk-demo.x86_64 : OpenJDK Demos
java-1.7.0-openjdk-devel.x86_64 : OpenJDK Development Environment
java-1.7.0-openjdk-headless.x86_64 : The OpenJDK runtime environment without
java-1.7.0-openjdk-javadoc.noarch : OpenJDK API Documentation
java-1.7.0-openjdk-src.x86_64 : OpenJDK Source Bundle
java-1.8.0-openjdk.i686 : OpenJDK Runtime Environment 8
java-1.8.0-openjdk.x86_64 : OpenJDK 8 Runtime Environment
java-1.8.0-openjdk-accessibility.i686 : OpenJDK accessibility connector
java-1.8.0-openjdk-accessibility.x86_64 : OpenJDK accessibility connector
java-1.8.0-openjdk-demo.i686 : OpenJDK Demos 8
java-1.8.0-openjdk-demo.x86_64 : OpenJDK 8 Demos
java-1.8.0-openjdk-devel.i686 : OpenJDK Development Environment 8
java-1.8.0-openjdk-devel.x86_64 : OpenJDK 8 Development Environment
java-1.8.0-openjdk-headless.i686 : OpenJDK Headless Runtime Environment 8
java-1.8.0-openjdk-headless.x86_64 : OpenJDK 8 Headless Runtime Environment
java-1.8.0-openjdk-javadoc.noarch : OpenJDK 8 API documentation
java-1.8.0-openjdk-javadoc-zip.noarch : OpenJDK 8 API documentation compressed
java-1.8.0-openjdk-src.i686 : OpenJDK Source Bundle 8
java-1.8.0-openjdk-src.x86_64 : OpenJDK 8 Source Bundle
java-11-openjdk.i686 : OpenJDK Runtime Environment 11
java-11-openjdk.x86_64 : OpenJDK 11 Runtime Environment
java-11-openjdk-demo.i686 : OpenJDK Demos 11
java-11-openjdk-demo.x86_64 : OpenJDK 11 Demos
java-11-openjdk-devel.i686 : OpenJDK Development Environment 11
java-11-openjdk-devel.x86_64 : OpenJDK 11 Development Environment
java-11-openjdk-headless.i686 : OpenJDK Headless Runtime Environment 11
java-11-openjdk-headless.x86_64 : OpenJDK 11 Headless Runtime Environment
java-11-openjdk-javadoc.i686 : OpenJDK 11 API documentation
java-11-openjdk-javadoc.x86_64 : OpenJDK 11 API documentation
java-11-openjdk-javadoc-zip.i686 : OpenJDK 11 API documentation compressed in a
java-11-openjdk-javadoc-zip.x86_64 : OpenJDK 11 API documentation compressed in
java-11-openjdk-jmods.i686 : JMods for OpenJDK 11
java-11-openjdk-jmods.x86_64 : JMods for OpenJDK 11
java-11-openjdk-src.i686 : OpenJDK Source Bundle 11
java-11-openjdk-src.x86_64 : OpenJDK 11 Source Bundle
java-11-openjdk-static-libs.i686 : OpenJDK libraries for static linking 11
java-11-openjdk-static-libs.x86_64 : OpenJDK 11 libraries for static linking
ldapjdk.noarch : The Mozilla LDAP Java SDK
openjdk-asmtools.noarch : To develop tools create proper & improper Java

2.2、安装OpenJDK 11

[root@iZbp1izvhfvbrd0mb6ktasZ ~]# yum install -y java-11-openjdk java-11-openjdk-devel

2.3、配置环境变量

[root@iZbp1izvhfvbrd0mb6ktasZ ~]# vi /etc/profile
export JAVA_HOME=/usr/lib/jvm/java-11-openjdk
export CLASSPATH=.:$JAVA_HOME/lib/dt.jar:$JAVA_HOME/lib/tools.jar
export PATH=$JAVA_HOME/bin:$PATH

2.4、验证安装

[root@iZbp1izvhfvbrd0mb6ktasZ ~]# java -version
openjdk version "11.0.23" 2024-04-16 LTS
OpenJDK Runtime Environment (Red_Hat-11.0.23.0.9-2.el7_9) (build 11.0.23+9-LTS)
OpenJDK 64-Bit Server VM (Red_Hat-11.0.23.0.9-2.el7_9) (build 11.0.23+9-LTS, mixed mode, sharing)

2.5、查看tomcat的可以用版本

注:以下两条命令都可查看

[root@iZbp1izvhfvbrd0mb6ktasZ ~]# yum list all | grep tomcat
jglobus-ssl-proxies-tomcat.noarch        2.1.0-13.el7                  epel     
tomcat.noarch                            7.0.76-16.el7_9               updates  
tomcat-admin-webapps.noarch              7.0.76-16.el7_9               updates  
tomcat-docs-webapp.noarch                7.0.76-16.el7_9               updates  
tomcat-el-2.2-api.noarch                 7.0.76-16.el7_9               updates  
tomcat-javadoc.noarch                    7.0.76-16.el7_9               updates  
tomcat-jsp-2.2-api.noarch                7.0.76-16.el7_9               updates  
tomcat-jsvc.noarch                       7.0.76-16.el7_9               updates  
tomcat-lib.noarch                        7.0.76-16.el7_9               updates  
tomcat-native.x86_64                     1.2.35-1.el7                  epel     
tomcat-servlet-3.0-api.noarch            7.0.76-16.el7_9               updates  
tomcat-webapps.noarch                    7.0.76-16.el7_9               updates  
tomcatjss.noarch                         7.2.5-1.el7                   base     
[root@iZbp1izvhfvbrd0mb6ktasZ ~]# yum search tomcat
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
================================================================================== N/S matched: tomcat ===================================================================================
jglobus-ssl-proxies-tomcat.noarch : Globus Java - SSL and proxy certificate support for Tomcat
tomcat-admin-webapps.noarch : The host-manager and manager web applications for Apache Tomcat
tomcat-docs-webapp.noarch : The docs web application for Apache Tomcat
tomcat-javadoc.noarch : Javadoc generated documentation for Apache Tomcat
tomcat-jsp-2.2-api.noarch : Apache Tomcat JSP API implementation classes
tomcat-jsvc.noarch : Apache jsvc wrapper for Apache Tomcat as separate service
tomcat-lib.noarch : Libraries needed to run the Tomcat Web container
tomcat-native.x86_64 : Tomcat native library
tomcat-servlet-3.0-api.noarch : Apache Tomcat Servlet API implementation classes
tomcat-webapps.noarch : The ROOT and examples web applications for Apache Tomcat
tomcatjss.noarch : JSS Connector for Apache Tomcat, a JSSE module for Apache Tomcat that uses JSS
tomcat.noarch : Apache Servlet/JSP Engine, RI for Servlet 3.0/JSP 2.2 API
tomcat-el-2.2-api.noarch : Expression Language v2.2 API

  Name and summary matches only, use "search all" for everything.

2.6、安装tomcat

[root@iZbp1izvhfvbrd0mb6ktasZ ~]# yum -y install tomcat

2.7、添加环境变量

[root@iZbp1izvhfvbrd0mb6ktasZ ~]# vi /etc/profile
export CATALINA_HOME=/usr/share/tomcat
export PATH=$PATH:$CATALINA_HOME/bin
[root@iZbp1izvhfvbrd0mb6ktasZ ~]# source /etc/profile

2.8、启动tomcat

[root@iZbp1izvhfvbrd0mb6ktasZ ~]# systemctl start tomcat
[root@iZbp1izvhfvbrd0mb6ktasZ ~]# systemctl status tomcat
● tomcat.service - Apache Tomcat Web Application Container
   Loaded: loaded (/usr/lib/systemd/system/tomcat.service; disabled; vendor preset: disabled)
   Active: active (running) since Sun 2024-08-18 17:39:31 CST; 8s ago
 Main PID: 12914 (java)
   CGroup: /system.slice/tomcat.service
           └─12914 /usr/lib/jvm/jre/bin/java -Djavax.sql.DataSource.Factory=org.apache.commons.dbcp.BasicDataSourceFactory -classpath /usr/share/tomcat/bin/bootstrap.jar:/usr/share/to...

Aug 18 17:39:32 iZbp1izvhfvbrd0mb6ktasZ server[12914]: Aug 18, 2024 5:39:32 PM org.apache.catalina.core.StandardService startInternal
Aug 18 17:39:32 iZbp1izvhfvbrd0mb6ktasZ server[12914]: INFO: Starting service Catalina
Aug 18 17:39:32 iZbp1izvhfvbrd0mb6ktasZ server[12914]: Aug 18, 2024 5:39:32 PM org.apache.catalina.core.StandardEngine startInternal
Aug 18 17:39:32 iZbp1izvhfvbrd0mb6ktasZ server[12914]: INFO: Starting Servlet Engine: Apache Tomcat/7.0.76
Aug 18 17:39:32 iZbp1izvhfvbrd0mb6ktasZ server[12914]: Aug 18, 2024 5:39:32 PM org.apache.coyote.AbstractProtocol start
Aug 18 17:39:32 iZbp1izvhfvbrd0mb6ktasZ server[12914]: INFO: Starting ProtocolHandler ["http-bio-8080"]
Aug 18 17:39:32 iZbp1izvhfvbrd0mb6ktasZ server[12914]: Aug 18, 2024 5:39:32 PM org.apache.coyote.AbstractProtocol start
Aug 18 17:39:32 iZbp1izvhfvbrd0mb6ktasZ server[12914]: INFO: Starting ProtocolHandler ["ajp-bio-8009"]
Aug 18 17:39:32 iZbp1izvhfvbrd0mb6ktasZ server[12914]: Aug 18, 2024 5:39:32 PM org.apache.catalina.startup.Catalina start
Aug 18 17:39:32 iZbp1izvhfvbrd0mb6ktasZ server[12914]: INFO: Server startup in 49 ms

2.9、安装Tomcat管理包

[root@iZbp1izvhfvbrd0mb6ktasZ ~]# yum install -y tomcat-webapps tomcat-admin-webapps

2.10、配置登录用户路径

[root@iZbp1izvhfvbrd0mb6ktasZ ~]# vi /usr/share/tomcat/conf/tomcat-users.xml