在弹性 beantalk 上部署 rails 应用程序时出错(生产模式)

Posted

技术标签:

【中文标题】在弹性 beantalk 上部署 rails 应用程序时出错(生产模式)【英文标题】:Error deploying rails app on elastic beanstalk (production mode) 【发布时间】:2013-12-10 09:46:06 【问题描述】:

我遇到了阻止我在 Amazon EB 上的应用程序的错误(弹性 beantalk 无法启动)......查看日志后,这是唯一看起来有错误的部分......请注意提到的部分mysql

-------------------------------------
/var/app/support/logs/production.log
-------------------------------------
  passenger (4.0.20) lib/phusion_passenger/request_handler/thread_handler.rb:108:in `main_loop'
  passenger (4.0.20) lib/phusion_passenger/request_handler.rb:441:in `block (3 levels) in start_threads'


I, [2013-11-25T15:15:27.080960 #10181]  INFO -- : Started GET "/" for 212.49.88.109 at 2013-11-25 15:15:27 +0000
F, [2013-11-25T15:15:27.093868 #10181] FATAL -- : 
Mysql2::Error (Host 'ip-10-72-151-230.eu-west-1.compute.internal' is blocked because of many connection errors; unblock with 'mysqladmin flush-hosts'):
  mysql2 (0.3.13) lib/mysql2/client.rb:58:in `connect'
  mysql2 (0.3.13) lib/mysql2/client.rb:58:in `initialize'
  activerecord (4.0.0) lib/active_record/connection_adapters/mysql2_adapter.rb:18:in `new'
  activerecord (4.0.0) lib/active_record/connection_adapters/mysql2_adapter.rb:18:in `mysql2_connection'
  activerecord (4.0.0) lib/active_record/connection_adapters/abstract/connection_pool.rb:440:in `new_connection'
  activerecord (4.0.0) lib/active_record/connection_adapters/abstract/connection_pool.rb:450:in `checkout_new_connection'
  activerecord (4.0.0) lib/active_record/connection_adapters/abstract/connection_pool.rb:421:in `acquire_connection'
  activerecord (4.0.0) lib/active_record/connection_adapters/abstract/connection_pool.rb:356:in `block in checkout'
  /usr/share/ruby/1.9/monitor.rb:211:in `mon_synchronize'
  activerecord (4.0.0) lib/active_record/connection_adapters/abstract/connection_pool.rb:355:in `checkout'
  activerecord (4.0.0) lib/active_record/connection_adapters/abstract/connection_pool.rb:265:in `block in connection'
  /usr/share/ruby/1.9/monitor.rb:211:in `mon_synchronize'
  activerecord (4.0.0) lib/active_record/connection_adapters/abstract/connection_pool.rb:264:in `connection'
  activerecord (4.0.0) lib/active_record/connection_adapters/abstract/connection_pool.rb:546:in `retrieve_connection'
  activerecord (4.0.0) lib/active_record/connection_handling.rb:79:in `retrieve_connection'
  activerecord (4.0.0) lib/active_record/connection_handling.rb:53:in `connection'
  activerecord (4.0.0) lib/active_record/query_cache.rb:51:in `restore_query_cache_settings'
  activerecord (4.0.0) lib/active_record/query_cache.rb:43:in `rescue in call'
  activerecord (4.0.0) lib/active_record/query_cache.rb:32:in `call'
  activerecord (4.0.0) lib/active_record/connection_adapters/abstract/connection_pool.rb:626:in `call'
  actionpack (4.0.0) lib/action_dispatch/middleware/callbacks.rb:29:in `block in call'
  activesupport (4.0.0) lib/active_support/callbacks.rb:373:in `_run__2745626355944311791__call__callbacks'
  activesupport (4.0.0) lib/active_support/callbacks.rb:80:in `run_callbacks'
  actionpack (4.0.0) lib/action_dispatch/middleware/callbacks.rb:27:in `call'
  actionpack (4.0.0) lib/action_dispatch/middleware/remote_ip.rb:76:in `call'
  actionpack (4.0.0) lib/action_dispatch/middleware/debug_exceptions.rb:17:in `call'
  actionpack (4.0.0) lib/action_dispatch/middleware/show_exceptions.rb:30:in `call'
  railties (4.0.0) lib/rails/rack/logger.rb:38:in `call_app'
  railties (4.0.0) lib/rails/rack/logger.rb:21:in `block in call'
  activesupport (4.0.0) lib/active_support/tagged_logging.rb:67:in `block in tagged'
  activesupport (4.0.0) lib/active_support/tagged_logging.rb:25:in `tagged'
  activesupport (4.0.0) lib/active_support/tagged_logging.rb:67:in `tagged'
  railties (4.0.0) lib/rails/rack/logger.rb:21:in `call'
  actionpack (4.0.0) lib/action_dispatch/middleware/request_id.rb:21:in `call'
  rack (1.5.2) lib/rack/methodoverride.rb:21:in `call'
  rack (1.5.2) lib/rack/runtime.rb:17:in `call'
  activesupport (4.0.0) lib/active_support/cache/strategy/local_cache.rb:83:in `call'
  railties (4.0.0) lib/rails/engine.rb:511:in `call'
  railties (4.0.0) lib/rails/application.rb:97:in `call'
  passenger (4.0.20) lib/phusion_passenger/rack/thread_handler_extension.rb:77:in `process_request'
  passenger (4.0.20) lib/phusion_passenger/request_handler/thread_handler.rb:140:in `accept_and_process_next_request'
  passenger (4.0.20) lib/phusion_passenger/request_handler/thread_handler.rb:108:in `main_loop'
  passenger (4.0.20) lib/phusion_passenger/request_handler.rb:441:in `block (3 levels) in start_threads'

知道有什么问题吗?该应用在本地运行良好(该应用在生产环境中连接到 RDS)。

Ps:请随时在 cmets 中提问,以便我可以完善我的问题并解释上下文。只是暂时不知道需要什么资料。

【问题讨论】:

【参考方案1】:

我的猜测是您没有为您的弹性 beanstalk 环境分配一个安全组来提供对您的 RDS 的访问。

http://docs.aws.amazon.com/AmazonRDS/latest/UserGuide/Overview.RDSSecurityGroups.html

【讨论】:

以上是关于在弹性 beantalk 上部署 rails 应用程序时出错(生产模式)的主要内容,如果未能解决你的问题,请参考以下文章

升级弹性 beantalk 堆栈时,Rails 应用程序无法部署

使用弹性 beantalk 部署的 Rails 应用程序响应“无法访问站点”

我的 ec2 实例中乘客日志文件的位置(弹性 beantalk + rails)

Rails 应用程序未在弹性 beantalk aws 上加载资产

在 AWS 弹性 beanstalk 上部署 Rails - 静态资产路由不起作用

Flask 应用程序未在 AWS 弹性 beantalk 上部署