【问题标题】:AWS Database Migration Error while deploying ruby on rails app on Elastic Beanstalk Environment在 Elastic Beanstalk 环境上部署 ruby​​ on rails 应用程序时出现 AWS 数据库迁移错误
【发布时间】:2018-08-26 06:28:11
【问题描述】:

当我尝试通过 AWS Elastic Beanstalk 环境部署我的 RoR 应用程序时,我在控制台上收到以下错误:

ERROR: [Instance: i-0c1d25d2a182d8424] Command failed on instance. Return code: 1 Output: (TRUNCATED)...ly and accepting
    connections on Unix domain socket "/var/run/postgresql/.s.PGSQL.5432"?
/opt/rubies/ruby-2.5.0/bin/bundle:23:in `load'
/opt/rubies/ruby-2.5.0/bin/bundle:23:in `<main>'
Tasks: TOP => db:migrate
(See full trace by running task with --trace). 
Hook /opt/elasticbeanstalk/hooks/appdeploy/pre/12_db_migration.sh 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].
ERROR: Unsuccessful command execution on instance id(s) 'i-0c1d25d2a182d8424'. Aborting the operation.
ERROR: Failed to deploy application.  

以下是我在database.yml中的配置

production:
  <<: *default
  database: <%= ENV['RDS_DB_NAME'] %>
  username: <%= ENV['RDS_USERNAME'] %>
  host: <%= ENV['RDS_HOSTNAME'] %>
  password: <%= ENV['RDS_PASSWORD'] %>
  port: <%= ENV['RDS_PORT'] %>

以下是日志中报告的错误:

  ++ export RUBY_ROOT=/opt/rubies/ruby-2.5.0
  ++ RUBY_ROOT=/opt/rubies/ruby-2.5.0
  ++ export RUBYOPT=
  ++ RUBYOPT=
  ++ export PATH=/opt/rubies/ruby-2.5.0/bin:/opt/elasticbeanstalk/lib/ruby/bin:/usr/local/sbin:/usr/local/bin:/usr/bin:/usr/sbin:/sbin:/bin
  ++ PATH=/opt/rubies/ruby-2.5.0/bin:/opt/elasticbeanstalk/lib/ruby/bin:/usr/local/sbin:/usr/local/bin:/usr/bin:/usr/sbin:/sbin:/bin
  +++ /opt/rubies/ruby-2.5.0/bin/ruby -
  ++ eval 'export RUBY_ENGINE=ruby;
  export RUBY_VERSION=2.5.0;
  export GEM_ROOT="/opt/rubies/ruby-2.5.0/lib/ruby/gems/2.5.0";'
  +++ export RUBY_ENGINE=ruby
  +++ RUBY_ENGINE=ruby
  +++ export RUBY_VERSION=2.5.0
  +++ RUBY_VERSION=2.5.0
  +++ export GEM_ROOT=/opt/rubies/ruby-2.5.0/lib/ruby/gems/2.5.0
  +++ GEM_ROOT=/opt/rubies/ruby-2.5.0/lib/ruby/gems/2.5.0
  ++ ((  0 != 0  ))
  + cd /var/app/ondeck
  + su -s /bin/bash -c 'bundle exec /opt/elasticbeanstalk/support/scripts/check-for-rake-task.rb db:migrate' webapp
  `/home/webapp` is not a directory.
  Bundler will use `/tmp/bundler/home/webapp' as your home directory temporarily.
  + '[' false = true ']'
  + su -s /bin/bash -c 'leader_only bundle exec rake db:migrate' webapp
  `/home/webapp` is not a directory.
  Bundler will use `/tmp/bundler/home/webapp' as your home directory temporarily.
  rake aborted!
  PG::ConnectionBad: could not connect to server: No such file or directory
    Is the server running locally and accepting
    connections on Unix domain socket "/var/run/postgresql/.s.PGSQL.5432"?
  /opt/rubies/ruby-2.5.0/bin/bundle:23:in `load'
  /opt/rubies/ruby-2.5.0/bin/bundle:23:in `<main>'
  Tasks: TOP => db:migrate
  (See full trace by running task with --trace) (Executor::NonZeroExitStatus) 

另外,rake db:migrate 在本地也能正常工作。我不知道这里会发生什么,对于数据库,我尝试导入我已经在 AWS RDS 上拥有的数据库实例的快照,但我也尝试创建一个新数据库。

如果您对这里可能发生的事情有任何想法,如果您能告诉我,将不胜感激。

提前致谢。

【问题讨论】:

  • Postgres 可能在 Beanstalk EC2 实例上死亡。例如,在this 答案中,用户尝试手动启动postgres。您可以尝试添加一个带有command.ebextension 配置,“postgres -D which postgres”,基本上,以确保postgres 在您的应用程序启动之前启动?
  • 您是否为RDS_HOSTNAMERDS_PORT 设置了正确的值?您可以连接 EC2 实例中的数据库吗?
  • @Tai 我在哪里设置这些值?我虽然这些是由 Elastic Beans 自动传递的。

标签: ruby-on-rails postgresql amazon-web-services amazon-s3 amazon-elastic-beanstalk


【解决方案1】:

作为您的评论,我相信您错过了在 Elastic Beanstalk 中配置 RDS_*。要解决这个问题:

  1. 要配置所有 RDS_*,请在此处遵循此指南:https://docs.aws.amazon.com/elasticbeanstalk/latest/dg/environments-cfg-softwaresettings.html#environments-cfg-softwaresettings-console
  2. 重新部署您的应用程序。

【讨论】:

  • 谢谢。我尝试添加参数,但我不断收到相同的错误。关于可能导致它的任何其他想法?
  • 请张贴 /var/log/eb-activity.log
  • 和我在@tai的问题里发的一样
  • 如果您正确设置变量,eb-activity.log 将包含您的变量,例如:+++ export RDS_DB_NAME=application +++ RDS_DB_NAME=application
  • 在 UI 中设置变量并不总是有效,通常通过 CLI 设置它们@Tai
猜你喜欢
  • 2021-04-09
  • 2017-03-04
  • 2018-12-03
  • 2012-04-05
  • 2013-02-20
  • 2012-09-24
  • 2018-06-19
  • 2019-09-25
  • 2015-07-06
相关资源
最近更新 更多