publish the project to a remote tomcat maven

A. Configure the manager tomcat

conf / tomcat-users.xml in edit remote tomcat server, at the end of the increase (in fact, as long as the pull end of the file, change it uncommented on it)

<role rolename="manager-gui"/>
<role rolename="manager-script"/>
<user username="admin" password="password" roles="manager-script"/>
<user username="root" password="password" roles="manager-gui"/>

The above password change your password, pay attention to tomcat9, it can not give users the manager-script and manager-gui role at the same time.
Save tomcat-users.xml.
Manager.xml create a file in the conf tomcat server / Catalina / localhost / directory, write the following values:

<?xml version="1.0" encoding="UTF-8"?>
<Context privileged="true" antiResourceLocking="false" docBase="${catalina.home}/webapps/manager">
      <Valve className="org.apache.catalina.valves.RemoteAddrValve" allow="^.*$" />
</Context>

Enter in your browser http: // serverip: port / manager / html, will pop asked to enter a user name and password dialog, input manager-gui corresponding user and password management console (which serverip server ip, if in the local server is localhost or 127.0.0.1, port tomcat port, default 8080). In order to confirm whether the manager configured correctly. Example correct result as follows:

Two in maven add a configuration item

In pom.xml file, add the following plugin node under the node plugins

    <groupId>org.apache.tomcat.maven</groupId>
    <artifactId>tomcat7-maven-plugin</artifactId>
    <version>2.2</version>

    <configuration>
        <url>http://serverip:port/manager/text</url>
        <username>admin</username>
        <password>password</password>
        <update>true</update>
        <path>/webapp</path>
    </configuration>
</plugin>

serverip remote tomcat address, port to port, username is the user name above configuration, password is the password

And then deployed, if the deployment is the first time, run mvn tomcat7: deploy automated deployment (for tomcat8,9, also use tomcat7 command),
if redeployment is to update the code update, run mvn tomcat7: redeploy, if the first deployments using mvn tomcat7: redeploy, war will only execute upload file server does not automatically unzip deployment.
If the path already exists in the tomcat server and using mvn tomcat7: deploy command, then the above configuration, the configuration must be true, or will be error.

Three memory leak

It would be a serious memory leak after deployment using the above method. tomcat manager provides a diagnostic of whether a memory leak in the deployment of the function, in the above-mentioned http: There is a "Find leaks" button port / manager / html bottom of this page,: // serverip

Click the button, the following message appears on the page header illustrate a memory leak when deployed

The above message is displayed memory leak test project deployment, redeployment if the same item multiple times, then a project name may appear more than once.
It causes a memory leak when the deployment is every (re) deployment time, Tomcat will create a new class loader for the project, and the old class loader has not been recovered GC. maven library classloader-leak-prevention-servlet can be used to solve this problem

Solving steps

(1) adding maven dependency:

<dependency>
  <groupId>se.jiderhamn.classloader-leak-prevention</groupId>
  <artifactId>classloader-leak-prevention-servlet</artifactId>
  <version>2.1.0</version>
</dependency>


(2)在项目的web.xml中添加一个Listener(必须让此Listener成为web.xml中的第一个Listener,否则不起作用)

<listener>
<listener-class>se.jiderhamn.classloader.leak.prevention.ClassLoaderLeakPreventorListener</listener-class></listener>


这样部署时的内存泄漏就解决了。

注意:

1) 添加这个Listener后,默认在tomcat关闭5s后jvm会进行内存回收的操作,具体时间设置可在下面的第三个参考链接中找到,所以,在关闭后的5s内,再次启动tomcat,可能会存在问题,导致启动无效(如果出现tomcat重启后日志显示正常但是服务器不工作的话考虑一下是不是这个问题)。

2)这个Listener只解决部署的内存泄漏,其他问题(如jdbc等)产生的内存泄漏还需要自己解决。


Guess you like

Origin blog.51cto.com/14579491/2458964