无法从我的Django Web应用程序连接到Amazon RDS Postgres数据库

我正在尝试使用弹性beantalk部署网站并将其连接到Postgres数据库。尝试在Django中进行迁移时,出现错误。

我已经能够成功建立本地Postgres数据库。我已经尝试了一段时间没有运气。

这是错误日志

(venv) C:\Users\dania\Development\Cliquefit>python manage.py makemigrations
Traceback (most recent call last):
  File "C:\Users\dania\Development\Cliquefit\venv\lib\site-packages\django\db\backends\base\base.py", line 217, in ensure_connection
    self.connect()
  File "C:\Users\dania\Development\Cliquefit\venv\lib\site-packages\django\db\backends\base\base.py", line 195, in connect
    self.connection = self.get_new_connection(conn_params)
  File "C:\Users\dania\Development\Cliquefit\venv\lib\site-packages\django\db\backends\postgresql\base.py", line 178, in get_new_connection
    connection = Database.connect(**conn_params)
  File "C:\Users\dania\Development\Cliquefit\venv\lib\site-packages\psycopg2\__init__.py", line 127, in connect
    conn = _connect(dsn, connection_factory=connection_factory, **kwasync)
psycopg2.OperationalError: could not connect to server: Connection timed out (0x0000274C/10060)     
        Is the server running on host "cliquefit.c8lfjtthzko9.ap-southeast-2.rds.amazonaws.com" (13.239.177.165) and accepting
        TCP/IP connections on port 5432?


The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "manage.py", line 15, in <module>
    execute_from_command_line(sys.argv)
  File "C:\Users\dania\Development\Cliquefit\venv\lib\site-packages\django\core\management\__init__.py", line 381, in execute_from_command_line
    utility.execute()
  File "C:\Users\dania\Development\Cliquefit\venv\lib\site-packages\django\core\management\__init__.py", line 375, in execute
    self.fetch_command(subcommand).run_from_argv(self.argv)
  File "C:\Users\dania\Development\Cliquefit\venv\lib\site-packages\django\core\management\base.py", line 323, in run_from_argv
    self.execute(*args, **cmd_options)
  File "C:\Users\dania\Development\Cliquefit\venv\lib\site-packages\django\core\management\base.py", line 364, in execute
    output = self.handle(*args, **options)
  File "C:\Users\dania\Development\Cliquefit\venv\lib\site-packages\django\core\management\base.py", line 83, in wrapped
    res = handle_func(*args, **kwargs)
  File "C:\Users\dania\Development\Cliquefit\venv\lib\site-packages\django\core\management\commands\makemigrations.py", line 101, in handle
    loader.check_consistent_history(connection)
  File "C:\Users\dania\Development\Cliquefit\venv\lib\site-packages\django\db\migrations\loader.py", line 283, in check_consistent_history
    applied = recorder.applied_migrations()
  File "C:\Users\dania\Development\Cliquefit\venv\lib\site-packages\django\db\migrations\recorder.py", line 73, in applied_migrations
    if self.has_table():
  File "C:\Users\dania\Development\Cliquefit\venv\lib\site-packages\django\db\migrations\recorder.py", line 56, in has_table
    return self.Migration._meta.db_table in self.connection.introspection.table_names(self.connection.cursor())
  File "C:\Users\dania\Development\Cliquefit\venv\lib\site-packages\django\db\backends\base\base.py", line 256, in cursor
    return self._cursor()
  File "C:\Users\dania\Development\Cliquefit\venv\lib\site-packages\django\db\backends\base\base.py", line 233, in _cursor
    self.ensure_connection()
  File "C:\Users\dania\Development\Cliquefit\venv\lib\site-packages\django\db\backends\base\base.py", line 217, in ensure_connection
    self.connect()
  File "C:\Users\dania\Development\Cliquefit\venv\lib\site-packages\django\db\utils.py", line 89, in __exit__
    raise dj_exc_value.with_traceback(traceback) from exc_value
  File "C:\Users\dania\Development\Cliquefit\venv\lib\site-packages\django\db\backends\base\base.py", line 217, in ensure_connection
    self.connect()
  File "C:\Users\dania\Development\Cliquefit\venv\lib\site-packages\django\db\backends\base\base.py", line 195, in connect
    self.connection = self.get_new_connection(conn_params)
  File "C:\Users\dania\Development\Cliquefit\venv\lib\site-packages\django\db\backends\postgresql\base.py", line 178, in get_new_connection
    connection = Database.connect(**conn_params)
  File "C:\Users\dania\Development\Cliquefit\venv\lib\site-packages\psycopg2\__init__.py", line 127, in connect
    conn = _connect(dsn, connection_factory=connection_factory, **kwasync)
