通过 maven实现部署war包到远程Tomcat服务器
step 1:
首先配置 远程tomcat远程服务器:
1.1 修改 conf/tomcat-user.xml文件 ,修改内容如下:
1.2 在tomcat的Manager和Host-Manager只接受本机的请求,而要让它接受远程的请求,需要添加上面提到的manager.xml的配置,在“conf/Catalina/localhost/目录下”创建 一个manager.xml文件 ,写入如下值后,tomcat服务器到此已经配置完成 :
<?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>
step 2:
2.1:在你要部署的项目的pom.xml内添加如下值:
<plugin> <groupId>org.apache.tomcat.maven</groupId> <artifactId>tomcat7-maven-plugin</artifactId> <version>2.1</version> <configuration> <url>http://172.16.2.234:8888/manager/text</url> <!-- 配置远程tomcat的路劲 --> <!--本地服务的端口--> <port>8080</port> <username>tomcat</username> <password>123456</password> <update>true</update> <path>/${project.artifactId}</path> </configuration> </plugin>
2.2 在maven:plugin-tomcat-deploy执行指令后 看到一下日志时,说明远程部署成功:
[INFO] Deploying war to http://172.16.2.234:8888/spring-base
Uploading: http://172.16.2.234:8888/manager/text/deploy?path=%2Fspring-base&update=true
30920/48802 KB Uploaded: http://172.16.2.234:8888/manager/text/deploy?path=%2Fspring-base&update=true (48802 KB at 16816.4 KB/sec)
[INFO] tomcatManager status code:200, ReasonPhrase:OK
[INFO] OK - Deployed application at context path /spring-base
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 24.522s
[INFO] Finished at: Mon Mar 26 15:13:21 CST 2018
[INFO] Final Memory: 29M/221M
[INFO] ------------------------------------------------------------------------
2.3 重启tomcat 服务器就可以访问自己部署过的项目了!!!
4. 如果在Linux 多Tomcat运行环境下 如何远程部署?
答案是:只需要改下:conf/catalina.sh 文件内:
CATALINA_HOME=/home/solr/webserver/XX
CATALINA_BASE =/home/solr/webserver/XX
即可。