繁体   English   中英

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

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

我正在尝试在 gcloud 上部署这个项目: https://github.com/ITger/PolishAPI_sample在本地工作正常,但在 gcloud 上我总是收到 502 错误。

mvn clean package appengine:deploy 命令运行没有问题。

在日志中(gcloud app logs tail)没有错误,只有信息和调试消息。 一周以来,我一直在寻找解决方案并尝试在 inte.net 中找到的许多建议,我遵循了 google、dzone 等教程,但没有成功。

我感谢任何帮助

已编辑(回复 John Hanley):广告 1:我的代码超过 165 个 java 个文件,那么如何显示它???

广告 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

广告 3:正如我所说,日志中没有错误,只有 spring 信息和调试消息。

应用程序.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 引擎防火墙规则:

Priority 
1000
Action on match
Allow
IP range 
0.0.0.0/0

当我在 Google Cloud Shell 控制台中运行“ **mvn clean spring-boot:run -P cloud-gcp** ”时,应用程序启动正常,在 Web 预览中,应用程序使用预定义的 swagger ui 页面启动良好:

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

显示所有模型和 api。 当我在浏览器中调用“ https://8080-dot-10127310-dot-devshell.appspot.com/api-docs ”时也能正常工作。 使用 curl 调用 url 上的任何 rest 服务会导致“访问被禁止”。

但是,在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)$

完整的日志(它很短,与“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

+++++++++ 在云 http 负载均衡器日志中我发现了这个:

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

这太疯狂了......现在超时:

[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

每个部署都有一个分配给它的版本号。 验证该版本号是否出现在 GCP 项目“应用引擎”下的“版本”部分中。 如果版本号确实出现,则 StackDriver 中将提供日志,详细说明发生的任何可能的部署错误。

如果版本号没有出现,则重新部署项目,这次启用详细标志以生成部署日志。 [1]

最后,尝试部署一个最低限度的“Hello World”应用程序,如果问题与代码无关,看看它是否有效。

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

添加

resources:
  memory_gb: 4

在你的 yaml 文件中。

我对此没有解决方案,但一直遇到同样的事情。 在尝试使用 spring 启动后端迁移 web 应用程序时,我遇到了令人难以置信且令人沮丧的问题。

我已经恢复部署我可以看到工作的 hello world spring 启动应用程序。 我已经开始从我的 webapp 中拉出所有的依赖项来介绍它们。 正如原始海报所说,启动日志在启动日志中有任何错误的零/无/无指示。 当取消注释诸如 com.google.cloud:google-cloud-logging-logback:0.129.9-alpha 之类的依赖项时,我将在部署后开始收到 502 错误。 不幸的是,这并不是发生这种情况的唯一依赖项。 我只是简单地尝试隔离导致此行为的所有依赖项。 同样,应用程序日志没有显示任何错误的迹象,并且它们启动正常。 它只是通过包含一些依赖项导致应用程序在 502s 之前不可用。 一旦我隔离了所有导致这种情况发生的依赖项,我就不确定接下来要做什么来解决这个问题,但隔离它们似乎是我唯一的行动方案。 此应用程序在本地开发中完全可以正常工作。

如果您正在阅读本文并考虑使用谷歌云,我强烈建议您看看其他云提供商。 谷歌云支持,文档绝对是垃圾,平台中的指示为零,或者在出现问题时记录出了什么问题。 我希望像这样的评论会引起谷歌方面的行动,因为这项技术绝对是垃圾。 我目前被我的客户束缚住了,需要使用它,但如果我有选择的话,我会迁移出去。 我通常认为谷歌是一家好公司,但他们的云产品套件让我意识到他们实际上为产品奠定了巨大的热气腾腾的卡尔。 希望这条评论能引起那里某人的注意,以便对这个巨大的产品垃圾场采取行动。

暂无
暂无

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

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