Google应用引擎TCP连接失败 [英] Google app engine TCP connection Failed

查看:239
本文介绍了Google应用引擎TCP连接失败的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

部署到谷歌应用程序引擎的Spring启动应用程序,并且对端点的请求按照预期使用硬编码文本进行正确响应。除了默认的端口 8080 外,另一个 TCP:8595 也暴露在数据发布到该端口的地方跟踪设备。

问题是当我测试与 telnet projectid.appspot.com 8595 i获取此响应连接到projectid.appspot.com ...无法打开与主机的连接,端口8595:连接失败,本地认为连接没有失败。

应用程序引擎中托管的应用程序如何公开端口?



免责声明:我是App Engine的新手和GCP

解决方案

docs ,你应该可以在你的app.yaml中设置端口转发,然后通过防火墙规则。

1。)端口转发

  network:
forwarded_ports:
- 2222 / tcp

调试思路:使用AppEngine Flex,您可以通过SSH进入实例进行进一步调试(App Engine> Instances,SSH按钮旁边的实例)。

登录后,您应该能够运行此docker命令以查看公开的端口(在我的示例中,我在 app中公开了8081 .yaml ):

  $ sudo docker port gaeapp 
8080 / tcp - > 172.17.0.1:8080
8081 / tcp - > 0.0.0.0:8081

你甚至可以检查它是否侦听(在我的情况下,它是一个HTTP服务正确回复404):

  curl localhost:8081 
{timestamp:1519837414455,status:404 ,error:Not Found,message:无信息,path:/}

(对于telnet,您需要使用 sudo apt-get update&& sudo apt-get install -y telnet 来安装它)



如果显示您的端口,那么下一步是仔细检查您的防火墙设置。
$ b 2。)防火墙设置

  gcloud compute firewall-rules create myrule --allow = tcp:8595 --source-ranges = 0.0.0.0 / 0 

然而,这只允许您直接通过VM实例IP访问您的应用程序!(您可以在控制台中找到您的IP或列出您的实例 gcloud compute实例列表



请参阅 docs


forwarded_ports 可选。您可以将实例
(HOST_PORT)中的端口转发到Docker容器(CONTAINER_PORT)。如果只有
指定一个PORT,那么App Engine会假定它是
主机和容器上的相同端口。默认情况下,TCP和UDP流量都是
转发。 流量必须直接发送到目标实例
,而不是通过appspot.com域名或您的自定义域名。


Spring boot application deployed to google app engine and a request to an endpoint respond correctly with hard-coded text as expected. Apart from the default port 8080 exposed, another TCP:8595 is also exposed where data with be published to that port by tracking devices.

The problem is when i tested to get tcp connection with telnet projectid.appspot.com 8595 i get this response Connecting To projectid.appspot.com...Could not open connection to the host, on port 8595: Connect failed, thought locally a connection is made without failure.

How can an application hosted in app engine expose ports?

Disclaimer: I'm new to App Engine and GCP

解决方案

As it states in the docs, you should be able to set port forwarding in your app.yaml and then exposing it via Firewall rules.

1.) port forwarding

network:
  forwarded_ports:
    - 2222/tcp

Debugging idea: with AppEngine Flex you can SSH into the instance for further debugging (App Engine > Instances , SSH button next to your instance).

After you logged in, you should be able to run this docker command to see the ports exposed (in my case I exposed 8081 in my app.yaml):

$ sudo docker port gaeapp
8080/tcp -> 172.17.0.1:8080
8081/tcp -> 0.0.0.0:8081

You can even check if it listens or not (in my case it's an HTTP service replying correctly 404):

curl localhost:8081
{"timestamp":1519837414455,"status":404,"error":"Not Found","message":"No message available","path":"/"}

(for telnet you'll need to install it with sudo apt-get update && sudo apt-get install -y telnet)

If this shows your port, then the next step is to double check your firewall settings.

2.) Firewall setup

gcloud compute firewall-rules create myrule --allow=tcp:8595 --source-ranges=0.0.0.0/0

However this will only let you access your app through the VM instance IP directly! (you can find your IP in the console or by listing your instances gcloud compute instances list)

See the description of forwarded_ports in the docs

forwarded_ports Optional. You can forward ports from your instance (HOST_PORT) to the Docker container (CONTAINER_PORT). If you only specify a PORT, then App Engine assumes that it is the same port on the host and the container. By default, both TCP and UDP traffic are forwarded. Traffic must be directly addressed to the target instance rather than over the appspot.com domain or your custom domain.

这篇关于Google应用引擎TCP连接失败的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