【问题标题】:Could not load database configuration. No such file - database.yml - OpsWorks无法加载数据库配置。没有这样的文件 - database.yml - OpsWorks
【发布时间】:2015-03-21 10:27:08
【问题描述】:

我第一次使用 OpsWorks (Ubuntu 14.04) 部署我的应用程序,并且在运行迁移时出现此错误:

无法加载数据库配置。没有这样的文件 - /srv/www/todoapp/releases/20150122121517/config/database.yml

我不明白这个错误,因为我的 rails 应用程序中有一个 /config/database.yml 并且被正确推送到 bitbucket。

你可以在这里看到我的 .gitignore 文件:

# If you find yourself ignoring temporary files generated by your text editor
# or operating system, you probably want to add a global ignore instead:
#   git config --global core.excludesfile '~/.gitignore_global'

# Ignore bundler config.
/.bundle

# Ignore the default SQLite database.
/db/*.sqlite3
/db/*.sqlite3-journal

# Ignore all logfiles and tempfiles.
/log/*.log
/tmp

【问题讨论】:

  • 您使用的是 Amazon RDS 数据库吗?
  • 不,我只是在使用 rails 实例

标签: mysql ruby-on-rails git ruby-on-rails-4 aws-opsworks


【解决方案1】:

我相信 Amazon Opsworks 会覆盖您的 database.yml 文件。您必须添加自定义 JSON 来配置您的生产数据库。

无论如何,这就是您的 JSON 应该是什么样子。

{
  "deploy": {
    "app_short_name": {  # this should be the short name Opsworks has given your app.
      "database": {
        "adapter": "postgresql", # change if you are using mysql
        "encoding": "unicode",
        "host": "your-host",
        "port": "5432", # change if you are using mysql
        "database": "your_database_name",
        "pool": "10",
        "username": "your_database_username",
        "password": "your_database_password"
      }
    }
  }
}

您可以在 Opsworks 堆栈设置中添加此项。

  • 登录您的 Opsworks
  • 点击左侧边栏上的Stack
  • 点击Stack settings按钮。
  • 您将在底部看到配置管理部分。您可以在此处添加自定义 JSON 以正确配置您的数据库。

以上设置适用于 Postgres 数据库配置。您可能需要使用 mysql 对其进行一些更改..

我使用 Amazon RDS postgres 数据库进行了此设置。 RDS也支持mysql。

希望这有助于您更接近部署应用程序。祝你好运。

【讨论】:

  • 在哪里可以找到主机、端口、数据库名称、用户名和密码?我只创建了 rails 实例,因为 opsworks 默认使用 mysql,然后我不知道在哪里可以找到所有这些属性。我的自定义 json 现在看起来像这样: { "deploy": { "ariadna": { "database": { "adapter": "mysql2" } } } }
  • 你更喜欢使用 Postgres 而不是 mysql?
  • 不,我更喜欢使用 mysql
  • 好吧,我建议您为您的数据库使用Amazon RDS instance。如果没有,您将不得不在您的服务器上创建一个数据库并使用名称、用户名/密码等进行设置。就像您在本地所做的一样。
  • 我有一个 Rails 应用程序,它没有拥有/使用数据库。没有数据库连接就无法部署 Rails 应用程序吗?我一直在我的 JSON 中提供 dummy/sqlite3 连接信息,但 AWS 显然不喜欢它/不使用它来制作 database.yml 文件,然后 Apache2 抱怨它无法读取 config/database.yml。有什么想法吗?
【解决方案2】:

对于使用 RDS 实例的任何人,请确保:

  • 创建一个RDS层(层>>添加层,RDS)
  • 向您的应用注册实例(应用>>编辑,数据源)

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2020-10-23
    • 2012-10-04
    • 1970-01-01
    • 2012-07-26
    • 1970-01-01
    • 2015-01-18
    • 1970-01-01
    • 2019-06-08
    相关资源
    最近更新 更多