Linux下安裝tomcat和jdk

簡單分爲一下幾個步驟:

1、上傳tomcat壓縮包到linux相關目錄下。(ftp或者winscp或者SecureCRT)

2、進入目錄,解壓tomcat安裝包。

cd /usr/tomcat 執行命令tar -xzvf apache-tomcat-8.5.33.tar.gz

會生成好多tomcat相關的文件

apache-tomcat-8.5.33/webapps/examples/jsp/jsp2/simpletag/book.html
apache-tomcat-8.5.33/webapps/examples/jsp/jsp2/simpletag/book.jsp
apache-tomcat-8.5.33/webapps/examples/jsp/jsp2/simpletag/book.jsp.html
apache-tomcat-8.5.33/webapps/examples/jsp/jsp2/simpletag/hello.html
apache-tomcat-8.5.33/webapps/examples/jsp/jsp2/simpletag/hello.jsp
apache-tomcat-8.5.33/webapps/examples/jsp/jsp2/simpletag/hello.jsp.html
apache-tomcat-8.5.33/webapps/examples/jsp/jsp2/simpletag/repeat.html
apache-tomcat-8.5.33/webapps/examples/jsp/jsp2/simpletag/repeat.jsp
apache-tomcat-8.5.33/webapps/examples/jsp/jsp2/simpletag/repeat.jsp.html
apache-tomcat-8.5.33/webapps/examples/jsp/jsp2/tagfiles/displayProducts.tag.html
apache-tomcat-8.5.33/webapps/examples/jsp/jsp2/tagfiles/hello.html
apache-tomcat-8.5.33/webapps/examples/jsp/jsp2/tagfiles/hello.jsp
apache-tomcat-8.5.33/webapps/examples/jsp/jsp2/tagfiles/hello.jsp.html
apache-tomcat-8.5.33/webapps/examples/jsp/jsp2/tagfiles/helloWorld.tag.html
apache-tomcat-8.5.33/webapps/examples/jsp/jsp2/tagfiles/panel.html
apache-tomcat-8.5.33/webapps/examples/jsp/jsp2/tagfiles/panel.jsp
apache-tomcat-8.5.33/webapps/examples/jsp/jsp2/tagfiles/panel.jsp.html
apache-tomcat-8.5.33/webapps/examples/jsp/jsp2/tagfiles/panel.tag.html。。。。。。。。。。。。。。。。。。。。。

之後,就會解壓完成。

3、修改解壓縮的文件名稱

mv apache-tomcat-8.5.33 tomcat8.5,這裏可以修改爲任意名成,看個人愛好了。

4、配置jdk環境變量,然後就可以啓動tomcat了

通過命令cd /usr/tomcat/tomcat8.5/bin進入該目錄下,通過ls -lt命令,按照時間順序查看該目錄的文件列表

通過開始命令發佈tomcat,以下是因爲我沒配置jdk,所以提示沒有jre環境

[[email protected] bin]# ./startup.sh
Neither the JAVA_HOME nor the JRE_HOME environment variable is defined
At least one of these environment variable is needed to run this program
[[email protected] bin]#

 

5、安裝jdk

運行命令解壓jdk安裝包:tar -xzvf jdk-8u181-linux-x64.tar.gz

//使用 tar -xvf file.tar解壓tar包

6、配置環境變量

 cd /etc進入該目錄,然後使用vi profile修改profile文件

在最後加上如下代碼塊:

export JAVA_HOME=/opt/jdk/jdk1.8.0_181

export CLASSPATH=.:$JAVA_HOME/lib:$JAVA_HOME/jre/lib:$CLASSPATH

export PATH=$JAVA_HOME/bin:$JAVA_HOME/jre/bin:$PATH

7、即時生效命令,或者重啓服務

source /etc/profile

8、查看是否安裝成功

java -version

9、再次啓動tomcat

cd /usr/tomcat/tomcat8.5/bin

執行命令:./startup.sh

10、使用命令查看tomcat啓動狀態

執行命令:ps -ef|grep tomcat,如果看到以下內容,說明tomcat以及jdk配置成功。

11、訪問http://ip:端口號測試是否發佈成功

  注意:在阿里雲ESC實例上部署了jdk和tomcat,啓動tomct後,內網可以訪問8080端口,外網無法訪問8080,需要設置安全組規則

 

如果訪問ip可以看到如下圖所示,恭喜您,配置完畢。