赞
踩
升级tomcat7至tomcat8.5,使用jenkins构建应用并发布时,出现了错误,具体是将war发布到tomcat时,报:403/401 for URL: http://192.168.64.100:8080/manager/text/list
处理:
1、修改tomcat/conf/tomcat-users.xml,配置tomcat用户,启用“manager-script”角色;
2、修改tomcat/webapps/manager/META-INF/context.xml,注释掉“
Valve className=”org.apache.catalina.valves.RemoteAddrValve”
allow=”127.\d+.\d+.\d+|::1|0:0:0:0:0:0:0:1” /> ”;
3、修改jenkins配置,指定tomcat管理用户、密码,重新构建即可成功。
思路来源于以下三篇文章,均属转载,备忘:
转载自:http://blog.csdn.net/houyefeng/article/details/50996198
本文是jenkins应用系统文章的一部分,大部分来自工作和学习中的实践,部分内容来自官方文档和网友的文章,引用的文章会在“参考资料”部分附上原始链接,如无意中侵犯您的权利,请联系QQ:46106962,如需要进一步的交流请加入QQ群: (Jenkins学习交流)469536515。转载和使用请注明出处。
WAR/EAR files相对于工作空间的相对路径,也可以写“Ant-style GLOBs”表达式,如:**/*.war,“Ant-style GLOBs”暂时还没有弄明白是什么,经测试可以按如下形式写:source/target/*.war或source/target/yiqifa-adcenter-web.war,建议以“**/*.war”形式填写。如本文中使用的Jenkins的工作空间为/data/jenkins,job名称为hyf-test-deploy-plugin,则这里的路径是相对/data/jenkins/hyf-test-deploy-plugin的(其中source是在job中指定的源码存放目录,视设置确定需不需要加上这个目录)
如果所有配置都正确,在Jenkins的控制台会看到如下图的提示:
其中“hyf-test-deploy-plugin”为Jenkins的job名称。Context Path应用在Tomcat中的部署路径,如上图,部署后可以通过http://172.16.18.192:8080/hyftest来访问部署的应用Manager user name/ Manager password在“修改Tomcat管理用户配置”中配置好的用户名和密码Tomcat Url
运程Tomcat的访问路径,如上图中的http://172.16.18.192:8080,插件通过这个地址将应用的war/ear包上传到Tomcat的webapps目录下Add Container在这里可以继续增加其他的容器,这样就可以实现将应用同时部署到不同的容器中。
转载自:http://blog.csdn.net/big_bigwolf/article/details/50899715
配置tomcat manager【Tomcat Manager用户配置详解】【Tomcat的Manager显示403 Access Denied】
Tomcat Manager是Tomcat自带的、用于对Tomcat自身以及部署在Tomcat上的应用进行管理的web应用。Tomcat是Java领域使用最广泛的服务器之一,因此Tomcat Manager也成为了使用非常普遍的功能应用。
在默认情况下,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中的*为通配符):
从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>
转载自:http://blog.csdn.net/u012167045/article/details/61624226
403 Access Denied
You are not authorized to view this page.
If you have already configured the Manager application to allow access and you have used your browsers back button, used a saved book-mark or similar then you may have triggered the cross-site request forgery (CSRF) protection that has been enabled for the HTML interface of the Manager application. You will need to reset this protection by returning to the main Manager page. Once you return to this page, you will be able to continue using the Manager appliction’s HTML interface normally. If you continue to see this access denied message, check that you have the necessary permissions to access this application.
If you have not changed any configuration files, please examine the file conf/tomcat-users.xml in your installation. That file must contain the credentials to let you use this webapp.
For example, to add the manager-gui role to a user named tomcat with a password of s3cret, add the following to the config file listed above.
Note that for Tomcat 7 onwards, the roles required to use the manager application were changed from the single manager role to the following four roles. You will need to assign the role(s) required for the functionality you wish to access.
manager-gui - allows access to the HTML GUI and the status pages
manager-script - allows access to the text interface and the status pages
manager-jmx - allows access to the JMX proxy and the status pages
manager-status - allows access to the status pages only
The HTML interface is protected against CSRF but the text and JMX interfaces are not. To maintain the CSRF protection:
Users with the manager-gui role should not be granted either the manager-script or manager-jmx roles.
If the text or jmx interfaces are accessed through a browser (e.g. for testing since these interfaces are intended for tools not humans) then the browser must be closed afterwards to terminate the session.
一般遇到此问题的解决方案是:
vi /usr/local/tomcat/apache-tomcat-8.5.9/conf/tomcat-users.xml
在此文件中添加用户和角色:
但是tomcat8.5 更改之后,仍然访问拒绝。
还需步骤如下:
vi /usr/local/tomcat/apache-tomcat-8.5.9/webapps/manager/META-INF/context.xml
备注:本人开始加上自己本机的ip地址,仍然访问不了。看到有帖子说明可以将
Valve className=”org.apache.catalina.valves.RemoteAddrValve”
allow=”127.\d+.\d+.\d+|::1|0:0:0:0:0:0:0:1” /> 注解掉。
之后再访问http://192.168.5.106:8080/
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。