Heroku 帮助部署使用 Mysql 数据库的 Rails 应用程序

发布于 2024-10-24 01:09:40 字数 696 浏览 1 评论 0原文

我正在尝试部署一个使用 Mysql 的 Rails 应用程序,

我已经:

  1. 创建了一个 Heroku 应用程序并将我的应用程序推送到了 heroku。

  2. 我已添加 Amazon RDS 我已创建一个 Amazon RDS 数据库实例。 我的 Heroku Amazon RDS 数据库 URL 为:mysql://mysusername:[电子邮件受保护]/mydatabasename

我的 Amazon RDS 数据库安全组设置为默认值

  1. 我尝试推送本地数据库,但出现以下错误 Heroku 帮助 Amazon RDS Rails 推送数据库错误

我做错了什么?

我的 Rdshostname 是什么?它是亚马逊端点吗?

I am trying to deploy a Rails app that uses Mysql

I have:

  1. Created a Heroku app and have pushed my app to heroku.

  2. I have added Amazon RDS I have created a Amazon RDS database instance.
    My Heroku Amazon RDS Database URL is: mysql://mysusername:[email protected]/mydatabasename

My Amazon RDS DB Security Group is set to default

  1. I have tried to push my local database but get the following error Heroku help Amazon RDS rails push database error

What am I doing wrong ?

What is my Rdshostname? Is it the Amazon endpoint?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

青衫负雪 2024-10-31 01:09:40

我只想首先说我感受到你的痛苦。我最近是 Rails 3 + Heroku + Amazon RDS 的新手。但是,今晚我解决了这个问题,并立即在 Stack Overflow 上让其他遇到问题的人知道如何解决。我稍后会在博客上介绍它。

您可能会跳过其中的一些内容,但我会尽力在此处提供全面的答复,包括您需要采取的步骤以及我遇到的问题和问题。

问题#1: heroku 无法安装 mysql2 gem,并出现以下错误:

       You have added to the Gemfile:
      * mysql2
      FAILED: http://devcenter.heroku.com/articles/bundler
!     Heroku push rejected, failed to install gems via Bundler

解决方案: 我几乎总是使用 PostgreSQL 来处理我正在处理的任何要求较高的任务以及沙箱和实验,我只需使用 SQLite3 即可快速进出。真正的问题是我没有在本地计算机上运行 MySQL。当我回来并尝试在本地运行bundle install时,gem 安装自然会失败,因为它找不到 mysql 库。我确信有办法解决这个问题,但我只是硬着头皮在本地安装了mysql。之后,我可以毫无问题地运行bundle install。另外,git push heroku master 将应用程序推送到 Heroku,没有失败:

   Installing activerecord (3.0.6) 
   Installing activeresource (3.0.6) 
   >>>>Installing mysql2 (0.3.2) with native extensions<<<< 
   Using bundler (1.0.7) 
   Installing thor (0.14.6) 
   Installing railties (3.0.6) 
   Installing rails (3.0.6) 
   Installing sqlite3 (1.3.3) with native extensions 
   Your bundle is complete! It was installed into ./.bundle/gems/
   Compiled slug size is 3.9MB
   -----> Launching... done
   http://myapp.heroku.com deployed to Heroku

问题 #2: 即使在安装了 mysql2 gem 后,我的应用程序也卡住了。 heroku 日志透露:

RuntimeError (!!! Missing the mysql2 gem. Add it to your Gemfile: gem 'mysql2'):

什么?我刚刚将其添加到我的 gemfile 中,提交并成功推送!我真的以为有人在跟我开一个下流的玩笑。一些研究和摆弄发现heroku rake db:migrate正在返回:

WARNING: This version of mysql2 (0.3.2) doesn't ship with the ActiveRecord adapter bundled anymore as it's now part of Rails 3.1
WARNING: Please use the 0.2.x releases if you plan on using it in Rails <= 3.0.x

解决方案:我使用gem uninstall mysql2卸载了mysql2 gem,然后将我的 gemfile 中的行修改为:

gem 'mysql2', '< 0.3'

