简体   繁体   English

部署到Elastic beantalk的Rails应用程序无法连接到RDS

[英]Deployed rails app to Elastic beanstalk can't connect to RDS

I'm trying to deploy my app to Elastic Beanstalk by following this tutorial . 我正按照本教程尝试将我的应用程序部署到Elastic Beanstalk。

The app works if I use splite3 , but I can't connect the app to RDS. 如果使用splite3 ,则该应用程序可以splite3 ,但无法将其连接到RDS。

I added group :production do gem 'mysql2' end in Gemfile, and this code to config/database.yml . 我在Gemfile中添加了group :production do gem 'mysql2' end gem'mysql2 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'] %>

I added RDS in Elastic Beanstalk console . 我在Elastic Beanstalk控制台中添加了RDS。

But production.log shows error, that indicates DB connection fails. 但是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 shows like this. eb status显示如下。

URL     : myAppURL
Status      : Ready
Health      : Green

RDS Database: AWSEBRDSDatabase | myDatabaseURL:port

Probably I miss something very basic. 可能我错过了一些非常基本的东西。 What should I do to fix this problem? 我应该怎么做才能解决这个问题?

If your database is not named ebdb you could hardcode your database name in the YAML file: 如果您的数据库未命名为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'] %>

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 使用弹性 beantalk 部署的 Rails 应用程序响应“站点无法访问” - Rails app deployed using elastic beanstalk responds with “site can't be reached” Heroku上的Rails应用程序无法连接到RDS - Rails App on Heroku Can't Connect to RDS 启动Ruby on Rails应用程序时,无法通过AWS Elastic Beanstalk“祝贺”屏幕 - can't get past AWS Elastic Beanstalk “Congratulations” screen when launching Ruby on Rails app AWS Elastic Beanstalk上的Rails应用返回“无法验证csrf令牌”的422 - Rails app on AWS Elastic Beanstalk returning 422 with “Can't verify csrf token” Elastic Beanstalk上的Rails,无法进行负载均衡器健康检查 - Rails on Elastic Beanstalk, Can't do a load balancer health check 使用Elastic Beanstalk进行Rails部署 - 无法将数组转换为字符串 - Rails Deploy using Elastic Beanstalk - Can't convert array into string Rails 6 无法连接到 AWS Elastic Beanstalk 预置的 RDS。 Unix 域套接字“/var/run/postgresql/.s.PGSQL.5432” - Rails 6 is unable to connect to AWS Elastic Beanstalk provisioned RDS. Unix domain socket "/var/run/postgresql/.s.PGSQL.5432" 弹性beanstalk:从一开始就使用postgres RDS创建rails env? - elastic beanstalk: create rails env with postgres RDS from beginning? 使用 Rails Elastic Beanstalk 上的 Ruby 将 RDS 迁移到 Aurora MySQL - Migrate RDS to Aurora MySQL with Ruby on rails Elastic Beanstalk Rails应用程序在本地运行,但在Elastic Beanstalk上崩溃 - Rails app runs locally but crashes on Elastic Beanstalk
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM