Tomcat热部署

以前我们都是打成war,然后放到tomcat服务器的webapps下,然后重启tomcat,但是大型的电商项目这样会很不方便,如果要在100台服务器上配置,那还不要去见西天啊。。。

1.Tomcat热部署

1.可以使用maven实现tomcat热部署。Tomcat启动时 部署工程。Tomcat有个后台管理功能,可以实现工程热部署。


2.配置用户名和密码:


第一步:需要修改tomcatconf/tomcat-users.xml配置文件。添加用户名、密码、权限。

<role rolename="manager-gui" />

<role rolename="manager-script" />

<user username="tomcat" password="tomcat" roles="manager-gui, manager-script"/>

第二步:重新启动tomcat





但是这还是存在问题,如果我们服务器多的话,那需要一个一个上传,也需要很多时间,所以这里我们使用maven的tomcat插件实现热部署:

我接下来演示一个:


第一步:配置tomcat插件,需要修改工程的pom文件。

<!-- 配置tomcat插件 -->
<build>
	<plugins>
		<plugin>
			<groupId>org.apache.tomcat.maven</groupId>
			<artifactId>tomcat7-maven-plugin</artifactId>
			<configuration>
				<path>/</path>  <!-- 放在ROOT目录下 -->
				<port>8080</port>
				<url>http://tomcatip:8080/manager/text</url>
				<username>tomcat</username>
				<password>tomcat</password>
			</configuration>
		</plugin>
		<plugin>
			<groupId>org.apache.maven.plugins</groupId>
			<artifactId>maven-surefire-plugin</artifactId>
			<version>2.5</version>
			<configuration>
			 <skipTests>true</skipTests>
			</configuration>
		</plugin>
	</plugins>
</build>

第二步:使用maven命令进行部署。

tomcat7:deploy 第一次部署

tomcat7:redeploy

部署的路径是/”会把系统部署到webapps/ROOT目录下。

部署工程跳过测试:
clean tomcat7:redeploy -DskipTests


