gpt4 book ai didi

Django 没有连接到 Elastic beanstalk 上的 PostGres

转载 作者:行者123 更新时间:2023-11-29 13:56:30 31 4
gpt4 key购买 nike

我在 AWS EC2 上使用 Elastic Beanstalk 设置了 django。但是,尝试运行该应用程序会在日志文件中出现以下错误

File "/opt/python/run/venv/local/lib/python2.7/site-packages/psycopg2/__init__.py", line 164, in connect
conn = _connect(dsn, connection_factory=connection_factory, async=async)
django.db.utils.OperationalError: could not connect to server: Connection refused
Is the server running on host "localhost" (127.0.0.1) and accepting
TCP/IP connections on port 5432?

(ElasticBeanstalk::ExternalInvocationError)


[2015-06-08T04:52:45.155Z] INFO [5434] - [CMD-AppDeploy/AppDeployStage0/EbExtensionPostBuild/Infra-EmbeddedPostBuild/postbuild_0_SportsGullyRest/Command 01_migrate] : Activity failed.
[2015-06-08T04:52:45.155Z] INFO [5434] - [CMD-AppDeploy/AppDeployStage0/EbExtensionPostBuild/Infra-EmbeddedPostBuild/postbuild_0_SportsGullyRest] : Activity failed.
[2015-06-08T04:52:45.155Z] INFO [5434] - [CMD-AppDeploy/AppDeployStage0/EbExtensionPostBuild/Infra-EmbeddedPostBuild] : Activity failed.
[2015-06-08T04:52:45.191Z] INFO [5434] - [CMD-AppDeploy/AppDeployStage0/EbExtensionPostBuild] : Activity failed.
[2015-06-08T04:52:45.191Z] INFO [5434] - [CMD-AppDeploy/AppDeployStage0] : Activity failed.
[2015-06-08T04:52:45.191Z] INFO [5434] - [CMD-AppDeploy] : Completed activity. Result:
Command CMD-AppDeploy failed.
[2015-06-08T04:58:30.553Z] INFO [5642] - [CMD-BundleLogs] : Starting activity...
[2015-06-08T04:58:30.781Z] INFO [5642] - [CMD-BundleLogs/AddonsBefore] : Starting activity...
[2015-06-08T04:58:30.781Z] INFO [5642] - [CMD-BundleLogs/AddonsBefore] : Completed activity.
[2015-06-08T04:58:30.781Z] INFO [5642] - [CMD-BundleLogs/BundleLogs] : Starting activity...
[2015-06-08T04:58:30.782Z] INFO [5642] - [CMD-BundleLogs/BundleLogs/BundleLogs] : Starting activity...

我的 Python 配置文件是:

option_settings:
"aws:elasticbeanstalk:application:environment":
DJANGO_SETTINGS_MODULE: "SportsGullyRest.settings"
"PYTHONPATH": "/opt/python/current/app/SportsGullyRest:$PYTHONPATH"
"ALLOWED_HOSTS": ".elasticbeanstalk.com"
"aws:elasticbeanstalk:container:python":
WSGIPath: SportsGullyRest/wsgi.py
NumProcesses: 3
NumThreads: 20
"aws:elasticbeanstalk:container:python:staticfiles":
"/static/": "/static/"

我在部署应用程序时缺少什么吗?

编辑:

这是我的数据库 settings.py

if 'RDS_DB_NAME' in os.environ:
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.postgresql_psycopg2',
'NAME': os.environ['RDS_DB_NAME'],
'USER': os.environ['RDS_USERNAME'],
'PASSWORD': os.environ['RDS_PASSWORD'],
'HOST': os.environ['RDS_HOSTNAME'],
'PORT': os.environ['RDS_PORT'],
}
}
else:
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.postgresql_psycopg2',
'NAME': 'dbname',
'USER': 'sgadmin',
'PASSWORD': 'root',
'HOST': 'localhost',
'PORT': '5432',
}
}

最佳答案

问题可能是以下任何一种:

  1. 您是否在您的环境中设置了 postgres?
  2. 它在运行吗?
  3. 您的实例是否突然关闭并且您不得不重新启动 EC2?查看服务状态

我经常遇到第三个问题,它也曾导致损坏的数据库文件一次。我不得不重新进行设置。我建议您迁移到 RDS,因为它会为您提供更多稳定性,否则您必须自己负责管理 postgres 数据库。

关于Django 没有连接到 Elastic beanstalk 上的 PostGres,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30701548/

31 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com