16.3 安裝Tomcat

安裝Tomcat目錄概要

安裝Tomcat

  • tomcat雖然是jdk和java 的中間件,可是若是沒有了它,就不能去監聽8080端口或80端口,也沒法讓客戶端或者瀏覽器去訪問直接訪問站點,tomcat就是一個java的webserver
  • tomcat依賴於jdk ,因此須要先安裝jdk
  1. 切換到/ues/local/src/目錄下
[root@hf-01 ~]# cd /usr/local/src
[root@hf-01 src]#
  1. 下載tomcat的安裝包(二進制免編譯包),命令 wget https://mirrors.tuna.tsinghua.edu.cn/apache/tomcat/tomcat-8/v8.5.24/bin/apache-tomcat-8.5.24.tar.gz
[root@hf-01 src]# wget https://mirrors.tuna.tsinghua.edu.cn/apache/tomcat/tomcat-8/v8.5.24/bin/apache-tomcat-8.5.24.tar.gz
  1. 解壓包
[root@hf-01 src]# tar zxf apache-tomcat-8.5.24.tar.gz 
[root@hf-01 src]#
  1. 解壓完以後,移動到/usr/local/目錄下,並更更名字爲tomcat
  • mv apache-tomcat-8.5.24 /usr/local/tomcat
[root@hf-01 src]# mv apache-tomcat-8.5.24 /usr/local/tomcat
[root@hf-01 src]#
  1. 啓動tomcat,由於tomcat軟件包下載的是 二進制免編譯包 ,不用去編譯
  • /usr/local/tomcat/bin/startup.sh
[root@hf-01 src]# /usr/local/tomcat/bin/startup.sh  //這樣就能把tomcat啓動
Using CATALINA_BASE:   /usr/local/tomcat
Using CATALINA_HOME:   /usr/local/tomcat
Using CATALINA_TMPDIR: /usr/local/tomcat/temp
Using JRE_HOME:        /usr/local/jdk1.8
Using CLASSPATH:       /usr/local/tomcat/bin/bootstrap.jar:/usr/local/tomcat/bin/tomcat-juli.jar
Tomcat started.
[root@hf-01 src]#
  1. 這時候能夠grep查看是否有java的進程,如果有java這個進程,說明tomcat正常啓動了
[root@hf-01 src]# ps aux |grep java
root      2800  2.5  8.6 2296760 87456 pts/0   Sl   13:02   0:04 /usr/local/jdk1.8/bin/java -Djava.util.logging.config.file=/usr/local/tomcat/conf/logging.properties -Djava.util.logging.manager=org.apache.juli.ClassLoaderLogManager -Djdk.tls.ephemeralDHKeySize=2048 -Djava.protocol.handler.pkgs=org.apache.catalina.webresources -Dignore.endorsed.dirs= -classpath /usr/local/tomcat/bin/bootstrap.jar:/usr/local/tomcat/bin/tomcat-juli.jar -Dcatalina.base=/usr/local/tomcat -Dcatalina.home=/usr/local/tomcat -Djava.io.tmpdir=/usr/local/tomcat/temp org.apache.catalina.startup.Bootstrap start
root      2844  0.0  0.0 112680   976 pts/0    R+   13:05   0:00 grep --color=auto java
[root@hf-01 src]#
  1. 關閉tomcat的命令爲/usr/local/romcat/bin/shutdown.sh ,tomcat不支持restart,如果更改了配置文件,須要去從新啓動,先stop,而後start
  • /usr/local/tomcat/bin/shutdown.sh
  • 關閉tomcat,再來查看進程,會看到tomcat已經關閉
[root@hf-01 src]# /usr/local/tomcat/bin/shutdown.sh
Using CATALINA_BASE:   /usr/local/tomcat
Using CATALINA_HOME:   /usr/local/tomcat
Using CATALINA_TMPDIR: /usr/local/tomcat/temp
Using JRE_HOME:        /usr/local/jdk1.8
Using CLASSPATH:       /usr/local/tomcat/bin/bootstrap.jar:/usr/local/tomcat/bin/tomcat-juli.jar
[root@hf-01 src]# ps aux |grep java
root      2875  0.0  0.0 112680   972 pts/0    R+   13:09   0:00 grep --color=auto java
[root@hf-01 src]#
  1. 這時再啓動tomcat
[root@hf-01 src]# /usr/local/tomcat/bin/startup.sh
Using CATALINA_BASE:   /usr/local/tomcat
Using CATALINA_HOME:   /usr/local/tomcat
Using CATALINA_TMPDIR: /usr/local/tomcat/temp
Using JRE_HOME:        /usr/local/jdk1.8
Using CLASSPATH:       /usr/local/tomcat/bin/bootstrap.jar:/usr/local/tomcat/bin/tomcat-juli.jar
Tomcat started.
[root@hf-01 src]#
  1. 查看tomcat的監聽端口,會看到的監聽端口爲8080端口和8009端口,還有一個8005端口
  • 8080爲提供web服務的端口,8005爲管理端口,8009端口爲第三方服務調用的端口,好比httpd和Tomcat結合時會用到
  • 通常使用的是8080端口
[root@hf-01 src]# netstat -lntp |grep java
tcp6       0      0 :::8080                 :::*                    LISTEN      2893/java           
tcp6       0      0 127.0.0.1:8005          :::*                    LISTEN      2893/java           
tcp6       0      0 :::8009                 :::*                    LISTEN      2893/java           
[root@hf-01 src]#
  1. 測試tomcat訪問頁面
  2. 關閉防火牆
  • 關閉firlewalld
    • systemctl stop firewalld
    • systemctl disable firewalld
關閉防火牆
[root@hf-01 src]# systemctl stop firewalld
[root@hf-01 src]# systemctl disable firewalld
Removed symlink /etc/systemd/system/dbus-org.fedoraproject.FirewallD1.service.
Removed symlink /etc/systemd/system/basic.target.wants/firewalld.service.
[root@hf-01 src]# iptables -nvL
Chain INPUT (policy ACCEPT 0 packets, 0 bytes)
 pkts bytes target     prot opt in     out     source               destination         

Chain FORWARD (policy ACCEPT 0 packets, 0 bytes)
 pkts bytes target     prot opt in     out     source               destination         

Chain OUTPUT (policy ACCEPT 0 packets, 0 bytes)
 pkts bytes target     prot opt in     out     source               destination         
[root@hf-01 src]#
  1. 關閉防火牆以後,打開瀏覽器訪問 虛擬機的IP 加 8080端口 ,如 192.168.202.131:8080

輸入圖片說明

  1. 打開以下的界面就是訪問成功了
相關文章
相關標籤/搜索