CentOS 安装tomcat

1、确保JDK已经安装,版本在1.8以上

2、到网管下载安装

wget http://mirrors.tuna.tsinghua.edu.cn/apache/tomcat/tomcat-9/v9.0.14/bin/apache-tomcat-9.0.14.tar.gz

tar -xzvf apache-tomcat-9.0.14.tar.gz

3、查看tomcat配置

[[email protected] bin]# ./catalina.sh version
Using CATALINA_BASE:   /opt/apache-tomcat-9.0.14
Using CATALINA_HOME:   /opt/apache-tomcat-9.0.14
Using CATALINA_TMPDIR: /opt/apache-tomcat-9.0.14/temp
Using JRE_HOME:        /home/java/jdk1.8.0_172/jre
Using CLAsspATH:       /opt/apache-tomcat-9.0.14/bin/bootstrap.jar:/opt/apache-tomcat-9.0.14/bin/tomcat-juli.jar
Server version: Apache Tomcat/9.0.14
Server built:   Dec 6 2018 21:13:53 UTC
Server number:  9.0.14.0
OS Name:        Linux
OS Version:     3.10.0-693.el7.x86_64
Architecture:   amd64
JVM Version:    1.8.0_172-b11
JVM vendor:     Oracle Corporation

4、配置端口,开通防火墙端口

#可以选择修改认的8080端口
[[email protected]-senior01 apache-tomcat-9.0.14]# vi conf/server.xml 

    <Connector port="8080" protocol="HTTP/1.1"
               connectionTimeout="20000"
               redirectPort="8443" />
    <!-- A "Connector" using the shared thread pool-->
    <!--
    <Connector executor="tomcatThreadPool"
               port="8080" protocol="HTTP/1.1"
               connectionTimeout="20000"
               redirectPort="8443" />
    -->


打开防火墙
[[email protected]-senior01 bin]# firewall-cmd --add-port=8080/tcp --permanent
success
[[email protected]-senior01 bin]# firewall-cmd --reload
success

5、配置管理用户

[[email protected] apache-tomcat-9.0.14]# vi conf/tomcat-users.xml 

#加入管理用户
  <role rolename="manager-gui"/>
  <user username="admin" password="123456" roles="manager-gui"/>
#修改管理页面的ip访问许可
[[email protected]-senior01 apache-tomcat-9.0.14]# vi  webapps/manager/meta-inf/context.xml 

<Context antiResourceLocking="false" privileged="true" >
  <Valve className="org.apache.catalina.valves.RemoteAddrValve"
         allow="192\.\d+\.\d+\.\d+|::1|0:0:0:0:0:0:0:1" />   #原本是127,即只允许本机访问
  <Manager sessionAttributeValueClassNameFilter="java\.lang\.(?:Boolean|Integer|Long|Number|String)|org\.apache\.catalina\.filters\.CsrfPreventionFilter\$LruCache(?:\$1)?|java\.util\.(?:Linked)?HashMap"/>
</Context>

6、测试tomcat

分享图片

分享图片

7、发布webapp

将war包或者整个webapp放入tomcat的webapps目录下即可访问,但是要跟上目录名,如果需要在ip或者域名后面直接访问,需要配置conf目录下的server.xml
[[email protected] apache-tomcat-9.0.14]# vi conf/server.xml 
... ...
      <Host name="localhost"  appBase=""
            unpackWARs="true" autoDeploy="true">

      <Context path="" docBase="/opt/apache-tomcat-9.0.14/webapps/bus" debug="0" privileged="true" />

相关文章

Centos下搭建性能监控Spotlight
CentOS 6.3下Strongswan搭建IPSec VPN
在CentOS6.5上安装Skype与QQ
阿里云基于centos6.5主机VPN配置
CentOS 6.3下配置multipah
CentOS安装、配置APR和tomcat-native