【问题标题】:Deploy Django backend on google cloud gives error on console but no error in logs在谷歌云上部署 Django 后端在控制台上出现错误,但在日志中没有错误
【发布时间】:2018-04-06 22:01:49
【问题描述】:

我正在尝试按照https://cloud.google.com/python/django/flexible-environment 上的谷歌教程在 GCP 上部署我的 django 后端 rest api

我能够成功部署示例应用,但是当我尝试部署我的 django 应用时出现以下错误:

latest: digest: 
sha256:d43a6f7d84335f8d724e44cee16de03fd50685d6713107a83b70f44d3c6b5e8f 
size: 2835
DONE
------------------------------------------------------------------------------------------------------------------------------------------------------------------------

Updating service [default] (this may take several minutes)...failed.
ERROR: (gcloud.app.deploy) Error Response: [9]
Application startup error:
[2018-04-03 13:01:35 +0000] [1] [INFO] Starting gunicorn 19.7.1
[2018-04-03 13:01:35 +0000] [1] [INFO] Listening at: http://0.0.0.0:8080 (1)
[2018-04-03 13:01:35 +0000] [1] [INFO] Using worker: sync
[2018-04-03 13:01:35 +0000] [7] [INFO] Booting worker with pid: 7
[2018-04-03 13:01:35 +0000] [1] [INFO] Shutting down: Master
[2018-04-03 13:01:35 +0000] [1] [INFO] Reason: Worker failed to boot.

在构建历史中,它显示成功:

Build information
Status  
 Build successful
Build id    
b2f2ab39-18df-420e-8fac-eeda74dc7a75
Image   
eu.gcr.io/bcbackend-200008/appengine/default.20180403t182207:latest
Trigger 
—
Source  
gs://staging.bcbackend-200008.appspot.com/eu.gcr.io/bcbackend- 
200008/appengine/default.20180403t182207:latest
Started 
April 3, 2018 at 6:23:32 PM UTC+5:30
Build time  
6 min 13 sec

在 GCP 日志中也没有显示错误,但“Worker failed to boot”:

A  2018/04/03 13:01:32 Ready for new connections
A  2018/04/03 13:01:33 Listening on /cloudsql/bcbackend-200008:europe- 
west3:bc-mysql-instance for bcbackend-200008:europe-west3:bc-mysql-instance
A  [2018-04-03 13:01:35 +0000] [1] [INFO] Starting gunicorn 19.7.1
A  [2018-04-03 13:01:35 +0000] [1] [INFO] Listening at: http://0.0.0.0:8080 (1)
A  [2018-04-03 13:01:35 +0000] [1] [INFO] Using worker: sync
A  [2018-04-03 13:01:35 +0000] [7] [INFO] Booting worker with pid: 7
A  [2018-04-03 13:01:35 +0000] [1] [INFO] Shutting down: Master
A  [2018-04-03 13:01:35 +0000] [1] [INFO] Reason: Worker failed to boot.
A  2018/04/03 13:01:40 Ready for new connections
A  2018/04/03 13:01:41 Listening on /cloudsql/bcbackend-200008:europe-west3:bc-mysql-instance for bcbackend-200008:europe-west3:bc-mysql-instance

当我尝试打开“https://bcbackend-200008.appspot.com/”时,我得到以下信息:

Error: Not Found
The requested URL / was not found on this server.

尝试使用“--verbosity=debug”选项运行它,下面是日志:

DEBUG: (gcloud.app.deploy) Error Response: [9]
Application startup error:
[2018-04-04 12:34:42 +0000] [1] [INFO] Starting gunicorn 19.7.1
[2018-04-04 12:34:42 +0000] [1] [INFO] Listening at: http://0.0.0.0:8080 (1)
[2018-04-04 12:34:42 +0000] [1] [INFO] Using worker: sync
[2018-04-04 12:34:42 +0000] [7] [INFO] Booting worker with pid: 7
[2018-04-04 12:34:43 +0000] [1] [INFO] Shutting down: Master
[2018-04-04 12:34:43 +0000] [1] [INFO] Reason: Worker failed to boot.
Traceback (most recent call last):
  File "/usr/lib/google-cloud-sdk/lib/googlecloudsdk/calliope/cli.py", line 
788, in Execute
    resources = calliope_command.Run(cli=self, args=args)
  File "/usr/lib/google-cloud-sdk/lib/googlecloudsdk/calliope/backend.py", 
line 760, in Run
    resources = command_instance.Run(args)
  File "/usr/lib/google-cloud-sdk/lib/surface/app/deploy.py", line 81, in 
Run
    parallel_build=False)
  File "/usr/lib/google-cloud- 

sdk/lib/googlecloudsdk/command_lib/app/deploy_util.py", line 583, in 
  RunDeploy
    flex_image_build_option=flex_image_build_option)
  File "/usr/lib/google-cloud- 

sdk/lib/googlecloudsdk/command_lib/app/deploy_util.py", line 392, in Deploy
    extra_config_settings)
  File "/usr/lib/google-cloud- 

sdk/lib/googlecloudsdk/api_lib/app/appengine_api_client.py", line 200, in 
DeployService
    poller=done_poller)
  File "/usr/lib/google-cloud- 

sdk/lib/googlecloudsdk/api_lib/app/operations_util.py", line 310, in 
WaitForOperation
    sleep_ms=retry_interval)
  File "/usr/lib/google-cloud- 

sdk/lib/googlecloudsdk/api_lib/util/waiter.py", line 251, in WaitFor
    sleep_ms, _StatusUpdate)
  File "/usr/lib/google-cloud- 

sdk/lib/googlecloudsdk/api_lib/util/waiter.py", line 309, in PollUntilDone
    sleep_ms=sleep_ms)
  File "/usr/lib/google-cloud-sdk/lib/googlecloudsdk/core/util/retry.py", 
line 226, in RetryOnResult
    if not should_retry(result, state):
  File "/usr/lib/google-cloud- 

sdk/lib/googlecloudsdk/api_lib/util/waiter.py", line 303, in _IsNotDone
    return not poller.IsDone(operation)
  File "/usr/lib/google-cloud- 

sdk/lib/googlecloudsdk/api_lib/app/operations_util.py", line 179, in IsDone
    encoding.MessageToPyValue(operation.error)))
OperationError: Error Response: [9]
Application startup error:
[2018-04-04 12:34:42 +0000] [1] [INFO] Starting gunicorn 19.7.1
[2018-04-04 12:34:42 +0000] [1] [INFO] Listening at: http://0.0.0.0:8080 (1)

【问题讨论】:

    标签: django google-cloud-platform


    【解决方案1】:

    尝试在 app.yaml 中添加 --preload 作为 gunicorn 命令的参数。这将在尝试启动工作人员时向您显示错误。这些错误将为您提供部署失败原因的线索。

    您的app.yaml 应该如下所示:

    runtime: python
    env: flex
    entrypoint: gunicorn --preload -b :$PORT mysite.wsgi
    
    beta_settings:
        cloud_sql_instances: <your-cloudsql-connection-string>
    
    runtime_config:
      python_version: 3
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-10-22
      • 2014-11-21
      • 1970-01-01
      • 2022-11-19
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多