django.db.utils.OperationalError: could not connect to server: Connection timed out (0x0000274C/10060)
        Is the server running on host "cliquefit.c8lfjtthzko9.ap-southeast-2.rds.amazonaws.com" (13.239.177.165) and accepting
        TCP/IP connections on port 5432?

这是我的项目.settings.py文件的数据库部分:

from .base import *    
DEBUG = config('DEBUG', cast=bool)
ALLOWED_HOSTS = ['localhost', '127.0.0.1','http://cliquefit-dev.ap-southeast-2.elasticbeanstalk.com','*******']


AUTH_PASSWORD_VALIDATORS = [
    {'NAME': 'django.contrib.auth.password_validation.UserAttributeSimilarityValidator'},
    {'NAME': 'django.contrib.auth.password_validation.MinimumLengthValidator'},
    {'NAME': 'django.contrib.auth.password_validation.CommonPasswordValidator'},
    {'NAME': 'django.contrib.auth.password_validation.NumericPasswordValidator'}
]



DATABASES = {
    'default': {
        'ENGINE': 'django.db.backends.postgresql',
        'NAME': 'cliquefit',
        'USER': '******',
        'PASSWORD': '*********',
        'HOST': 'cliquefit.*********.ap-southeast-2.rds.amazonaws.com',
        'PORT': '5432'
    }
}

这是我的Django配置文件

Container_commands:
  01_makemigrations:
    command: "source /opt/python/run/venv/bin/activate && python manage.py makemigrations"
    leader_only: true
  02_migrate:
    command: "source /opt/python/run/venv/bin/activate && python manage.py migrate --noinput"
    leader_only: true
  03_createsu:
    command: "source /opt/python/run/venv/bin/activate && python manage.py createsu"
    leader_only: true
  04_collectstatic:
    command: "source /opt/python/run/venv/bin/activate && python manage.py collectstatic --noinput"
    leader_only: true

option_settings:
  aws:elasticbeanstalk:application:environment:
    DJANGO_SETTINGS_MODULE: cliquefit.settings.base
  aws:elasticbeanstalk:container:python:
    WSGIPath: "cliquefit/wsgi.py"

packages:
    yum:
        httpd24-devel: []

还有我的requirements.txt

appdirs==1.4.4
autopep8==1.4.4
awsebcli==3.18.2
botocore==1.15.49
cassandra-driver==3.24.0
cement==2.8.2
certifi==2019.3.9
chardet==3.0.4
click==7.1.2
colorama==0.4.3
defusedxml==0.6.0
distlib==0.3.1
Django==2.2
django-allauth==0.39.1
django-countries==5.3.3
django-crispy-forms==1.7.2
django-debug-toolbar==1.10.1
docutils==0.15.2
filelock==3.0.12
future==0.16.0
geomet==0.2.1.post1
idna==2.7
importlib-metadata==1.7.0
importlib-resources==3.0.0
jmespath==0.10.0
mod-wsgi==4.7.1
oauthlib==3.0.1
pathspec==0.5.9
pep8==1.7.1
Pillow==6.2.2
psycopg2-binary==2.8.5
pycodestyle==2.5.0
python-dateutil==2.8.0
python-decouple==3.1
python-slugify==4.0.1
python3-openid==3.1.0
pytz==2018.5
PyYAML==5.3.1
requests==2.20.1
requests-oauthlib==1.2.0
semantic-version==2.5.0
six==1.11.0
slugify==0.0.1
sqlparse==0.2.4
stripe==2.27.0
termcolor==1.1.0
text-unidecode==1.3
urllib3==1.24.2
virtualenv==20.0.30
wcwidth==0.1.9
zipp==3.1.0

我尝试修复数据库凭证并在Amazon RDS上创建新的数据库实例,但是不幸的是没有运气。

谢谢您的帮助!

编辑:有关更多信息,我从尝试将此代码部署到弹性beantalk时添加了错误日志