这安装了 mysql2 gem 的 0.2.7 版本,它也成功安装在 Heroku 上。

问题#3:安装正确版本的 mysql2 gem 后,heroku rake db:migrate 仍然返回相同的错误:

rake aborted!
!!! Missing the mysql2 gem. Add it to your Gemfile: gem 'mysql2'

好的,所以我做了更多研究,发现此帖子,它基本上告诉我:该适配器尝试使用“mysql”适配器而不是“mysql2”适配器。

解决方案:解决这个问题的方法是在heroku config中手动设置DATABASE_URL以使用mysql2://通过执行以下操作:(

heroku config:add DATABASE_URL=mysql2://user:[email protected]/databaseName

您可以通过单击您正在使用的数据库在 AWS 配置面板中找到此 URL 的“dbInstanceName.hostname.us-east-1.amazonaws.com”部分)

这必须使用以下命令来完成line 工具,并且无法使用 Web 控制面板上的 RDS 附加 GUI 进行添加,因为 Heroku 不会接受它作为有效的数据库 URL。

陷阱#4:不正确的安全配置不会返回信息性或有用的错误。

解决方案:确保您已将安全组添加到 RDS 配置中,以允许 Heroku 访问您的 RDS 实例,并将该安全组添加到您的实例中。如需执行此操作的 CLI 帮助,您可以查看 Heroku 上的 RDS 文档 或登录到 AWS 控制台并执行以下操作此:

  1. 单击顶部的 RDS 选项卡。
  2. 单击左列中的数据库安全组
  3. 单击“创建数据库安全组”
  4. 输入名称和描述(例如:名称:Heroku,描述:允许 Heroku 访问!”)
  5. 在下部面板中,选择新组后,创建一个通过从下拉列表中选择“EC2 安全组”
  6. ,输入:“默认”并输入 AWS 账户 ID:“098166147350”(这很重要;此帐号属于 Heroku,必须添加)。到默认安全组才能工作。)
  7. 单击“添加”
  8. 重要!修改现有数据库并向其中添加新安全组

因此,回顾一下,如果您已经:

  1. 安装了正确版本的 mysql2 gem(< ;0.3)
  2. 通过正确设置 DATABASE_URL 设置 Heroku 配置以使用 mysql2 适配器,
  3. 并通过在 AWS RDS 上创建适当的安全组并将该安全组添加到您的数据库来确保 Heroku 可以访问您的 RDS,

您现在应该能够。将 RDS 与 Heroku 上的 Rails 3 应用程序一起使用:)

I just wanted to first say that I feel your pain. I was recently a complete newbie to Rails 3 + Heroku + Amazon RDS. But, tonight I conquered the problem and immediately got on Stack Overflow to let others who were having issues know how. I'll blog about it later.

Some of this, you might skip, but I'll try to be comprehensive in my response here, including steps you'll need to take as well as gotchas and issues I encountered as well.

Gotcha #1: heroku fails to install mysql2 gem with the following error:

       You have added to the Gemfile:
      * mysql2
      FAILED: http://devcenter.heroku.com/articles/bundler
!     Heroku push rejected, failed to install gems via Bundler

Solution: I almost always use PostgreSQL for anything demanding I am working on and for sandboxes and experiments, I just use SQLite3 to get in and out fast. The real issue was that I wasn't running MySQL on my local machine. When I came back and tried to run the bundle install locally, naturally the gem install failed because it could not find the mysql libraries. I'm sure there is a way around this, but I just bit the bullet and installed mysql locally. Afterwards, I was able to run bundle install with no problem. Also, git push heroku master pushed the application to Heroku with no failure:

   Installing activerecord (3.0.6) 
   Installing activeresource (3.0.6) 
   >>>>Installing mysql2 (0.3.2) with native extensions<<<< 
   Using bundler (1.0.7) 
   Installing thor (0.14.6) 
   Installing railties (3.0.6) 
   Installing rails (3.0.6) 
   Installing sqlite3 (1.3.3) with native extensions 
   Your bundle is complete! It was installed into ./.bundle/gems/
   Compiled slug size is 3.9MB
   -----> Launching... done
   http://myapp.heroku.com deployed to Heroku

