
服務部屬 ( 一 )
終於,我們要來練習部屬服務啦~
之前在 Tomcat 開發環境部屬 有這段!
下載 Tomcat Core
這裡只是簡單複習一下,如果有不懂可以回頭看一下,複習一下基礎!
先來看一下 Tomcat 本身要怎麽使用
先來看一下目錄結構吧!
這是我們的 apache-tomcat-9.0.31 資料夾
apache-tomcat-9.0.31 ├── BUILDING.txt ├── CONTRIBUTING.md ├── LICENSE ├── NOTICE ├── README.md ├── RELEASE-NOTES ├── RUNNING.txt # 服務說明文件 ├── bin # 執行檔目錄 ├── conf ├── lib ├── logs ├── temp ├── webapps # 應用服務目錄 └── work
這邊我們只要專注三個地方
- RUNNING.txt
- bin 目錄
- webapps 目錄
RUNNING.txt
是服務說明文件,包含了:
環境配置需求、Windows 環境、Linux 環境、Mac 環境
如何啟動服務,如何停止服務….
相關說明都是在這個檔案
bin 目錄
執行檔目錄,上面的 RUNNING.txt 通常都會有指定到這個目錄的描述
(4) Start Up Tomcat (4.1) Tomcat can be started by executing one of the following commands: On Windows: %CATALINA_HOME%\bin\startup.bat or %CATALINA_HOME%\bin\catalina.bat start
這邊我節錄 Start Up Tomcat 的片段,可以看到都是 %CATALINA_HOME%\bin 帶頭的,那個 bin 也就是這個 bin 目錄了唷
目錄中很多 .sh 檔 跟 .bat 檔,很明顯的,這些都是可執行檔囉~
webapps 目錄
我們之後打包好的 Servlet 服務,會壓成一個 war 檔,把 war 檔丟進 webapps 目錄之後,服務就會上來囉!
ok! 看完上面的說明,我們可以來把 Tomcat 服務起上來囉!
先以我的個人電腦來做 Demo
我的電腦環境是: macOS Catalina
我現在想要把 Tomcat 服務起上來,所以我要看 RUNNING.txt 檔案
( 環境設定的部分我先略過 )
直接找到 (4) Start Up Tomcat 的段落
(4) Start Up Tomcat (4.1) Tomcat can be started by executing one of the following commands: On Windows: %CATALINA_HOME%\bin\startup.bat or %CATALINA_HOME%\bin\catalina.bat start On *nix: $CATALINA_HOME/bin/startup.sh or $CATALINA_HOME/bin/catalina.sh start (4.2) After startup, the default web applications included with Tomcat will be available by visiting: http://localhost:8080/ (4.3) Further information about configuring and running Tomcat can be found in the documentation included here, as well as on the Tomcat web site: https://tomcat.apache.org/
因為我的電腦是 Catalina ,我們有看到
$CATALINA_HOME/bin/catalina.sh start
也就是說,我只要去執行 catalina.sh 這個檔案,並且帶上 start 參數,就會啟動。
不過要檢查一下權限,預設下載下來應該會看到像這樣的權限
-rw-r–r–
要加一下可執行權限給它,
chmod +x catalina.sh
ok! 來執行吧~
~/tomcat-9.0.31/bin ./catalina.sh start 15:29:10 Using CATALINA_BASE: /Users/wayne/apache-tomcat-9.0.31 Using CATALINA_HOME: /Users/wayne/apache-tomcat-9.0.31 Using CATALINA_TMPDIR: /Users/wayne/apache-tomcat-9.0.31/temp Using JRE_HOME: /Library/Java/JavaVirtualMachines/adoptopenjdk-11.jdk/Contents/Home Using CLASSPATH: /Users/wayne/apache-tomcat-9.0.31/bin/bootstrap.jar:/Users/wayne/apache-tomcat-9.0.31/bin/tomcat-juli.jar Tomcat started.
這樣服務就起來囉!
(4.2) After startup, the default web applications included with Tomcat will be available by visiting: http://localhost:8080/
RUNNING.txt 有說到,預設的服務會在 http://localhost:8080/

這樣 Tomcat 服務就上來囉!
No Comment