【问题标题】:Deployed rails app to Elastic beanstalk can't connect to RDS部署到 Elastic beanstalk 的 rails 应用程序无法连接到 RDS
【发布时间】:2014-03-06 20:49:31
【问题描述】:

我正在尝试通过关注this tutorial 将我的应用程序部署到 Elastic Beanstalk。

如果我使用splite3,应用程序可以工作,但我无法将应用程序连接到 RDS。

我在 Gemfile 中添加了group :production do gem 'mysql2' end,并将此代码添加到config/database.yml

production:
  adapter: mysql2
  encoding: utf8
  database: <%= ENV['RDS_DB_NAME'] %>
  username: <%= ENV['RDS_USERNAME'] %>
  password: <%= ENV['RDS_PASSWORD'] %>
  host: <%= ENV['RDS_HOSTNAME'] %>
  port: <%= ENV['RDS_PORT'] %>

我在Elastic Beanstalk console添加了RDS。

但是production.log显示错误,表示数据库连接失败。

-------------------------------------
/var/app/support/logs/production.log
-------------------------------------
I, [2014-02-09T16:01:56.520967 #29379]  INFO -- : Started GET "/" for xxx.xxx.xxx.xxx at 2014-02-09 16:01:56 +0000
I, [2014-02-09T16:01:56.620738 #29379]  INFO -- : Processing by PostsController#index as HTML
E, [2014-02-09T16:01:56.629835 #29379] ERROR -- : Mysql2::Error: Table 'ebdb.posts' doesn't exist: SELECT `posts`.* FROM `posts`
I, [2014-02-09T16:01:56.630802 #29379]  INFO -- :   Rendered posts/index.html.erb within layouts/application (4.3ms)
I, [2014-02-09T16:01:56.631068 #29379]  INFO -- : Completed 500 Internal Server Error in 10ms
F, [2014-02-09T16:01:56.633962 #29379] FATAL -- : 
ActionView::Template::Error (Mysql2::Error: Table 'ebdb.posts' doesn't exist: SELECT `posts`.* FROM `posts`):

eb status 显示如下。

URL     : myAppURL
Status      : Ready
Health      : Green

RDS Database: AWSEBRDSDatabase | myDatabaseURL:port

可能我错过了一些非常基本的东西。我应该怎么做才能解决这个问题?

【问题讨论】:

  • 您确实连接到 RDS,因为如果您无法连接,您的应用程序会在启动时崩溃。它只是找不到表。您可以连接到 RDS 并运行“使用您的数据库名称;”吗?和“显示表格”;看看?也许只是您的生产数据库中缺少迁移?
  • 您是在使用由 EB 进程创建的 RDS 实例,还是将您的 EB 应用程序连接到已经存在的 RDS 数据库?
  • 嘿!我有同样的问题......我已经设法连接到我的 RDS 数据库 vis Sequel 客户端的 SQL,并观察到数据库 'ebdb' 存在,但根本不包含任何表或内容!......我相信这一点你也可能是这种情况,所以一定是 Rails 迁移由于某种原因无法正常运行的问题......知道如何检查它们是否正在运行,手动运行它们,或者查看完成的 db_migrate 命令的输出在弹性豆茎环境中?

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


【解决方案1】:

如果您的数据库未命名为 ebdb,您可以在 YAML 文件中硬编码您的数据库名称:

production:
  adapter: mysql2
  encoding: utf8
  database: my_database_name
  username: <%= ENV['RDS_USERNAME'] %>
  password: <%= ENV['RDS_PASSWORD'] %>
  host: <%= ENV['RDS_HOSTNAME'] %>
  port: <%= ENV['RDS_PORT'] %>

【讨论】:

    猜你喜欢
    • 2015-05-07
    • 2016-08-24
    • 2021-03-01
    • 2016-01-09
    • 2021-02-14
    • 2019-07-24
    • 2013-03-18
    • 2013-04-03
    • 2019-03-07
    相关资源
    最近更新 更多