本文講解筆者如何在阿裡雲Linux CentOS伺服器上部署Java Web項目,完整的記錄好操作的每一個步驟。 ...
本文講解如何在Linux CentOS下部署Java Web項目的步驟。
一、環境準備:
(1)Linux CentOS
(2)apache-tomcat-9.0.10
(3)XShell
二、啟動tomcat
1、啟動Tomcat
進入 apache-tomcat-9.0.10 下的 bin 目錄下
輸入: ./catalina.sh start
[root@izuf6famz0x92jd98na1kiz bin]# ./catalina.sh start Using CATALINA_BASE: /usr/local/tomcat/apache-tomcat-9.0.10 Using CATALINA_HOME: /usr/local/tomcat/apache-tomcat-9.0.10 Using CATALINA_TMPDIR: /usr/local/tomcat/apache-tomcat-9.0.10/temp Using JRE_HOME: /usr/java/jdk1.8.0_171 Using CLASSPATH: /usr/local/tomcat/apache-tomcat-9.0.10/bin/bootstrap.jar:/usr/local/tomcat/apache-tomcat-9.0.10/bin/tomcat-juli.jar Tomcat started.
2、查看 tomcat 啟動日誌[可選]
進入 apache-tomcat-9.0.10/logs 下
[root@izuf6famz0x92jd98na1kiz apache-tomcat-9.0.10]# ls bin conf lib LICENSE logs NOTICE RELEASE-NOTES RUNNING.txt temp webapps work [root@izuf6famz0x92jd98na1kiz apache-tomcat-9.0.10]# cd logs [root@izuf6famz0x92jd98na1kiz logs]# ls catalina.2018-07-04.log host-manager.2018-07-04.log localhost.2018-07-05.log manager.2018-07-04.log catalina.2018-07-05.log host-manager.2018-07-05.log localhost_access_log.2018-07-04.txt manager.2018-07-05.log catalina.out localhost.2018-07-04.log localhost_access_log.2018-07-05.txt
執行 cat catalina.out
註: ./catalina.sh start 和 ./startup.sh 都能啟動tomcat。使用 ./catalina.sh stop 或 ./shutdown.sh 停止tomcat。
可以查看 tomcat 啟動日誌:
[root@izuf6famz0x92jd98na1kiz logs]# cat catalina.out 04-Jul-2018 18:32:03.012 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Server version: Apache Tomcat/9.0.10 04-Jul-2018 18:32:03.013 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Server built: Jun 20 2018 17:32:21 UTC 04-Jul-2018 18:32:03.013 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Server number: 9.0.10.0 04-Jul-2018 18:32:03.013 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log OS Name: Linux 04-Jul-2018 18:32:03.013 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log OS Version: 3.10.0-693.2.2.el7.x86_64 04-Jul-2018 18:32:03.014 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Architecture: amd64 04-Jul-2018 18:32:03.014 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Java Home: /usr/java/jdk1.8.0_171/jre 04-Jul-2018 18:32:03.014 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log JVM Version: 1.8.0_171-b11 04-Jul-2018 18:32:03.014 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log JVM Vendor: Oracle Corporation 04-Jul-2018 18:32:03.014 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log CATALINA_BASE: /usr/local/tomcat/apache-tomcat-9.0.10 ……省略05-Jul-2018 14:05:43.147 INFO [main] org.apache.catalina.startup.HostConfig.deployDirectory Deployment of web application directory [/usr/local/tomcat/apache-tomcat-9.0.10/webapps/manager] has finished in [49] ms 05-Jul-2018 14:05:43.147 INFO [main] org.apache.catalina.startup.HostConfig.deployDirectory Deploying web application directory [/usr/local/tomcat/apache-tomcat-9.0.10/webapps/host-manager] 05-Jul-2018 14:05:43.187 INFO [main] org.apache.catalina.startup.HostConfig.deployDirectory Deployment of web application directory [/usr/local/tomcat/apache-tomcat-9.0.10/webapps/host-manager] has finished in [39] ms 05-Jul-2018 14:05:43.198 INFO [main] org.apache.coyote.AbstractProtocol.start Starting ProtocolHandler ["http-nio-8080"] 05-Jul-2018 14:05:43.209 INFO [main] org.apache.coyote.AbstractProtocol.start Starting ProtocolHandler ["ajp-nio-8009"] 05-Jul-2018 14:05:43.210 INFO [main] org.apache.catalina.startup.Catalina.start Server startup in 565104 ms
3、訪問瀏覽器,驗證tomcat啟動成功
二、上傳要部署項目文件到伺服器
1、安裝上傳文件到 Linux 中的工具軟體
lrzsz
安裝指令如下:
yum install lrzsz
[root@izuf6famz0x92jd98na1kiz download]# yum install lrzsz Loaded plugins: fastestmirror base | 3.6 kB 00:00:00 epel | 3.2 kB 00:00:00 extras | 3.4 kB 00:00:00 updates | 3.4 kB 00:00:00 (1/7): base/7/x86_64/group_gz | 166 kB 00:00:00 (2/7): epel/x86_64/group_gz | 88 kB 00:00:00 (3/7): epel/x86_64/updateinfo | 927 kB 00:00:00 (4/7): extras/7/x86_64/primary_db | 149 kB 00:00:00 (5/7): epel/x86_64/primary | 3.5 MB 00:00:00 (6/7): base/7/x86_64/primary_db | 5.9 MB 00:00:00 (7/7): updates/7/x86_64/primary_db | 2.7 MB 00:00:00 Determining fastest mirrors epel 12608/12608 Resolving Dependencies --> Running transaction check ---> Package lrzsz.x86_64 0:0.12.20-36.el7 will be installed --> Finished Dependency Resolution Dependencies Resolved ============================================================================================================================= Package Arch Version Repository Size ============================================================================================================================= Installing: lrzsz x86_64 0.12.20-36.el7 base 78 k Transaction Summary ============================================================================================================================= Install 1 Package Total download size: 78 k Installed size: 181 k Is this ok [y/d/N]:
輸入 "y"
Is this ok [y/d/N]: y Downloading packages: lrzsz-0.12.20-36.el7.x86_64.rpm | 78 kB 00:00:00 Running transaction check Running transaction test Transaction test succeeded Running transaction Installing : lrzsz-0.12.20-36.el7.x86_64 1/1 Verifying : lrzsz-0.12.20-36.el7.x86_64 1/1 Installed: lrzsz.x86_64 0:0.12.20-36.el7 Complete!
驗證是否安裝成功:
[root@izuf6famz0x92jd98na1kiz download]# rpm -qa|grep lrzsz lrzsz-0.12.20-36.el7.x86_64
出現如上,即是安裝成功。
2、將項目部署文件上傳到伺服器
(1)使用 lrzsz 上傳文件到伺服器
輸入 rz ,即彈出 本地電腦的文件選擇框,選擇要上傳到伺服器的文件
(2)選擇要部署項目 的 war 文件
windows 下的文件:
上傳到 阿裡雲的 linux伺服器上:
3、ls指令查看當前目錄
三、部署項目
1、將打包好的war包上傳到tomcat伺服器的webapps目錄
[root@izuf6famz0x92jd98na1kiz webapps]# cp /usr/download/WeChatJPro_01.war /usr/local/tomcat/apache-tomcat-9.0.10/webapps [root@izuf6famz0x92jd98na1kiz webapps]# ls docs examples host-manager manager ROOT WeChatJPro_01 WeChatJPro_01.war
可以發現Tomcat伺服器自動解壓縮war包
2、在瀏覽器上訪問部署的項目
瀏覽器地址欄輸入: http://IP地址:8080/項目名
最終:成功的在阿裡雲ECS 的 Linux CentOS伺服器上部署好Java Web項目!
Donate捐贈
如果我的文章幫助了你,可以贊賞我 1 元給我支持,讓我繼續寫出更好的內容)
(微信) (支付寶)
微信/支付寶 掃一掃