简体   繁体   English

spring 引导 + gcloud +“502 错误网关”

[英]spring boot + gcloud + "502 Bad Gateway"

I'm trying to deploy on gcloud this project: https://github.com/ITger/PolishAPI_sample locally works fine, but on gcloud I'm always receiving the 502 error.我正在尝试在 gcloud 上部署这个项目: https://github.com/ITger/PolishAPI_sample在本地工作正常,但在 gcloud 上我总是收到 502 错误。

mvn clean package appengine:deploy command run without problems. mvn clean package appengine:deploy 命令运行没有问题。

In logs (gcloud app logs tail) there are no errors only Info and Debug messages.在日志中(gcloud app logs tail)没有错误,只有信息和调试消息。 For a week I have been looking for a solution and trying many suggestions found in inte.net,I followed google, dzone, etc tutorials, with no luck.一周以来,我一直在寻找解决方案并尝试在 inte.net 中找到的许多建议,我遵循了 google、dzone 等教程,但没有成功。

I appreciate any help我感谢任何帮助

EDITED (resp to John Hanley): ad 1: my code is more than 165 java files, so how to show it???已编辑(回复 John Hanley):广告 1:我的代码超过 165 个 java 个文件,那么如何显示它???

ad 2: app.yaml:广告 2:app.yaml:

runtime: java
env: flex
instance_class: F2
runtime_config:
  jdk: openjdk8
#env_variables:
#  SPRING_PROFILES_ACTIVE: "gcp"
handlers:
  - url: /.*
    script: this field is required, but ignored
readiness_check:
  check_interval_sec: 15
  timeout_sec: 14
  failure_threshold: 2
  success_threshold: 2
  app_start_timeout_sec: 1200

ad 3: As I said there are NO ERRORS in logs only spring info and debug messages.广告 3:正如我所说,日志中没有错误,只有 spring 信息和调试消息。

application.properties file:应用程序.properties 文件:

debug=true
spring.application.name=polish-api-psd2
springfox.documentation.swagger.v2.path=/api-docs
server.port=${port:8080}
spring.jackson.date-format=pl.itger.PolishAPI.RFC3339DateFormat
#Mongo Config
spring.data.mongodb.database=PolishAPI
spring.data.mongodb.uri=mongodb+srv://polishapi-user:SECRET CLUSTER DATA
spring.data.mongodb.auto-index-creation=true
log4j.category.org.springframework.data.mongodb=DEBUG
log4j.appender.stdout.layout.ConversionPattern=%d{ABSOLUTE} %5p %40.40c:%4L - %m%n
logging.level.pl.itger=DEBUG
logging.level.root=WARN

App engine Firewall rules: App 引擎防火墙规则:

Priority 
1000
Action on match
Allow
IP range 
0.0.0.0/0

When I run the " **mvn clean spring-boot:run -P cloud-gcp** " in the Google Cloud Shell console the app starts fine, in the Web Preview the app starts well with the predefined swagger ui page:当我在 Google Cloud Shell 控制台中运行“ **mvn clean spring-boot:run -P cloud-gcp** ”时,应用程序启动正常,在 Web 预览中,应用程序使用预定义的 swagger ui 页面启动良好:

https://8080-dot-10127310-dot-devshell.appspot.com/

with all models and api's displayed.显示所有模型和 api。 When I invoke in the browser " https://8080-dot-10127310-dot-devshell.appspot.com/api-docs " also works well.当我在浏览器中调用“ https://8080-dot-10127310-dot-devshell.appspot.com/api-docs ”时也能正常工作。 Calling with curl any rest service on that url results in"Access Forbidden".使用 curl 调用 url 上的任何 rest 服务会导致“访问被禁止”。

But , after mvn -DskipTests package appengine:deploy -P cloud-gcp nothing works, only 502 Bad Gateway .但是,在mvn -DskipTests package appengine:deploy -P cloud-gcp之后没有任何效果,只有502 Bad Gateway

