linux安装Tomcat

1、官网链接:https://tomcat.apache.org/download-80.cgi
自行选择需要的包
image.png
tomcat、jdk兼容性对照表
image.png

安装

#上传文件至服务器
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端口
image.png
2、在firewalld 上开放8080端口
输入命令:firewall-cmd --zone=public --add-port=8080/tcp --permanent
3、重启防火墙
输入命令:firewall-cmd --reload
4、打开外部浏览器,输入http://IP:8080
image.png
其他防火墙相关命令:

查看防火墙状态: 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 &quot;%r&quot; %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 &quot;%r&quot; %s %b" />
      </Host>
    </Engine>
  </Service>
</Server>

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值