linux安装Tomcat

1、官网链接:https://tomcat.apache.org/download-80.cgi
自行选择需要的包
linux安装Tomcat_第1张图片
tomcat、jdk兼容性对照表
linux安装Tomcat_第2张图片

安装

#上传文件至服务器
rz
#解压
tar -zxvf apache-tomcat-9.0.76
#配置系统变量
vim /ect/profile
#添加变量
export TOMCAT_HOME=/root/tools/tomcat/apache-tomcat-9.0.76
#使文件生效
source /etc/profile

浏览器进入 http://ip:8080
但发现无法进入,解决方案如下:
1、使用服务器的话,需要在服务器上增加8080端口
linux安装Tomcat_第3张图片
2、在firewalld 上开放8080端口
输入命令:firewall-cmd --zone=public --add-port=8080/tcp --permanent
3、重启防火墙
输入命令:firewall-cmd --reload
4、打开外部浏览器,输入http://IP:8080
linux安装Tomcat_第4张图片
其他防火墙相关命令:

查看防火墙状态: systemctl status firewalld 或者 systemctl is-active firewalld
启动防火墙: systemctl start firewalld
停止防火墙: systemctl stop firewalld
永久停用: systemctl disable firewalld
启用防火墙: systemctl enable firewalld

一台服务器上部署多个tomcat,需要在配置中增加对应的端口

进入tomcat/conf
输入命令:vim server.xml

#server.xml

    
<?xml version="1.0" encoding="UTF-8"?>

<Server port="8005" shutdown="SHUTDOWN">
  <Listener className="org.apache.catalina.startup.VersionLoggerListener" />

  <Listener className="org.apache.catalina.core.AprLifecycleListener" SSLEngine="on" />
  <Listener className="org.apache.catalina.core.JreMemoryLeakPreventionListener" />
  <Listener className="org.apache.catalina.mbeans.GlobalResourcesLifecycleListener" />
  <Listener className="org.apache.catalina.core.ThreadLocalLeakPreventionListener" />

  <GlobalNamingResources>
    <Resource name="UserDatabase" auth="Container"
              type="org.apache.catalina.UserDatabase"
              description="User database that can be updated and saved"
              factory="org.apache.catalina.users.MemoryUserDatabaseFactory"
              pathname="conf/tomcat-users.xml" />
  </GlobalNamingResources>

  <Service name="Catalina">

    <Connector port="8080" protocol="HTTP/1.1"
               connectionTimeout="20000"
               redirectPort="8443" />
    <Engine name="Catalina" defaultHost="localhost">
      <Realm className="org.apache.catalina.realm.LockOutRealm">
        <Realm className="org.apache.catalina.realm.UserDatabaseRealm"
               resourceName="UserDatabase"/>
      </Realm>

      <Host name="localhost"  appBase="webapps"
            unpackWARs="true" autoDeploy="true">
        <Valve className="org.apache.catalina.valves.AccessLogValve" directory="logs"
               prefix="localhost_access_log" suffix=".txt"
               pattern="%h %l %u %t "%r" %s %b" />
      </Host>
    </Engine>
  </Service>

    
#新加的端口配置,复制以后修改port参数就行
   <Service name="Catalina1">
    <Connector port="8081" protocol="HTTP/1.1"
               connectionTimeout="20000"
               redirectPort="8443" />
    <Engine name="Catalina1" defaultHost="localhost">
      <Realm className="org.apache.catalina.realm.LockOutRealm">
        <Realm className="org.apache.catalina.realm.UserDatabaseRealm"
               resourceName="UserDatabase"/>
      </Realm>

      <Host name="localhost"  appBase="webapps1"
            unpackWARs="true" autoDeploy="true">
        <Valve className="org.apache.catalina.valves.AccessLogValve" directory="logs"
               prefix="localhost_access_log" suffix=".txt"
               pattern="%h %l %u %t "%r" %s %b" />
      </Host>
    </Engine>
  </Service>
</Server>

你可能感兴趣的:(linux,linux,tomcat,运维)