[INFO] GCLOUD: Setting traffic split for service [default]...
[INFO] GCLOUD: ..............................................................done.
[INFO] GCLOUD: Deployed service [default] to [https://polish-api-psd2.appspot.com]
[INFO] GCLOUD:
[INFO] GCLOUD: You can stream logs from the command line by running:
[INFO] GCLOUD:   $ gcloud app logs tail -s default
[INFO] GCLOUD:
[INFO] GCLOUD: To view your application in the web browser run:
[INFO] GCLOUD:   $ gcloud app browse
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time:  09:15 min
[INFO] Finished at: 2019-12-12T15:49:39+01:00
[INFO] ------------------------------------------------------------------------
p_zerynger@cloudshell:~/PolishAPI_sample/server (polish-api-psd2)$

full Log (its very short, different from that after "mvn spring-boot:run -P cloud-gcp" I dont know why):完整的日志(它很短,与“mvn spring-boot:run -P cloud-gcp”之后的不同,我不知道为什么):

ar!/, jar:file:/app.jar!/BOOT-INF/lib/spring-data-jpa-2.1.10.RELEASE.jar!/, jar:file:/app.jar!/BOOT-INF/lib/spring-orm-5.2.2.RELEASE.jar!/, jar:file:/app.jar!/BOOT-INF/lib/spring-jdbc-5.2.2.RELEASE.jar!/, jar:file:/app.jar!/BOOT-INF/lib/aspectjrt-1.9.5.jar!/, jar:file:/app.jar!/BOOT-INF/lib/lombok-1.18.10.jar!/, jar:file:/app.jar!/BOOT-INF/lib/core-1.5.3.jar!/, jar:file:/app.jar!/BOOT-INF/lib/proxytoys-1.0.jar!/, jar:file:/app.jar!/BOOT-INF/lib/gson-2.8.6.jar!/, jar:file:/app.jar!/BOOT-INF/lib/annotations-17.0.0.jar!/, jar:file:/app.jar!/BOOT-INF/lib/jaxb-api-2.3.1.jar!/, jar:file:/app.jar!/BOOT-INF/lib/javax.activation-api-1.2.0.jar!/]
2019-12-12 14:48:53 default[1]
2019-12-12 14:48:53 default[1]    .   ____          _            __ _ _
2019-12-12 14:48:53 default[1]   /\\ / ___'_ __ _ _(_)_ __  __ _ \ \ \ \
2019-12-12 14:48:53 default[1]  ( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \
2019-12-12 14:48:53 default[1]   \\/  ___)| |_)| | | | | || (_| |  ) ) ) )
2019-12-12 14:48:53 default[1]    '  |____| .__|_| |_|_| |_\__, | / / / /
2019-12-12 14:48:53 default[1]   =========|_|==============|___/=/_/_/_/
2019-12-12 14:48:53 default[1]   :: Spring Boot ::        (v2.2.2.RELEASE)
2019-12-12 14:48:53 default[1]
2019-12-12 14:48:54 default[1]  2019-12-12 14:48:54.093  INFO 1 --- [           main] p.i.P.PolishAPI_2_1_2_SpringBoot         : Starting PolishAPI_2_1_2_SpringBoot v1.0.1 on e1b35acb6032 with PID 1 (/app.jar started by root in /)
2019-12-12 14:48:54 default[1]  2019-12-12 14:48:54.096 DEBUG 1 --- [           main] p.i.P.PolishAPI_2_1_2_SpringBoot         : Running with Spring Boot v2.2.2.RELEASE, Spring v5.2.2.RELEASE
2019-12-12 14:48:54 default[1]  2019-12-12 14:48:54.098  INFO 1 --- [           main] p.i.P.PolishAPI_2_1_2_SpringBoot         : No active profile set, falling back to default profiles: default
2019-12-12 14:48:54 default[1]  2019-12-12 14:48:54.102 DEBUG 1 --- [           main] o.s.boot.SpringApplication               : Loading source class pl.itger.PolishAPI.PolishAPI_2_1_2_SpringBoot
2019-12-12 14:48:54 default[1]  2019-12-12 14:48:54.341 DEBUG 1 --- [           main] o.s.b.c.c.ConfigFileApplicationListener  : Loaded config file 'jar:file:/app.jar!/BOOT-INF/classes!/application.properties' (classpath:/application.properties)
2019-12-12 14:48:54 default[1]  2019-12-12 14:48:54.345 DEBUG 1 --- [           main] ConfigServletWebServerApplicationContext : Refreshing org.springframework.boot.web.servlet.context.AnnotationConfigServletWebServerApplicationContext@6c3708b3
2019-12-12 14:52:42 default[1]  I1212 14:51:56.693214    26 callbacks_monitor.cc:66] Cloud Debugger call "JVMTI:ClassPrepare" completed after 25847 ms

+++++++++ in cloud http load balancer log I found this: +++++++++ 在云 http 负载均衡器日志中我发现了这个:

jsonPayload: {
  @type: "type.googleapis.com/google.cloud.loadbalancing.type.LoadBalancerLogEntry"   
  statusDetails: "failed_to_connect_to_backend"   
 }

It's crazy... now timeout:这太疯狂了......现在超时:

