1. 程式人生 > >在虛擬機器CentOS 5.11 裡安裝 tomcat7

在虛擬機器CentOS 5.11 裡安裝 tomcat7

1.下載 apache-tomcat 7

wget http://mirrors.tuna.tsinghua.edu.cn/apache/tomcat/tomcat-7/v7.0.94/bin/apache-tomcat-7.0.94.tar.gz

2.解壓縮檔案

tar -zxvf apache-tomcat-7.0.94.tar.gz

3.啟動tomcat

cd /usr/local/tomcat7/bin
./startup.sh

4. 在虛擬機器本地連線tomcat首頁成功。

[root@localhost bin]# curl -I http://192.168.135.134:8080/
HTTP/1.1 200 OK
Server: Apache-Coyote/1.1
Content-Type: text/html;charset=ISO-8859-1
Transfer-Encoding: chunked
Date: Fri, 03 May 2019 01:39:17 GMT

5. 從宿主機訪問tomcat不成功

6. 防火牆開放8080埠,編輯檔案 /etc/sysconfig/iptables

在-A INPUT -m state --state NEW -m tcp -p tcp --dport 22 -j ACCEPT這行的下方新增一行
-A INPUT -m state --state NEW -m tcp -p tcp --dport 8080 -j ACCEPT
修改後如下所示:

# Firewall configuration written by system-config-firewall
# Manual customization of this file is not recommended.
*filter
:INPUT ACCEPT [0:0]
:FORWARD ACCEPT [0:0]
:OUTPUT ACCEPT [0:0]
-A INPUT -m state --state ESTABLISHED,RELATED -j ACCEPT
-A INPUT -p icmp -j ACCEPT
-A INPUT -i lo -j ACCEPT
-A INPUT -m state --state NEW -m tcp -p tcp --dport 22 -j ACCEPT
-A INPUT -m state --state NEW -m tcp -p tcp --dport 8080 -j ACCEPT
-A INPUT -j REJECT --reject-with icmp-host-prohibited
-A FORWARD -j REJECT --reject-with icmp-host-prohibited
COMMIT

儲存後重啟linux的防火牆服務,命令如下:

[root@localhost ~]# /etc/init.d/iptables restart

此時你會發現在宿主機的瀏覽器重新輸入網址就可以看到我們的Tomcat首頁了

參考一:無法訪問虛擬機器tomcat網頁

參考二:Cent