问题设置Elastic Beanstalk实例 - 无法连接到服务器

时间:2015-05-08 00:32:41

标签: amazon-web-services elastic-beanstalk aws-ec2

我一直在尝试在AWS上设置网站,在运行eb initeb create并选择我的设置后没有遇到任何问题我遇到了以下错误:

  

错误:[实例:i-f8e3c005模块:AWSEBAutoScalingGroup配置:   null]命令在实例上失败。返回码:1输出:   (截断)... conn = _connect(dsn,   connection_factory = connection_factory,async = async)   django.db.utils.OperationalError:无法连接到服务器:   连接被拒绝服务器是否在主机上运行" localhost"   (127.0.0.1)并接受端口5432上的TCP / IP连接?

我不确定为什么拒绝连接,但我怀疑它与我的安全设置有关。我知道这有点模糊,但有没有人遇到过这个问题,你是怎么设法最终解决的?

完整输出如下:

INFO: createEnvironment is starting.
INFO: Using elasticbeanstalk-us-east-1-671186898336 as Amazon S3 storage bucket for environment data.
INFO: Created security group named: sg-96efb5f2
INFO: Created load balancer named: awseb-e-v-AWSEBLoa-12ABLMPELT72Q
INFO: Created security group named: awseb-e-v6mwzkkgjw-stack-AWSEBSecurityGroup-JEYPGZP3YJJG
INFO: Created Auto Scaling launch configuration named: awseb-e-v6mwzkkgjw-stack-AWSEBAutoScalingLaunchConfiguration-17DLMC0THMKW
INFO: Created Auto Scaling group named: awseb-e-v6mwzkkgjw-stack-AWSEBAutoScalingGroup-FBCJ1LFH8U38
INFO: Waiting for EC2 instances to launch. This may take a few minutes.
INFO: Created Auto Scaling group policy named: arn:aws:autoscaling:us-east-1:671186898336:scalingPolicy:9e2df788-3cee-4f47-917f-a11179972c69:autoScalingGroupName/awseb-e-v6mwzkkgjw-stack-AWSEBAutoScalingGroup-FBCJ1LFH8U38:policyName/awseb-e-v6mwzkkgjw-stack-AWSEBAutoScalingScaleDownPolicy-P6J45PB8N1XA
INFO: Created Auto Scaling group policy named: arn:aws:autoscaling:us-east-1:671186898336:scalingPolicy:e5a18684-1f95-446d-be29-ad560db7e3e6:autoScalingGroupName/awseb-e-v6mwzkkgjw-stack-AWSEBAutoScalingGroup-FBCJ1LFH8U38:policyName/awseb-e-v6mwzkkgjw-stack-AWSEBAutoScalingScaleUpPolicy-1IV5PENRNB785
INFO: Created CloudWatch alarm named: awseb-e-v6mwzkkgjw-stack-AWSEBCloudwatchAlarmHigh-K0258EMNK9O3
INFO: Created CloudWatch alarm named: awseb-e-v6mwzkkgjw-stack-AWSEBCloudwatchAlarmLow-15Z0Z4KVYDGEC
ERROR: [Instance: i-f8e3c005 Module: AWSEBAutoScalingGroup ConfigSet: null] Command failed on instance. Return code: 1 Output: (TRUNCATED)...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?. 
EBExtension container_command 01_migrate failed. For more detail, check /var/log/eb-activity.log using console or EB CLI.
INFO: Command execution completed on all instances. Summary: [Successful: 0, Failed: 1].
INFO: Added EC2 instance 'i-f8e3c005' to Auto Scaling Group 'awseb-e-v6mwzkkgjw-stack-AWSEBAutoScalingGroup-FBCJ1LFH8U38'.

更新:来自eb-activity.log的代码

 execute_from_command_line(sys.argv)
  File "/opt/python/run/venv/local/lib/python2.7/site-packages/django/core/management/__init__.py", line 385, in execute_from_command_line
  utility.execute()
  File "/opt/python/run/venv/local/lib/python2.7/site-packages/django/core/management/__init__.py", line 354, in execute
  django.setup()
  File "/opt/python/run/venv/local/lib/python2.7/site-packages/django/__init__.py", line 21, in setup
  apps.populate(settings.INSTALLED_APPS)
  File "/opt/python/run/venv/local/lib/python2.7/site-packages/django/apps/registry.py", line 108, in populate
  app_config.import_models(all_models)
  File "/opt/python/run/venv/local/lib/python2.7/site-packages/django/apps/config.py", line 202, in import_models
  self.models_module = import_module(models_module_name)
  File "/usr/lib64/python2.7/importlib/__init__.py", line 37, in import_module
  __import__(name)
  File "/opt/python/bundle/2/app/paypaladaptive/models.py", line 126, in <module>
  class Payment(PaypalAdaptive):
  File "/opt/python/bundle/2/app/paypaladaptive/models.py", line 178, in Payment
  def process(self, receivers, preapproval=None, **kwargs):

更新:

在尝试了尼克的建议后,我得到了同样的错误:

ERROR: [Instance: i-d05e9b2f Module: AWSEBAutoScalingGroup ConfigSet: null] Command failed on instance. Return code: 1 Output: (TRUNCATED)...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?. 
EBExtension container_command 01_migrate failed. For more detail, check /var/log/eb-activity.log using console or EB CLI.

2 个答案:

答案 0 :(得分:3)

简短版本:您的Django应用程序正在尝试连接到本地数据库实例。使用 RDS实例

您不能在Beanstalk节点本地拥有数据库实例(如PostgreSQL)。这是因为它在自动扩展的负载平衡应用程序上没有意义,根据您的服务负载创建和销毁节点(因此会破坏本地数据库实例)。

为了解决此问题,您需要使用自动扩展组外部且持久的AWS RDS实例。在您的设置中,使用主机用户名密码来创建RDS实例。请记住在分配给RDS实例的安全组上打开正确的端口(例如,对于PostgreSQL为5432)。

答案 1 :(得分:1)

看起来您的实例正在尝试通过端口5342连接自身。如果您需要此功能,可以打开端口5342以使其正常工作。

一种方法是使用.ebextensions。

在项目名称.ebextensions/openport.config中创建一个文件,并在其中加入以下内容。

Resources:
  databaseSecurityGroupIngress:
    Type: AWS::EC2::SecurityGroupIngress
    Properties:
      GroupName: {Ref : AWSEBSecurityGroup}
      IpProtocol: tcp
      ToPort: 5432
      FromPort: 5432
      CidrIp: 0.0.0.0/0

(如果需要,提交文件)然后尝试eb create