Jenkins发布报错:403/401 for URL: http://192.168.64.100:8080/manager/text/list

升级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——应用篇——插件使用——Deploy to container Plugin

本文是jenkins应用系统文章的一部分,大部分来自工作和学习中的实践,部分内容来自官方文档和网友的文章,引用的文章会在“参考资料”部分附上原始链接,如无意中侵犯您的权利,请联系QQ:46106962,如需要进一步的交流请加入QQ群: (Jenkins学习交流)469536515。转载和使用请注明出处。

依赖环境

JDK
Tomcat

插件安装

在jenkins“系统管理”的“管理插件”中安装“Deploy to container Plugin”

在运程机上安装Tomcat

本文是通过Deploy to container Plugin插件将应用发布到tomcat下,使用的是tomcat 7.0.63,我使用的是绿色免安装版,如果使用其他方式安装请自行查找资料。

修改Tomcat管理用户配置

Deploy to container Plugin需要通过属于manager-script组的Tomcat管理用户将war包发布到Tomcat服务器上,默认没有这样的用户,需要在TOMCAT_HOME/conf/tomcat-users.xml添加manager-script组和相应的用户,增加如下两行:
<role rolename="manager-script"/>
<user username="deploy" password="deploy123456" roles="manager-script"/>
注:配置好后需要重启Tomcat才能生效

在Jenkins中配置Job

在“构建后操作”中增加“Deploy war/ear to container”,配置如下图:
Deploy to container Plugin配置

参数说明

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的控制台会看到如下图的提示:
deploy的输出
其中“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
在这里可以继续增加其他的容器,这样就可以实现将应用同时部署到不同的容器中。

注意事项

  1. 运行Job进行部署前要先启动运程机上的WEB容器,插件需要通过容器提供的接口将war包发布到容器下
  2. 如果遇到“Deployed application at context path /xxx but context failed to start”这样的异常请到远程机的WEB容器下查看日志
  3. 如果遇到“Connection refused”的异常请检查远程机的容器是否启动、端口是否设置正常,不同的容器配置方式不一样,请参考相应容器的配置文档
  4. 如果遇到“403/401 for URL: http://172.16.18.192:8090/manager/text/list”,请检查远程机上是否存在Job中的Manager user name处添加的用户以及权限和密码设置是否正确

问题汇总

  1. 部署后Tomcat崩溃问题
    这个问题是由于Tomcat检测到webapps下应用的WEB-INF/lib、WEB-INF/classes或war有变化自动部署应用引起的,最常见的就是内存溢出问题,因为不在生产环境使用Tomcat所以没深究,有知道的同学请补充。


转载自: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节点表示单个用户,属性usernamepassword分别表示登录的用户名和密码,属性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-guimanager-scriptmanager-jmx均具备manager-status的权限,也就是说,manager-guimanager-scriptmanager-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

Tomcat8访问管理页面localhost出现:403 Access Denied


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/ 
这里写图片描述