繁体   English   中英

无法远程访问 tomcat 服务器

[英]Can't reach tomcat server remotely

我在 Google Compute Engine 上使用 VM,我选择了 g1-small 机器。

我安装了 tomcat 服务器。 服务器确实运行,但我无法在我的 web 浏览器上访问它。

我还安装了 httpd,我可以在浏览器上访问端口 80,但不能访问 8080

这是我的开放端口:

Active Internet connections (only servers)
Proto Recv-Q Send-Q Local Address           Foreign Address         State       
PID/Program name    
tcp        0      0 0.0.0.0:22              0.0.0.0:*               LISTEN      1180/sshd           
tcp        0      0 127.0.0.1:25            0.0.0.0:*               LISTEN      1198/master         
tcp6       0      0 :::22                   :::*                    LISTEN      1180/sshd           
tcp6       0      0 ::1:25                  :::*                    LISTEN      1198/master         
tcp6       0      0 127.0.0.1:8005          :::*                    LISTEN      11470/java          
tcp6       0      0 :::8080                 :::*                    LISTEN      11470/java          
tcp6       0      0 :::80                   :::*                    LISTEN      11319/httpd

这是我的 tomcat.service 文件:

[Unit]
Description=Tomcat 8.5 servlet container
After=network.target

[Service]
Type=forking

User=tomcat
Group=tomcat

Environment="JAVA_HOME=/usr/lib/jvm/jre"

Environment="CATALINA_BASE=/opt/tomcat/apache-tomcat-8.5.56"
Environment="CATALINA_HOME=/opt/tomcat/apache-tomcat-8.5.56"
Environment="CATALINA_PID=/opt/tomcat/apache-tomcat-8.5.56/temp/tomcat.pid"
Environment="CATALINA_OPTS=-Xms512M -Xmx1024M -server -XX:+UseParallelGC"

ExecStart=/opt/tomcat/apache-tomcat-8.5.56/bin/startup.sh
ExecStop=/opt/tomcat/apache-tomcat-8.5.56/bin/shutdown.sh

[Install]
WantedBy=multi-user.target

我已经使用命令将端口 8080 添加到防火墙

firewall-cmd --zone=public --permanent --add-port=8080/tcp
firewall-cmd --reload

但是当我列出防火墙设置时,我得到了这个

trusted (active)
 target: ACCEPT
 icmp-block-inversion: no
 interfaces: eth0
 sources: 
 services: http https
 ports: 
 protocols: 
 masquerade: no
 forward-ports: 
 source-ports: 
 icmp-blocks: 
 rich rules: 

要解决您的问题,您应该配置 GCP 防火墙以允许入口连接到您的 Tomcat 服务器。

查看文档配置防火墙规则并按照说明通过控制台或命令行创建防火墙入口规则

gcloud compute firewall-rules create tomcat-server-allow-ingress --direction=INGRESS --priority=1000 --network=default --action=ALLOW --rules=tcp:8080 --source-ranges=0.0.0.0/0 --target-tags=tomcat-server

我建议您将0.0.0.0/0替换为您的 IP,并使用网络标签将您的规则直接应用于您的 VM 实例:

gcloud compute instances add-tags tomcat-server --zone=europe-west3-a --tags=tomcat-server

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM