maven-tomcat 插件部署在远程服务器上

maven-tomcat plugin deploy on Remote server

我想在远程服务器上使用 maven 部署我的应用程序,以便拥有一个持续集成系统:)。

我在 Whosebug 上检查了很多问题,但无法使其正常工作。首先我会告诉你我的错误,然后是我所做的配置。 这里是关于上传的消息,它似乎是正确的: Uploaded: http://SERVEUR_IP/manager/text/deploy?path=%2FGiveMeAShow (49631 KB at 51.5 KB/sec)

错误:

[ERROR] Failed to execute goal org.apache.tomcat.maven:tomcat7-maven-plugin:2.2:deploy (default-cli) on project GiveMeAShow: Tomcat return http status error: 401, Reason Phrase: Unauthorized:
[ERROR] <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
[ERROR] <html>
[ERROR] <head>
[ERROR] <title>401 Unauthorized</title>
[ERROR] <style type="text/css">
[ERROR] <!--
[ERROR] BODY {font-family:Tahoma,Arial,sans-serif;color:black;background-color:white;font-size:12px;}
[ERROR] H1 {font-family:Tahoma,Arial,sans-serif;color:white;background-color:#525D76;font-size:22px;}
[ERROR] PRE, TT {border: 1px dotted #525D76}
[ERROR] A {color : black;}A.name {color : black;}
[ERROR] -->
[ERROR] </style>
[ERROR] </head>
[ERROR] <body>
[ERROR] <h1>401 Unauthorized</h1>
[ERROR] <p>
[ERROR] You are not authorized to view this page. If you have not changed
[ERROR] any configuration files, please examine the file
[ERROR] <tt>conf/tomcat-users.xml</tt> in your installation. That
[ERROR] file must contain the credentials to let you use this webapp.
[ERROR] </p>
[ERROR] <p>
[ERROR] For example, to add the <tt>manager-gui</tt> role to a user named
[ERROR] <tt>tomcat</tt> with a password of <tt>s3cret</tt>, add the following to the
[ERROR] config file listed above.
[ERROR] </p>
[ERROR] <pre>
[ERROR] &lt;role rolename="manager-gui"/&gt;
[ERROR] &lt;user username="tomcat" password="s3cret" roles="manager-gui"/&gt;
[ERROR] </pre>
[ERROR] <p>
[ERROR] Note that for Tomcat 7 onwards, the roles required to use the manager
[ERROR] application were changed from the single <tt>manager</tt> role to the
[ERROR] following four roles. You will need to assign the role(s) required for
[ERROR] the functionality you wish to access.
[ERROR] </p>
[ERROR] <ul>
[ERROR] <li><tt>manager-gui</tt> - allows access to the HTML GUI and the status
[ERROR] pages</li>
[ERROR] <li><tt>manager-script</tt> - allows access to the text interface and the
[ERROR] status pages</li>
[ERROR] <li><tt>manager-jmx</tt> - allows access to the JMX proxy and the status
[ERROR] pages</li>
[ERROR] <li><tt>manager-status</tt> - allows access to the status pages only</li>
[ERROR] </ul>
[ERROR] <p>
[ERROR] The HTML interface is protected against CSRF but the text and JMX interfaces
[ERROR] are not. To maintain the CSRF protection:
[ERROR] </p>
[ERROR] <ul>
[ERROR] <li>Users with the <tt>manager-gui</tt> role should not be granted either
[ERROR] the <tt>manager-script</tt> or <tt>manager-jmx</tt> roles.</li>
[ERROR] <li>If the text or jmx interfaces are accessed through a browser (e.g. for
[ERROR] testing since these interfaces are intended for tools not humans) then
[ERROR] the browser must be closed afterwards to terminate the session.</li>
[ERROR] </ul>
[ERROR] <p>
[ERROR] For more information - please see the
[ERROR] <a href="/docs/manager-howto.html">Manager App HOW-TO</a>.
[ERROR] </p>
[ERROR] </body>
[ERROR]
[ERROR] </html>
[ERROR] -> [Help 1]
[ERROR]
[ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.
[ERROR] Re-run Maven using the -X switch to enable full debug logging.
[ERROR]
[ERROR] For more information about the errors and possible solutions, please read the following articles:
[ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/MojoExecutionException

看起来很清楚,这是一个授权问题。让我们看看我的远程 tomcat7 tomcat-users.xml 文件 :

<?xml version='1.0' encoding='utf-8'?>
<tomcat-users>
        <role rolename="manager-gui"/>
        <role rolename="admin-gui"/>
        <role rolename="manager-script"/>
        <role rolename="admin-script"/>
        <user username="admin" password="password" roles="manager-gui,manager-script,admin-gui,admin-script" />
</tomcat-users>

我知道我不应该授予所有角色,但是嘿它不起作用所以我正在尝试:)。

我可以在我的浏览器中使用 "admin" 和 "password" 通过 HTTP 登录应用程序 manager/admin 页面。这个我觉得还行。

这是我在 maven-tomcat-plugin 中的配置:

<plugin>
    <groupId>org.apache.tomcat.maven</groupId>
    <artifactId>tomcat7-maven-plugin</artifactId>
    <version>2.2</version>
    <configuration>
        <usernamee>admin</usernamee>
        <password>password</password>
        <url>http:SERVEUR_IP/manager/text</url>
        <server>TomcatServer</server>
        <path>/GiveMeAShow</path>
    </configuration>
</plugin>

当我开始尝试时,我无法上传 war 文件。添加这个允许我这样做。不过授权问题好像是后面来的。

我还在 ~/.m2/settings.xml 的远程服务器中放置了一个 settings.xml 文件:

<?xml version='1.0' encoding='utf-8'?>
<servers>
        <server>
                <id>TomcatServer</id>
                <username>admin</username>
                <password>password</password>
        </server>
</servers>

~/.m2文件夹只有一个子文件夹和我创建的这个文件。

请注意,我正在使用 root 用户执行所有这些操作。

我现在不知道该试试什么,谢谢你的帮助!

编辑

我确实喜欢@fatteddy 说的: - 创建了一个仅限部署的用户。只有角色 "manager-script" - 更正了我在 pom.xml 中的错误,将 <usernamee> 更改为 </username>

我认为创建一个仅限部署的用户完成了大部分工作,因为我同时在 TRAVIS-CI 上进行了测试,并且 <username> 标签中的 env 变量写入没有错误。

实际上这是一个身份验证问题。 尝试定义(显然出于安全原因)分配了 manager-script(仅此)角色的单独部署用户。不要忘记重启 tomcat.

如果这不能帮助更改 tomcat 管理器 URL 的路径段(manager/managermanager/textmanager/text/ -> 据我所知,are/or 尾部斜杠存在问题,已在后来的 tomcat 版本中修复)

我忘记做的最简单的事情是 - 在设置更改后重新启动 Tomcat。这句话 - "Don't forget to restart tomcat" 帮了大忙! :)