Printing Status:
2020-08-16 10:33:18    INFO    createEnvironment is starting.
2020-08-16 10:33:19    INFO    Using elasticbeanstalk-ap-southeast-2-369458984841 as Amazon S3 storage bucket for environment data.
2020-08-16 10:33:40    INFO    Created security group named: sg-049f4a122d881069e
2020-08-16 10:33:43    INFO    Created load balancer named: awseb-e-f-AWSEBLoa-UWLA7I0LF6WN
2020-08-16 10:33:58    INFO    Created security group named: awseb-e-f9zthb6x58-stack-AWSEBSecurityGroup-UXKL3CPFGSVJ
2020-08-16 10:33:58    INFO    Created Auto Scaling launch configuration named: awseb-e-f9zthb6x58-stack-AWSEBAutoScalingLaunchConfiguration-UB2HYII1KHCR
2020-08-16 10:34:46    INFO    Created Auto Scaling group named: awseb-e-f9zthb6x58-stack-AWSEBAutoScalingGroup-1EGDGJYCTFOFQ
2020-08-16 10:34:46    INFO    Waiting for EC2 instances to launch. This may take a few minutes.
2020-08-16 10:35:01    INFO    Created Auto Scaling group policy named: arn:aws:autoscaling:ap-southeast-2:369458984841:scalingPolicy:5681f42e-9672-4f68-8566-fe465044ea90:autoScalingGroupName/awseb-e-f9zthb6x58-stack-AWSEBAutoScalingGroup-1EGDGJYCTFOFQ:policyName/awseb-e-f9zthb6x58-stack-AWSEBAutoScalingScaleUpPolicy-TLZXCZ8CV6Q2
2020-08-16 10:35:01    INFO    Created Auto Scaling group policy named: arn:aws:autoscaling:ap-southeast-2:369458984841:scalingPolicy:13bc6e9d-fd8f-4a12-a2bd-74f036335481:autoScalingGroupName/awseb-e-f9zthb6x58-stack-AWSEBAutoScalingGroup-1EGDGJYCTFOFQ:policyName/awseb-e-f9zthb6x58-stack-AWSEBAutoScalingScaleDownPolicy-JUL92X7VVS7T
2020-08-16 10:35:01    INFO    Created CloudWatch alarm named: awseb-e-f9zthb6x58-stack-AWSEBCloudwatchAlarmHigh-KVUMT41RNBO5
2020-08-16 10:35:01    INFO    Created CloudWatch alarm named: awseb-e-f9zthb6x58-stack-AWSEBCloudwatchAlarmLow-131ZV7XJVRICW
2020-08-16 10:36:03    ERROR   [Instance: i-0bf7de5ced912896c] Command failed on instance. Return code: 1 Output: (TRUNCATED)... in complain
raise ImproperlyConfigured("settings.DATABASES is improperly configured. "
django.core.exceptions.ImproperlyConfigured: settings.DATABASES is improperly configured. Please supply the ENGINE value. Check settings documentation for more details.
container_command 02_migrate in .ebextensions/django.config failed. For more detail, check /var/log/eb-activity.log using console or EB CLI.
2020-08-16 10:36:03    INFO    Command execution completed on all instances. Summary: [Successful: 0, Failed: 1].
2020-08-16 10:37:06    ERROR   Create environment operation is complete, but with errors. For more information, see troubleshooting documentation.

现在包括安全组的屏幕快照:[1]:https : //i.stack.imgur.com/4LEfH.jpg

马辛

基于评论和其他信息。

5432端口的入站规则设置为安全组sg-597这仅允许来自具有相同sg的其他实例的入站流量,而不允许来自Internet的入站流量

为了能够从互联网访问rds,必须使用特定的IP范围或地址(例如1.2.3.4/32)0.0.0.0/0作为源(即所有源位置),或者更好范围可以是您的工作或家庭公用网络的范围,而IP可以是工作站的特定地址。

本文收集自互联网,转载请注明来源。

如有侵权,请联系[email protected] 删除。

编辑于
0

我来说两句

0条评论
登录后参与评论

相关文章

来自分类Dev

如何使用Php将我的Android应用程序连接到Amazon RDS MySQL数据库?

来自分类Dev

Amazon RDS postgres数据已擦除并且无法连接到数据库?

来自分类Dev

boxfuse应用程序无法连接到RDS数据库

来自分类Dev

boxfuse应用程序无法连接到RDS数据库

来自分类Dev

Amazon RDS无法连接到数据库

来自分类Dev

Amazon RDS无法连接到数据库

来自分类Dev

如何使用Php将Android应用程序连接到Amazon RDS MySQL数据库?

来自分类Dev

AWS:无法从我的机器连接到RDS数据库

来自分类Dev

HeidiSQL无法连接到我的RDS数据库?

来自分类Dev

如何将EC2中的Django连接到RDS中的Postgres数据库?

来自分类Dev

无法连接到 AWS-RDS MySql 数据库

来自分类Dev

我的 Django 应用程序无法通过 TypeError 连接到数据库

来自分类Dev

AWS ElasticBeanstalk上的Laravel应用程序未连接到RDS数据库

来自分类Dev

无法通过RDS代理连接到RDS PostgreSQL数据库实例

来自分类Dev

使用sequelize ORM连接到node.js上的Amazon RDS Postgres数据库的问题

来自分类Dev

从Azure连接到Amazon RDS上的Postgres数据库的超时

来自分类Dev

从 Node.js 应用程序连接到通过 Amazon 上的 RDS 托管的 postgres 时出现超时错误

来自分类Dev

无法使用Docker连接我的postgres数据库

来自分类Dev

由于数据库所有权差异,无法还原Django应用程序的Postgres数据库

来自分类Dev

Amazon RDS登台与生产数据库

来自分类Dev

Hyperledger Iroha 无法连接到 postgres 数据库?

来自分类Dev

无法使用Sequelize从本地节点应用程序连接到Heroku Postgresql数据库

来自分类Dev

无法使用Node.js(OpenShift应用程序)连接到MySQL数据库

来自分类Dev

无法从Vibed应用程序连接到MySQL / MariaDB数据库

来自分类Dev

无法使用Rails应用程序连接到sqlite3数据库

来自分类Dev

无法在Android应用程序中连接到在线数据库

来自分类Dev

Maven 应用程序无法连接到数据库服务器

来自分类Dev

Elastic Beanstalk 应用程序无法连接到数据库,但服务器可以

来自分类Dev

无法从 RHEL 7 上的 .Net 核心应用程序连接到 SQL Server 数据库

Related 相关文章

  1. 1

    如何使用Php将我的Android应用程序连接到Amazon RDS MySQL数据库?

  2. 2

    Amazon RDS postgres数据已擦除并且无法连接到数据库?

  3. 3

    boxfuse应用程序无法连接到RDS数据库

  4. 4

    boxfuse应用程序无法连接到RDS数据库

  5. 5

    Amazon RDS无法连接到数据库

  6. 6

    Amazon RDS无法连接到数据库

  7. 7

    如何使用Php将Android应用程序连接到Amazon RDS MySQL数据库?

  8. 8

    AWS:无法从我的机器连接到RDS数据库

  9. 9

    HeidiSQL无法连接到我的RDS数据库?

  10. 10

    如何将EC2中的Django连接到RDS中的Postgres数据库?

  11. 11

    无法连接到 AWS-RDS MySql 数据库

  12. 12

    我的 Django 应用程序无法通过 TypeError 连接到数据库

  13. 13

    AWS ElasticBeanstalk上的Laravel应用程序未连接到RDS数据库

  14. 14

    无法通过RDS代理连接到RDS PostgreSQL数据库实例

  15. 15

    使用sequelize ORM连接到node.js上的Amazon RDS Postgres数据库的问题

  16. 16

    从Azure连接到Amazon RDS上的Postgres数据库的超时

  17. 17

    从 Node.js 应用程序连接到通过 Amazon 上的 RDS 托管的 postgres 时出现超时错误

  18. 18

    无法使用Docker连接我的postgres数据库

  19. 19

    由于数据库所有权差异,无法还原Django应用程序的Postgres数据库

  20. 20

    Amazon RDS登台与生产数据库

  21. 21

    Hyperledger Iroha 无法连接到 postgres 数据库?

  22. 22

    无法使用Sequelize从本地节点应用程序连接到Heroku Postgresql数据库

  23. 23

    无法使用Node.js(OpenShift应用程序)连接到MySQL数据库

  24. 24

    无法从Vibed应用程序连接到MySQL / MariaDB数据库

  25. 25

    无法使用Rails应用程序连接到sqlite3数据库

  26. 26

    无法在Android应用程序中连接到在线数据库

  27. 27

    Maven 应用程序无法连接到数据库服务器

  28. 28

    Elastic Beanstalk 应用程序无法连接到数据库,但服务器可以

  29. 29

    无法从 RHEL 7 上的 .Net 核心应用程序连接到 SQL Server 数据库

热门标签

归档