Centos7安裝tomcat-7.0.56和熱部署
阿新 • • 發佈:2018-11-02
一、tomcat安裝
按照上一篇的Centos7安裝JDK的方法將檔案從主機下載到Centos7的下載目錄下。
安裝包名稱為:apache-tomcat-7.0.56.zip
- 解壓檔案到usr/local下面
$ su - # cd /usr/local # cp /home/[使用者名稱]/下載/apache-tomcat-7.0.56.zip ./ <!-- 複製檔案到當前目錄 --> # unzip apache-tomcat-7.0.56.zip # chmod 777 -R ./apache-tomcat-7.0.56 <!-- 為此檔案授權,不然進入使用者後無啟動許可權 --> <!-- 或者使用: # cd apache-tomcat-7.0.56 # chmod 777 -R ./* -->
- 進入apache-tomcat-7.0.56/bin下面啟動tomcat
# exit 退出root賬戶
$ cd /usr/local/apache-tomcat-7.0.56/bin
$ ./startup.sh 啟動tomcat
啟動完成後就可以在火狐瀏覽器中輸入localhost://8080就可以顯示tomcat的介面,至此安裝完成
二、熱部署
如果要進行基於maven的熱部署,就需要相應的配置
- 利用root賬戶修改apache-tomcat-7.0.56/conf/tomcat-users.xml檔案
在此之前關閉tomcat 即:shutdown.sh $ su - # cd /usr/local/apache-tomcat-7.0.56/conf # ls 檢視下面是否有tomcat-users.xml檔案 # vi tomcat-users.xml 進入後新增下面的程式碼在最後面【</tomcat-users>之前】 <role rolename="manager-gui"/> <role rolename="manager-script"/> <user username="admin" password="password" roles="manager-gui,manager-script"/> 使用shift + i 進行編輯 Esc退出編輯 shif + :進入末行 輸入 wq 進行儲存並退出 在瀏覽器地址中使用 http://10.12.155.85:8080/manager/text 輸入上一步設定的使用者名稱、密碼 [admin password] http://10.12.155.85:8080/manager/html訪問顯示web版tomcat操作介面
- 修改maven的m2倉庫下的setting檔案[我的maven使用的是m2下的setting,所以視自己的maven的setting檔案而定]
settings.xml 的125行左右新增如下程式碼: <!-- <server> <id>deploymentRepo</id> <username>repouser</username> <password>repopwd</password> </server> 這是125行的東西,為了提示,所以這個註釋的程式碼可以不拷貝 --> <server> <id>tomcat7</id> <username>admin</username> <password>password</password> </server>
- 新建STS的maven工程,選擇war包,在pom.xml中新增如下程式碼
<build>
<plugins>
<!-- 配置編譯環境-->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.6.1</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>
<!-- 配置tomcat外掛 -->
<plugin>
<groupId>org.apache.tomcat.maven</groupId>
<artifactId>tomcat7-maven-plugin</artifactId>
<version>2.2</version>
<configuration>
<url>http://10.12.155.94:8080/manager/text</url> <!-- 前面的網址是Linux的網址 -->
<server>tomcat7</server>
<username>admin</username>
<password>password</password>
<ignorePackaging>true</ignorePackaging>
</configuration>
</plugin>
</plugins>
</build>
<!--
網址需要在virtualbox中選擇橋接模式,並選擇當前網路的連線介面卡(在本地檢視網路)
在Linux更改一個引數,如下:
-->
# cd /etc/sysconfig/network-scripts
# vi ifcfg-enp0s3 <!-- 第一個檔案 -->
更改裡面的ONBOOT=yes即可
執行使用maven build
tomcat7:deploy 熱部署,這是執行工程
tomcat7:undeploy 熱反部署,這是將工程從Linux刪除