配置tomcat manager【Tomcat Manager用户配置详解】【Tomcat的Manager显示403 Access Denied】
2016-03-15 20:42
260 查看
Tomcat Manager是Tomcat自带的、用于对Tomcat自身以及部署在Tomcat上的应用进行管理的web应用。Tomcat是Java领域使用最广泛的服务器之一,因此Tomcat Manager也成为了使用非常普遍的功能应用。
在默认情况下,Tomcat Manager是处于禁用状态的。准确地说,Tomcat Manager需要以用户角色进行登录并授权才能使用相应的功能,不过Tomcat并没有配置任何默认的用户,因此需要我们进行相应的用户配置之后才能使用Tomcat Manager。
Tomcat Manager的用户配置是在
Tomcat Manager的用户配置非常简单,下面我们以一个具体的配置为例:
如上所示,我们只需要在
稍加思考,我们就应该猜测到,
以下是Tomcat Manager 4种角色的大致介绍(下面URL中的*为通配符):
manager-gui允许访问html接口(即URL路径为/manager/html/*)manager-script允许访问纯文本接口(即URL路径为/manager/text/*)manager-jmx允许访问JMX代理接口(即URL路径为/manager/jmxproxy/*)manager-status允许访问Tomcat只读状态页面(即URL路径为/manager/status/*)
从Tomcat Manager内部配置文件中可以得知,
==================================================================================================================
管理tomcat的时候遇到了以下问题:
1.刚开始需要用户名密码,不知道用户名和密码是什么,但是输入什么都不正确。
解决办法:
自己在tomcat-users.xml中按格式添加用户 conf文件夹里面
默认是注释掉了的,这主要是考虑到服务器的安全,如果是本地测试,去掉以下这段注释,然后重启动服务器,再输入
<role rolename="tomcat"/>
<role rolename="role1"/>
<user username="tomcat" password="tomcat" roles="tomcat"/>
<user username="both" password="tomcat" roles="tomcat,role1"/>
<user username="role1" password="tomcat" roles="role1"/>
用户和密码都一目了然了。
2.进入manager界面之后,显示的是403 Access Denied。
解决办法:
在conf/tomcat-users.xml文件中看到这么一段话:
NOTE: By default, no user is included in the "manager-gui" role required
to operate the "/manager/html" web application. If you wish to use this app,
you must define such a user - the username and password are arbitrary.
也就是说,为了考虑安全,tomcat默认还是没有manager-gui的管理权限的,如果想要使用manager
的话,需要自行加入管理权限(角色)。
需要加一个这样的权限(角色)
<role rolename="manager-gui"/>
然后再加到需要的用户名中去
<user username="tomcat" password="tomcat" roles="tomcat,manager-gui"/>
这样OK了。
===========================================代码如下===========================================================
<?xml version='1.0' encoding='utf-8'?>
<!--
Licensed to the Apache Software Foundation (ASF) under one or more
contributor license agreements. See the NOTICE file distributed with
this work for additional information regarding copyright ownership.
The ASF licenses this file to You under the Apache License, Version 2.0
(the "License"); you may not use this file except in compliance with
the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
-->
<tomcat-users>
<!--
NOTE: By default, no user is included in the "manager-gui" role required
to operate the "/manager/html" web application. If you wish to use this app,
you must define such a user - the username and password are arbitrary.
-->
<!--
NOTE: The sample user and role entries below are wrapped in a comment
and thus are ignored when reading this file. Do not forget to remove
<!.. ..> that surrounds them.
-->
<!--
<role rolename="tomcat"/>
<role rolename="role1"/>
<user username="tomcat" password="tomcat" roles="tomcat"/>
<user username="both" password="tomcat" roles="tomcat,role1"/>
<user username="role1" password="tomcat" roles="role1"/>
-->
<role rolename="tomcat"/>
<role rolename="role1"/>
<role rolename="manager-gui"/>
<user username="tomcat" password="tomcat" roles="tomcat"/>
<user username="both" password="tomcat" roles="tomcat,role1"/>
<user username="role1" password="tomcat" roles="role1"/>
<user username="tomcat" password="tomcat" roles="tomcat,manager-gui"/>
</tomcat-users>
在默认情况下,Tomcat Manager是处于禁用状态的。准确地说,Tomcat Manager需要以用户角色进行登录并授权才能使用相应的功能,不过Tomcat并没有配置任何默认的用户,因此需要我们进行相应的用户配置之后才能使用Tomcat Manager。
Tomcat Manager的用户配置是在
Tomcat安装目录/conf/tomcat-users.xml文件中进行管理的。
Tomcat Manager的用户配置非常简单,下面我们以一个具体的配置为例:
<tomcat-users> <role rolename="manager-gui"/> <role rolename="manager-script"/> <user username="tomcat" password="tomcat" roles="manager-gui"/> <user username="admin" password="123456" roles="manager-script"/> </tomcat-users>
如上所示,我们只需要在
tomcat-users节点中配置相应的
role(角色/权限)和
user(用户)即可。一个
user节点表示单个用户,属性
username和
password分别表示登录的用户名和密码,属性
roles表示该用户所具备的权限。
user节点的
roles属性值与
role节点的
rolename属性值相对应,表示当前用户具备该role节点所表示的角色权限。当然,一个用户可以具备多种权限,因此属性
roles的值可以是多个
rolename,多个
rolename之间以英文逗号隔开即可。
稍加思考,我们就应该猜测到,
rolename的属性值并不是随意的内容,否则Tomcat怎么能够知道我们随便定义的
rolename表示什么样的权限呢。实际上,Tomcat已经为我们定义了4种不同的角色——也就是4个
rolename,我们只需要使用Tomcat为我们定义的这几种角色就足够满足我们的工作需要了。
以下是Tomcat Manager 4种角色的大致介绍(下面URL中的*为通配符):
manager-gui允许访问html接口(即URL路径为/manager/html/*)manager-script允许访问纯文本接口(即URL路径为/manager/text/*)manager-jmx允许访问JMX代理接口(即URL路径为/manager/jmxproxy/*)manager-status允许访问Tomcat只读状态页面(即URL路径为/manager/status/*)
从Tomcat Manager内部配置文件中可以得知,
manager-gui、
manager-script、
manager-jmx均具备
manager-status的权限,也就是说,
manager-gui、
manager-script、
manager-jmx三种角色权限无需再额外添加
manager-status权限,即可直接访问路径/manager/status/*。
==================================================================================================================
管理tomcat的时候遇到了以下问题:
1.刚开始需要用户名密码,不知道用户名和密码是什么,但是输入什么都不正确。
解决办法:
自己在tomcat-users.xml中按格式添加用户 conf文件夹里面
默认是注释掉了的,这主要是考虑到服务器的安全,如果是本地测试,去掉以下这段注释,然后重启动服务器,再输入
<role rolename="tomcat"/>
<role rolename="role1"/>
<user username="tomcat" password="tomcat" roles="tomcat"/>
<user username="both" password="tomcat" roles="tomcat,role1"/>
<user username="role1" password="tomcat" roles="role1"/>
用户和密码都一目了然了。
2.进入manager界面之后,显示的是403 Access Denied。
解决办法:
在conf/tomcat-users.xml文件中看到这么一段话:
NOTE: By default, no user is included in the "manager-gui" role required
to operate the "/manager/html" web application. If you wish to use this app,
you must define such a user - the username and password are arbitrary.
也就是说,为了考虑安全,tomcat默认还是没有manager-gui的管理权限的,如果想要使用manager
的话,需要自行加入管理权限(角色)。
需要加一个这样的权限(角色)
<role rolename="manager-gui"/>
然后再加到需要的用户名中去
<user username="tomcat" password="tomcat" roles="tomcat,manager-gui"/>
这样OK了。
===========================================代码如下===========================================================
<?xml version='1.0' encoding='utf-8'?>
<!--
Licensed to the Apache Software Foundation (ASF) under one or more
contributor license agreements. See the NOTICE file distributed with
this work for additional information regarding copyright ownership.
The ASF licenses this file to You under the Apache License, Version 2.0
(the "License"); you may not use this file except in compliance with
the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
-->
<tomcat-users>
<!--
NOTE: By default, no user is included in the "manager-gui" role required
to operate the "/manager/html" web application. If you wish to use this app,
you must define such a user - the username and password are arbitrary.
-->
<!--
NOTE: The sample user and role entries below are wrapped in a comment
and thus are ignored when reading this file. Do not forget to remove
<!.. ..> that surrounds them.
-->
<!--
<role rolename="tomcat"/>
<role rolename="role1"/>
<user username="tomcat" password="tomcat" roles="tomcat"/>
<user username="both" password="tomcat" roles="tomcat,role1"/>
<user username="role1" password="tomcat" roles="role1"/>
-->
<role rolename="tomcat"/>
<role rolename="role1"/>
<role rolename="manager-gui"/>
<user username="tomcat" password="tomcat" roles="tomcat"/>
<user username="both" password="tomcat" roles="tomcat,role1"/>
<user username="role1" password="tomcat" roles="role1"/>
<user username="tomcat" password="tomcat" roles="tomcat,manager-gui"/>
</tomcat-users>
相关文章推荐
- Nginx + Tomcat 动静分离实现负载均衡(转)
- Linux 安装jdk、tomcat,maven
- Tomcat源码解析(五):Connector连接器的初始化和启动流程
- mac下安装tomcat
- Linux下启动启动tomcat 服务器报错 The file is absent or does not have execute permission
- MyEclipse下Tomcat启动变慢 解决方法
- Tomcat虚拟目录配置
- Tomcat实现Session对象的持久化原理及配置方法介绍
- maven tomcat7:deploy
- java与tomcat类加载机制
- tomcat log 配置解决catalina.out文件过大问题
- tomcat catalina.out 日志分割
- tomcat虚拟目录配置方法
- Tomcat启动报Error listenerStart错误
- 动静分离—Nginx+Tomcat
- MyEclipse2014 怎么将项目部署在tomcat的ROOT目录下
- 为tomcat指定JDK
- MyEclipse 启动 Tomcat 配置容器内存分配
- Windows下的修改Tomcat的可用内存
- Tomcat 输出日志文件 catalina.out 大小控制