[INFO] Scanning for projects...
[INFO] ------------------------------------------------------------------------
[INFO] Reactor Build Order:
[INFO] 
[INFO] e3-manager
[INFO] e3-manager-pojo
[INFO] e3-manager-dao
[INFO] e3-manager-interface
[INFO] e3-manager-service
[INFO]                                                                         
[INFO] ------------------------------------------------------------------------
[INFO] Building e3-manager 0.0.1-SNAPSHOT
[INFO] ------------------------------------------------------------------------
[INFO] 
[INFO] --- maven-clean-plugin:2.5:clean (default-clean) @ e3-manager ---
[INFO] 
[INFO] >>> tomcat7-maven-plugin:2.2:redeploy (default-cli) > package @ e3-manager >>>
[INFO] 
[INFO] <<< tomcat7-maven-plugin:2.2:redeploy (default-cli) < package @ e3-manager <<<
[INFO] 
[INFO] --- tomcat7-maven-plugin:2.2:redeploy (default-cli) @ e3-manager ---
[INFO] Skipping non-war project
[INFO]                                                                         
[INFO] ------------------------------------------------------------------------
[INFO] Building e3-manager-pojo 0.0.1-SNAPSHOT
[INFO] ------------------------------------------------------------------------
[INFO] 
[INFO] --- maven-clean-plugin:2.5:clean (default-clean) @ e3-manager-pojo ---
[INFO] Deleting E:\eclipse\workplace\e3-manager\e3-manager-pojo\target
[INFO] 
[INFO] >>> tomcat7-maven-plugin:2.2:redeploy (default-cli) > package @ e3-manager-pojo >>>
[INFO] 
[INFO] --- maven-resources-plugin:2.7:resources (default-resources) @ e3-manager-pojo ---
[INFO] Using 'UTF-8' encoding to copy filtered resources.
[INFO] Copying 0 resource
[INFO] 
[INFO] --- maven-compiler-plugin:3.2:compile (default-compile) @ e3-manager-pojo ---
[INFO] Changes detected - recompiling the module!
[INFO] Compiling 22 source files to E:\eclipse\workplace\e3-manager\e3-manager-pojo\target\classes
[INFO] 
[INFO] --- maven-resources-plugin:2.7:testResources (default-testResources) @ e3-manager-pojo ---
[INFO] Using 'UTF-8' encoding to copy filtered resources.
[INFO] Copying 0 resource
[INFO] 
[INFO] --- maven-compiler-plugin:3.2:testCompile (default-testCompile) @ e3-manager-pojo ---
[INFO] Nothing to compile - all classes are up to date
[INFO] 
[INFO] --- maven-surefire-plugin:2.5:test (default-test) @ e3-manager-pojo ---
[INFO] Tests are skipped.
[INFO] 
[INFO] --- maven-jar-plugin:2.4:jar (default-jar) @ e3-manager-pojo ---
[INFO] Building jar: E:\eclipse\workplace\e3-manager\e3-manager-pojo\target\e3-manager-pojo.jar
[INFO] 
[INFO] <<< tomcat7-maven-plugin:2.2:redeploy (default-cli) < package @ e3-manager-pojo <<<
[INFO] 
[INFO] --- tomcat7-maven-plugin:2.2:redeploy (default-cli) @ e3-manager-pojo ---
[INFO] Skipping non-war project
[INFO]                                                                         
[INFO] ------------------------------------------------------------------------
[INFO] Building e3-manager-dao 0.0.1-SNAPSHOT
[INFO] ------------------------------------------------------------------------
[INFO] 
[INFO] --- maven-clean-plugin:2.5:clean (default-clean) @ e3-manager-dao ---
[INFO] Deleting E:\eclipse\workplace\e3-manager\e3-manager-dao\target
[INFO] 
[INFO] >>> tomcat7-maven-plugin:2.2:redeploy (default-cli) > package @ e3-manager-dao >>>
[INFO] 
[INFO] --- maven-resources-plugin:2.7:resources (default-resources) @ e3-manager-dao ---
[INFO] Using 'UTF-8' encoding to copy filtered resources.
[INFO] Copying 11 resources
[INFO] 
[INFO] --- maven-compiler-plugin:3.2:compile (default-compile) @ e3-manager-dao ---
[INFO] Changes detected - recompiling the module!
[INFO] Compiling 11 source files to E:\eclipse\workplace\e3-manager\e3-manager-dao\target\classes
[INFO] 
[INFO] --- maven-resources-plugin:2.7:testResources (default-testResources) @ e3-manager-dao ---
[INFO] Using 'UTF-8' encoding to copy filtered resources.
[INFO] Copying 0 resource
[INFO] 
[INFO] --- maven-compiler-plugin:3.2:testCompile (default-testCompile) @ e3-manager-dao ---
[INFO] Nothing to compile - all classes are up to date
[INFO] 
[INFO] --- maven-surefire-plugin:2.5:test (default-test) @ e3-manager-dao ---
[INFO] Tests are skipped.
[INFO] 
[INFO] --- maven-jar-plugin:2.4:jar (default-jar) @ e3-manager-dao ---
[INFO] Building jar: E:\eclipse\workplace\e3-manager\e3-manager-dao\target\e3-manager-dao.jar
[INFO] 
[INFO] <<< tomcat7-maven-plugin:2.2:redeploy (default-cli) < package @ e3-manager-dao <<<
[INFO] 
[INFO] --- tomcat7-maven-plugin:2.2:redeploy (default-cli) @ e3-manager-dao ---
[INFO] Skipping non-war project
[INFO]                                                                         
[INFO] ------------------------------------------------------------------------
[INFO] Building e3-manager-interface 0.0.1-SNAPSHOT
[INFO] ------------------------------------------------------------------------
[INFO] 
[INFO] --- maven-clean-plugin:2.5:clean (default-clean) @ e3-manager-interface ---
[INFO] Deleting E:\eclipse\workplace\e3-manager\e3-manager-interface\target
[INFO] 
[INFO] >>> tomcat7-maven-plugin:2.2:redeploy (default-cli) > package @ e3-manager-interface >>>
[INFO] 
[INFO] --- maven-resources-plugin:2.7:resources (default-resources) @ e3-manager-interface ---
[INFO] Using 'UTF-8' encoding to copy filtered resources.
[INFO] Copying 0 resource
[INFO] 
[INFO] --- maven-compiler-plugin:3.2:compile (default-compile) @ e3-manager-interface ---
[INFO] Changes detected - recompiling the module!
[INFO] Compiling 2 source files to E:\eclipse\workplace\e3-manager\e3-manager-interface\target\classes
[INFO] 
[INFO] --- maven-resources-plugin:2.7:testResources (default-testResources) @ e3-manager-interface ---
[INFO] Using 'UTF-8' encoding to copy filtered resources.
[INFO] Copying 0 resource
[INFO] 
[INFO] --- maven-compiler-plugin:3.2:testCompile (default-testCompile) @ e3-manager-interface ---
[INFO] Nothing to compile - all classes are up to date
[INFO] 
[INFO] --- maven-surefire-plugin:2.5:test (default-test) @ e3-manager-interface ---
[INFO] Tests are skipped.
[INFO] 
[INFO] --- maven-jar-plugin:2.4:jar (default-jar) @ e3-manager-interface ---
[INFO] Building jar: E:\eclipse\workplace\e3-manager\e3-manager-interface\target\e3-manager-interface.jar
[INFO] 
[INFO] <<< tomcat7-maven-plugin:2.2:redeploy (default-cli) < package @ e3-manager-interface <<<
[INFO] 
[INFO] --- tomcat7-maven-plugin:2.2:redeploy (default-cli) @ e3-manager-interface ---
[INFO] Skipping non-war project
[INFO]                                                                         
[INFO] ------------------------------------------------------------------------
[INFO] Building e3-manager-service 0.0.1-SNAPSHOT
[INFO] ------------------------------------------------------------------------
[INFO] 
[INFO] --- maven-clean-plugin:2.5:clean (default-clean) @ e3-manager-service ---
[INFO] Deleting E:\eclipse\workplace\e3-manager\e3-manager-service\target
[INFO] 
[INFO] >>> tomcat7-maven-plugin:2.2:redeploy (default-cli) > package @ e3-manager-service >>>
[INFO] 
[INFO] --- maven-resources-plugin:2.7:resources (default-resources) @ e3-manager-service ---
[INFO] Using 'UTF-8' encoding to copy filtered resources.
[INFO] Copying 9 resources
[INFO] 
[INFO] --- maven-compiler-plugin:3.2:compile (default-compile) @ e3-manager-service ---
[INFO] Changes detected - recompiling the module!
[INFO] Compiling 2 source files to E:\eclipse\workplace\e3-manager\e3-manager-service\target\classes
[INFO] 
[INFO] --- maven-resources-plugin:2.7:testResources (default-testResources) @ e3-manager-service ---
[INFO] Using 'UTF-8' encoding to copy filtered resources.
[INFO] Copying 0 resource
[INFO] 
[INFO] --- maven-compiler-plugin:3.2:testCompile (default-testCompile) @ e3-manager-service ---
[INFO] Changes detected - recompiling the module!
[INFO] Compiling 4 source files to E:\eclipse\workplace\e3-manager\e3-manager-service\target\test-classes
[INFO] 
[INFO] --- maven-surefire-plugin:2.5:test (default-test) @ e3-manager-service ---
[INFO] Tests are skipped.
[INFO] 
[INFO] --- maven-war-plugin:2.2:war (default-war) @ e3-manager-service ---
[INFO] Packaging webapp
[INFO] Assembling webapp [e3-manager-service] in [E:\eclipse\workplace\e3-manager\e3-manager-service\target\e3-manager-service]
[INFO] Processing war project
[INFO] Copying webapp resources [E:\eclipse\workplace\e3-manager\e3-manager-service\src\main\webapp]
[INFO] Webapp assembled in [616 msecs]
[INFO] Building war: E:\eclipse\workplace\e3-manager\e3-manager-service\target\e3-manager-service.war
[INFO] WEB-INF\web.xml already added, skipping
[INFO] 
[INFO] <<< tomcat7-maven-plugin:2.2:redeploy (default-cli) < package @ e3-manager-service <<<
[INFO] 
[INFO] --- tomcat7-maven-plugin:2.2:redeploy (default-cli) @ e3-manager-service ---
[INFO] Deploying war to http://115.159.126.205:8080/  
Uploading: http://115.159.126.205:8080/manager/text/deploy?path=%2F&update=true
Uploaded: http://115.159.126.205:8080/manager/text/deploy?path=%2F&update=true (26091 KB at 2378.1 KB/sec)

[INFO] tomcatManager status code:200, ReasonPhrase:OK
[INFO] OK - Undeployed application at context path /
[INFO] OK - Deployed application at context path /
[INFO] ------------------------------------------------------------------------
[INFO] Reactor Summary:
[INFO] 
[INFO] e3-manager ......................................... SUCCESS [  2.023 s]
[INFO] e3-manager-pojo .................................... SUCCESS [  5.262 s]
[INFO] e3-manager-dao ..................................... SUCCESS [  0.848 s]
[INFO] e3-manager-interface ............................... SUCCESS [  0.316 s]
[INFO] e3-manager-service ................................. SUCCESS [ 30.656 s]
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 40.384 s
[INFO] Finished at: 2018-04-24T17:20:27+08:00
[INFO] Final Memory: 37M/293M
[INFO] ------------------------------------------------------------------------


=================================================

自己写个脚本,同时管理多台tomcat服务器(建议一台服务器上部署3个服务)



修改tomcat端口:

先到安装目录(或者解压目录)下找到conf文件夹,在里面找到server.xml的文件,

<Connector port="8080" protocol="HTTP/1.1"  
               connectionTimeout="20000"  
               redirectPort="8443" />  


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值