简体   繁体   English

无法远程访问 tomcat 服务器

[英]Can't reach tomcat server remotely

I'm using a VM on Google Compute Engine, I chose a g1-small machine.我在 Google Compute Engine 上使用 VM,我选择了 g1-small 机器。

I installed tomcat server.我安装了 tomcat 服务器。 The server do run, but I can't reach it on my web browser.服务器确实运行,但我无法在我的 web 浏览器上访问它。

I also installed httpd and I can reach port 80 on my browser, but not 8080我还安装了 httpd,我可以在浏览器上访问端口 80,但不能访问 8080

This are my open ports:这是我的开放端口:

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

This is my tomcat.service file:这是我的 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

I already added port 8080 to firewall with the command我已经使用命令将端口 8080 添加到防火墙

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

But when I list the firewall settings I get this但是当我列出防火墙设置时,我得到了这个

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: 

To solve your issue you should configure GCP Firewall to allow ingress connections to your Tomcat server.要解决您的问题,您应该配置 GCP 防火墙以允许入口连接到您的 Tomcat 服务器。

Have a look at the documentation Configuring Firewall Rules and follow instruction Creating a firewall ingress rule via Console or via command line:查看文档配置防火墙规则并按照说明通过控制台或命令行创建防火墙入口规则

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

I'd recommend you to replace 0.0.0.0/0 with your IPs and use network tags to apply your rule to your VM instance directly:我建议您将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