应用部署实现基于WEB的管理
打开浏览器可以访问tomcat管理的默认管理页面,点击下图按钮都会出现下面提示403的错误提示


默认的管理页面被禁用,启用方法如下
- 修改conf/conf/tomcat-users.xml
[root@centos8 tomcat]#ls conf/
Catalina             context.xml           logging.properties  tomcat-users.xml
catalina.policy      jaspic-providers.xml  server.xml          tomcat-users.xsd
catalina.properties  jaspic-providers.xsd  tomcat.conf         web.xml
#查看配置信息
[root@centos8 tomcat]#cat conf/server.xml 
<GlobalNamingResources>
    <!-- Editable user database that can also be used by
         UserDatabaseRealm to authenticate users
    -->
    <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>用户认证,配置文件是conf/tomcat-users.xml。打开tomcat-users.xml,我们需要一个角色manager-gui。
[root@centos8 tomcat]#vim conf/tomcat-users.xml 
<tomcat-users xmlns="http://tomcat.apache.org/xml"
              xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
              xsi:schemaLocation="http://tomcat.apache.org/xml tomcat-users.xsd"
              version="1.0">
#加下面两行,指定用户和密码
  <role rolename="manager-gui"/>
  <user username="admin" password="123456" roles="manager-gui"/>
</tomcat-users>
[root@centos8 tomcat]#systemctl restart tomcat
- 修改webapps/manager/META-INF/context.xml
<?xml version="1.0" encoding="UTF-8"?>
<Context antiResourceLocking="false" privileged="true" >
  <Valve className="org.apache.catalina.valves.RemoteAddrValve"
         allow="127\.\d+\.\d+\.\d+|::1|0:0:0:0:0:0:0:1" />
  <Manager sessionAttributeValueClassNameFilter="java\.lang\.(?:Boolean|Integer|Long|Number|String)|org\.apache\.catalina\.filters\.CsrfPreventionFilter\$LruCache(?:\$1)?|java\.util\.(?:Linked)?HashMap"/>
</Context>看正则表达式就知道是本地访问了,由于当前访问地址是192.168.x.x,可以修改正则为
allow="127\.\d+\.\d+\.\d+|::1|0:0:0:0:0:0:0:1|192\.168\.\d+\.\d+"范例:
[root@centos8 tomcat]#vim webapps/manager/META-INF/context.xml
<Context antiResourceLocking="false" privileged="true" >
  <Valve className="org.apache.catalina.valves.RemoteAddrValve"
         allow="127\.\d+\.\d+\.\d+|::1|0:0:0:0:0:0:0:1|10\.0\.0\.\d+" />
  <Manager sessionAttributeValueClassNameFilter="java\.lang\.(?:Boolean|Integer|Long|Number|String)|org\.apach
e\.catalina\.filters\.CsrfPreventionFilter\$LruCache(?:\$1)?|java\.util\.(?:Linked)?HashMap"/>
</Context> - 再次通过浏览器访问,可以看到以下管理界面,输入前面的用户和密码进行登录


Web 应用程序管理界面可以实现以下功能
Applications 应用程序管理,可以启动、停止、重加载、反部署、清理过期session
Deploy 可以热部署,也可以部署war文件。

本文链接:https://www.yunweipai.com/35139.html


 
        

网友评论comments