[INFO] GCLOUD: ERROR: (gcloud.app.deploy) Error Response: [4] App Engine Flexible timed out while configuring resources, internal operation projects/polish-api-psd2/regions/europe-west1/operations/3343fc51-2991-4da1-ba45-128bd897d92f

Every deployment has a version number assigned to it.每个部署都有一个分配给它的版本号。 Verify if that version number appears in the "versions" section under "app engine" of your GCP project.验证该版本号是否出现在 GCP 项目“应用引擎”下的“版本”部分中。 If the version number does appear, logs will be provided in StackDriver detailing any possible deployment errors that occurred.如果版本号确实出现,则 StackDriver 中将提供日志,详细说明发生的任何可能的部署错误。

If the version number does not appear then re-deploy the project and this time enable the verbosity flag to generate deploy logs.[1]如果版本号没有出现,则重新部署项目,这次启用详细标志以生成部署日志。 [1]

Lastly, try deploying a bare minimum "Hello World" app and see if that works if the issue is not code-related.最后,尝试部署一个最低限度的“Hello World”应用程序,如果问题与代码无关,看看它是否有效。

[1] https://cloud.google.com/sdk/gcloud/reference/#--verbosity [1] https://cloud.google.com/sdk/gcloud/reference/#--verbosity

Add添加

resources:
  memory_gb: 4

Inside your yaml file.在你的 yaml 文件中。

I don't have a solution to this but have been running into the same thing.我对此没有解决方案,但一直遇到同样的事情。 In attempting to migrate a web application using a spring boot backend I've run into and incredible and frustrating amount of issues.在尝试使用 spring 启动后端迁移 web 应用程序时,我遇到了令人难以置信且令人沮丧的问题。

I've reverted to deploying a hello world spring boot app that I can see work.我已经恢复部署我可以看到工作的 hello world spring 启动应用程序。 I've started by pulling all of the dependencies over from my webapp introducing them piece meal.我已经开始从我的 webapp 中拉出所有的依赖项来介绍它们。 As the original poster says, the startup logs have zero/no/none indications of ANY errors in the startup logs.正如原始海报所说,启动日志在启动日志中有任何错误的零/无/无指示。 When uncommenting a dependency such as com.google.cloud:google-cloud-logging-logback:0.129.9-alpha I'll begin to get the 502 errors after deploy.当取消注释诸如 com.google.cloud:google-cloud-logging-logback:0.129.9-alpha 之类的依赖项时,我将在部署后开始收到 502 错误。 Unfortunately this is not the only dependency this is happening for.不幸的是,这并不是发生这种情况的唯一依赖项。 I'm just simply trying to isolate ALL of the dependencies which cause this behavior.我只是简单地尝试隔离导致此行为的所有依赖项。 Again application logs show no indication of any error and they startup fine.同样,应用程序日志没有显示任何错误的迹象,并且它们启动正常。 It's simply by including some dependencies it causes application to be unavailable bc of 502s.它只是通过包含一些依赖项导致应用程序在 502s 之前不可用。 Once I isolate all of the dependencies which are making this happen not exactly sure what I'll do next in order to resolve this but isolating them seems to be my only course of action.一旦我隔离了所有导致这种情况发生的依赖项,我就不确定接下来要做什么来解决这个问题,但隔离它们似乎是我唯一的行动方案。 This application works completely fine in local development.此应用程序在本地开发中完全可以正常工作。

If you are reading this and considering google cloud I STRONGLY RECOMMEND YOU LOOK AT OTHER CLOUD PROVIDERS.如果您正在阅读本文并考虑使用谷歌云,我强烈建议您看看其他云提供商。 Google cloud support, documentation is absolute garbage and there is zero indication in the platform or logs what is going wrong when a problem occurs.谷歌云支持,文档绝对是垃圾,平台中的指示为零,或者在出现问题时记录出了什么问题。 I hope comments like this will cause action on google's part because this technology ABSOLUTE GARBAGE.我希望像这样的评论会引起谷歌方面的行动,因为这项技术绝对是垃圾。 I'm currently hamstrung by my client and need to use this but would have migrated away if I had the choice.我目前被我的客户束缚住了,需要使用它,但如果我有选择的话,我会迁移出去。 I generally think google is good company but their suite of cloud products has made me come to the hard realization they do in fact lay giant hot steamy carl's for products.我通常认为谷歌是一家好公司,但他们的云产品套件让我意识到他们实际上为产品奠定了巨大的热气腾腾的卡尔。 This comment hopefully will get the attention of someone there to take action on this giant garbage dump of a product.希望这条评论能引起那里某人的注意,以便对这个巨大的产品垃圾场采取行动。

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

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