Gotcha #2: My application choked, even after installing the mysql2 gem. heroku logs revealed:

RuntimeError (!!! Missing the mysql2 gem. Add it to your Gemfile: gem 'mysql2'):

What? I just added that to my gemfile, committed it and pushed it sucessfully! I really thought someone was playing a nasty joke on me. A little research and fiddling revealed that a heroku rake db:migrate was returning:

WARNING: This version of mysql2 (0.3.2) doesn't ship with the ActiveRecord adapter bundled anymore as it's now part of Rails 3.1
WARNING: Please use the 0.2.x releases if you plan on using it in Rails <= 3.0.x

Solution: I uninstalled the mysql2 gem with gem uninstall mysql2 and then modified the line in my gemfile to read:

gem 'mysql2', '< 0.3'

This installed the 0.2.7 version of the mysql2 gem, which also installed on Heroku sucessfully.

Gotcha #3: After installing the correct version of the mysql2 gem, a heroku rake db:migrate still returned the same error:

rake aborted!
!!! Missing the mysql2 gem. Add it to your Gemfile: gem 'mysql2'

Okay, so I did some more research and found this thread, which basically told me that the adapter was trying to use the "mysql" adapter instead of the "mysql2" adapter.

Solution: The way around this one is to manually set the DATABASE_URL in heroku config to use mysql2:// by doing this:

heroku config:add DATABASE_URL=mysql2://user:[email protected]/databaseName

(you can find the "dbInstanceName.hostname.us-east-1.amazonaws.com" portion of this url in your AWS config panel by clicking on the database you are using)

This has to be done using the command line tool, and cannot be added using the RDS Add-on GUI on the web control panel, because Heroku won't accept it as a valid db URL there.

Gotcha #4: Incorrect security configurations will not return informative or useful errors.

Solution: Ensure that you have added a security group to your RDS configuration to allow Heroku to access your RDS instance and added that security group to your instance. For CLI help doing this you can view the RDS docs on Heroku or login to your AWS console and do this:

  1. Click on RDS tab at the top.
  2. Click on DB Security Groups in the left column
  3. Click "Create DB Security Group"
  4. Enter a name and a description (ex: Name: Heroku, Description: Allow Heroku Access!")
  5. In the lower panel, with the new group selected, create a new authorization by selecting "EC2 Security Group" from the dropdown.
  6. For Security Group, enter: "default" and AWS Account ID, enter: "098166147350" (This is important; this account number belongs to Heroku, and it it must be added to the default security group in order to work.)
  7. Click "Add"
  8. IMPORTANT! Modify the existing database and add the new security group to it.

So, to recap, if you've:

  1. Installed the correct version of the mysql2 gem (<0.3)
  2. Setup your heroku configuration to use the mysql2 adapter by setting the DATABASE_URL correctly.
  3. and ensured that Heroku has access to your RDS by creating the appropriate security group on AWS RDS and added that security group to your database,

You should now be able to use RDS with your Rails 3 app on heroku. :)

初与友歌 2024-10-31 01:09:40
  1. 将您的应用程序推送到 heroku(不要忘记包含 gem taps)
  2. 添加插件 Amazon RDS
  3. 在 Amazon RDS 中创建数据库实例
  4. 进入安全组并在 Heroku 帮助 Amazon RDS Rails 推送数据库错误
  5. 您的端点 URL 是您的 rdshostname,没有 .amazonaws.com
  6. 登录到 heroku 并转到到 Amazon RDS 插件并添加 mysql://mysusername:[电子邮件受保护]/数据库名
  1. Push your app to heroku (Dont forget to include gem taps)
  2. Add plugin Amazon RDS
  3. Create a database instance in Amazon RDS
  4. Go into the security group and add the following in this answer in Heroku help Amazon RDS rails push database error
  5. Your Endpoint url is your rdshostname without the .amazonaws.com
  6. Login to heroku and go into the Amazon RDS plugin and add mysql://mysusername:[email protected]/databasename
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文