4

我正在尝试使用一个不错的简单 Rails 应用程序(1 个模型和 2 个字段)来学习如何使用 mysql2 数据适配器将应用程序部署到 Amazon Web Services (AWS) EC2 实例服务器。我正在尝试使用 Rubber Gem 进行部署。在我尝试浏览网站之前,一切看起来都很好(引导和部署)。当我输入模型索引页面的 URL 时,apache2 error.log 显示此错误:

*** Exception PhusionPassenger::UnknownError in
PhusionPassenger::Rack::ApplicationSpawner 
(Access denied for user ''@'blog.foo.com' to database 'blog_production' 
(Mysql2::Error)) 

为什么不能访问mysql db?橡胶设置的一切看起来都很好。

完整的 error.log 数据是

[ pid=19455 thr=19477020 file=utils.rb:176 time=2012-09-13 23:25:01.220 ]: *** Exception PhusionPassenger::UnknownError in PhusionPassenger::Rack::ApplicationSpawner (Access denied for user ''@'blog.foo.com' to database 'blog_production' (Mysql2::Error)) (process 19455, thread #<Thread:0x00000002526438>):
from /mnt/blog-production/shared/bundle/ruby/1.9.1/gems/mysql2-0.3.11/lib/mysql2/client.rb:44:in `connect'
from /mnt/blog-production/shared/bundle/ruby/1.9.1/gems/mysql2-0.3.11/lib/mysql2/client.rb:44:in `initialize'
from /mnt/blog-production/shared/bundle/ruby/1.9.1/gems/activerecord-3.1.0/lib/active_record/connection_adapters/mysql2_adapter.rb:16:in `new'
from /mnt/blog-production/shared/bundle/ruby/1.9.1/gems/activerecord-3.1.0/lib/active_record/connection_adapters/mysql2_adapter.rb:16:in `mysql2_connection'
from /mnt/blog-production/shared/bundle/ruby/1.9.1/gems/activerecord-3.1.0/lib/active_record/connection_adapters/abstract/connection_pool.rb:304:in `new_connection'
from /mnt/blog-production/shared/bundle/ruby/1.9.1/gems/activerecord-3.1.0/lib/active_record/connection_adapters/abstract/connection_pool.rb:323:in `checkout_new_connection'
from /mnt/blog-production/shared/bundle/ruby/1.9.1/gems/activerecord-3.1.0/lib/active_record/connection_adapters/abstract/connection_pool.rb:265:in `block (2 levels) in checkout'
from /mnt/blog-production/shared/bundle/ruby/1.9.1/gems/activerecord-3.1.0/lib/active_record/connection_adapters/abstract/connection_pool.rb:261:in `loop'
from /mnt/blog-production/shared/bundle/ruby/1.9.1/gems/activerecord-3.1.0/lib/active_record/connection_adapters/abstract/connection_pool.rb:261:in `block in checkout'
from /usr/local/rvm/rubies/ruby-1.9.2-p290/lib/ruby/1.9.1/monitor.rb:201:in `mon_synchronize'
from /mnt/blog-production/shared/bundle/ruby/1.9.1/gems/activerecord-3.1.0/lib/active_record/connection_adapters/abstract/connection_pool.rb:260:in `checkout'
from /mnt/blog-production/shared/bundle/ruby/1.9.1/gems/activerecord-3.1.0/lib/active_record/connection_adapters/abstract/connection_pool.rb:162:in `connection'
from /mnt/blog-production/shared/bundle/ruby/1.9.1/gems/activerecord-3.1.0/lib/active_record/connection_adapters/abstract/connection_pool.rb:409:in `retrieve_connection'
from /mnt/blog-production/shared/bundle/ruby/1.9.1/gems/activerecord-3.1.0/lib/active_record/connection_adapters/abstract/connection_specification.rb:107:in `retrieve_connection'
from /mnt/blog-production/shared/bundle/ruby/1.9.1/gems/activerecord-3.1.0/lib/active_record/connection_adapters/abstract/connection_specification.rb:89:in `connection'
from /mnt/blog-production/shared/bundle/ruby/1.9.1/gems/activerecord-3.1.0/lib/active_record/base.rb:701:in `table_exists?'
from /mnt/blog-production/shared/bundle/ruby/1.9.1/gems/activerecord-3.1.0/lib/active_record/base.rb:792:in `attribute_names'
from /mnt/blog-production/shared/bundle/ruby/1.9.1/gems/actionpack-3.1.0/lib/action_controller/metal/params_wrapper.rb:168:in `_set_wrapper_defaults'
from /mnt/blog-production/shared/bundle/ruby/1.9.1/gems/actionpack-3.1.0/lib/action_controller/metal/params_wrapper.rb:128:in `inherited'
from /mnt/blog-production/shared/bundle/ruby/1.9.1/gems/actionpack-3.1.0/lib/abstract_controller/railties/routes_helpers.rb:7:in `block (2 levels) in with'
from /mnt/blog-production/shared/bundle/ruby/1.9.1/gems/actionpack-3.1.0/lib/action_controller/railties/paths.rb:7:in `block (2 levels) in with'
from /mnt/blog-production/releases/20120914032205/app/controllers/articles_controller.rb:1:in `<top (required)>'
from /mnt/blog-production/shared/bundle/ruby/1.9.1/gems/activesupport-3.1.0/lib/active_support/dependencies.rb:240:in `require'
from /mnt/blog-production/shared/bundle/ruby/1.9.1/gems/activesupport-3.1.0/lib/active_support/dependencies.rb:240:in `block in require'
from /mnt/blog-production/shared/bundle/ruby/1.9.1/gems/activesupport-3.1.0/lib/active_support/dependencies.rb:225:in `load_dependency'
from /mnt/blog-production/shared/bundle/ruby/1.9.1/gems/activesupport-3.1.0/lib/active_support/dependencies.rb:240:in `require'
from /mnt/blog-production/shared/bundle/ruby/1.9.1/gems/activesupport-3.1.0/lib/active_support/dependencies.rb:348:in `require_or_load'
from /mnt/blog-production/shared/bundle/ruby/1.9.1/gems/activesupport-3.1.0/lib/active_support/dependencies.rb:302:in `depend_on'
from /mnt/blog-production/shared/bundle/ruby/1.9.1/gems/activesupport-3.1.0/lib/active_support/dependencies.rb:214:in `require_dependency'
from /mnt/blog-production/shared/bundle/ruby/1.9.1/gems/railties-3.1.0/lib/rails/engine.rb:416:in `block (2 levels) in eager_load!'
from /mnt/blog-production/shared/bundle/ruby/1.9.1/gems/railties-3.1.0/lib/rails/engine.rb:415:in `each'
from /mnt/blog-production/shared/bundle/ruby/1.9.1/gems/railties-3.1.0/lib/rails/engine.rb:415:in `block in eager_load!'
from /mnt/blog-production/shared/bundle/ruby/1.9.1/gems/railties-3.1.0/lib/rails/engine.rb:413:in `each'
from /mnt/blog-production/shared/bundle/ruby/1.9.1/gems/railties-3.1.0/lib/rails/engine.rb:413:in `eager_load!'
from /mnt/blog-production/shared/bundle/ruby/1.9.1/gems/railties-3.1.0/lib/rails/application/finisher.rb:51:in `block in <module:Finisher>'
from /mnt/blog-production/shared/bundle/ruby/1.9.1/gems/railties-3.1.0/lib/rails/initializable.rb:25:in `instance_exec'
from /mnt/blog-production/shared/bundle/ruby/1.9.1/gems/railties-3.1.0/lib/rails/initializable.rb:25:in `run'
from /mnt/blog-production/shared/bundle/ruby/1.9.1/gems/railties-3.1.0/lib/rails/initializable.rb:50:in `block in run_initializers'
from /mnt/blog-production/shared/bundle/ruby/1.9.1/gems/railties-3.1.0/lib/rails/initializable.rb:49:in `each'
from /mnt/blog-production/shared/bundle/ruby/1.9.1/gems/railties-3.1.0/lib/rails/initializable.rb:49:in `run_initializers'
from /mnt/blog-production/shared/bundle/ruby/1.9.1/gems/railties-3.1.0/lib/rails/application.rb:92:in `initialize!'
from /mnt/blog-production/shared/bundle/ruby/1.9.1/gems/railties-3.1.0/lib/rails/railtie/configurable.rb:30:in `method_missing'
from /mnt/blog-production/releases/20120914032205/config/environment.rb:5:in `<top (required)>'
from config.ru:3:in `require'
from config.ru:3:in `block in <main>'
from /mnt/blog-production/shared/bundle/ruby/1.9.1/gems/rack-1.3.6/lib/rack/builder.rb:51:in `instance_eval'
from /mnt/blog-production/shared/bundle/ruby/1.9.1/gems/rack-1.3.6/lib/rack/builder.rb:51:in `initialize'
from config.ru:1:in `new'
from config.ru:1:in `<main>'
from /usr/local/rvm/gems/ruby-1.9.2-p290/gems/passenger-3.0.12/lib/phusion_passenger/rack/application_spawner.rb:225:in `eval'
from /usr/local/rvm/gems/ruby-1.9.2-p290/gems/passenger-3.0.12/lib/phusion_passenger/rack/application_spawner.rb:225:in `load_rack_app'
from /usr/local/rvm/gems/ruby-1.9.2-p290/gems/passenger-3.0.12/lib/phusion_passenger/rack/application_spawner.rb:157:in `block in initialize_server'
from /usr/local/rvm/gems/ruby-1.9.2-p290/gems/passenger-3.0.12/lib/phusion_passenger/utils.rb:572:in `report_app_init_status'
from /usr/local/rvm/gems/ruby-1.9.2-p290/gems/passenger-3.0.12/lib/phusion_passenger/rack/application_spawner.rb:154:in `initialize_server'
from /usr/local/rvm/gems/ruby-1.9.2-p290/gems/passenger-3.0.12/lib/phusion_passenger/abstract_server.rb:204:in `start_synchronously'
from /usr/local/rvm/gems/ruby-1.9.2-p290/gems/passenger-3.0.12/lib/phusion_passenger/abstract_server.rb:180:in `start'
from /usr/local/rvm/gems/ruby-1.9.2-p290/gems/passenger-3.0.12/lib/phusion_passenger/rack/application_spawner.rb:129:in `start'
from /usr/local/rvm/gems/ruby-1.9.2-p290/gems/passenger-3.0.12/lib/phusion_passenger/spawn_manager.rb:253:in `block (2 levels) in spawn_rack_application'
from /usr/local/rvm/gems/ruby-1.9.2-p290/gems/passenger-3.0.12/lib/phusion_passenger/abstract_server_collection.rb:132:in `lookup_or_add'
from /usr/local/rvm/gems/ruby-1.9.2-p290/gems/passenger-3.0.12/lib/phusion_passenger/spawn_manager.rb:246:in `block in spawn_rack_application'
from /usr/local/rvm/gems/ruby-1.9.2-p290/gems/passenger-3.0.12/lib/phusion_passenger/abstract_server_collection.rb:82:in `block in synchronize'
from <internal:prelude>:10:in `synchronize'
from /usr/local/rvm/gems/ruby-1.9.2-p290/gems/passenger-3.0.12/lib/phusion_passenger/abstract_server_collection.rb:79:in `synchronize'
from /usr/local/rvm/gems/ruby-1.9.2-p290/gems/passenger-3.0.12/lib/phusion_passenger/spawn_manager.rb:244:in `spawn_rack_application'
from /usr/local/rvm/gems/ruby-1.9.2-p290/gems/passenger-3.0.12/lib/phusion_passenger/spawn_manager.rb:137:in `spawn_application'
from /usr/local/rvm/gems/ruby-1.9.2-p290/gems/passenger-3.0.12/lib/phusion_passenger/spawn_manager.rb:275:in `handle_spawn_application'
from /usr/local/rvm/gems/ruby-1.9.2-p290/gems/passenger-3.0.12/lib/phusion_passenger/abstract_server.rb:357:in `server_main_loop'
from /usr/local/rvm/gems/ruby-1.9.2-p290/gems/passenger-3.0.12/lib/phusion_passenger/abstract_server.rb:206:in `start_synchronously'
from /usr/local/rvm/gems/ruby-1.9.2-p290/gems/passenger-3.0.12/helper-scripts/passenger-spawn-server:99:in `<main>'
[ pid=19516 thr=140129381447488 file=ext/apache2/Hooks.cpp:862 time=2012-09-13 23:25:01.326 ]: Unexpected error in mod_passenger: Cannot spawn application '/mnt/blog-production/releases/20120914032205': An error occured while spawning the application.
Backtrace:
 in 'virtual Passenger::SessionPtr Passenger::ApplicationPool::Client::get(const Passenger::PoolOptions&)' (Client.h:742)
 in 'Passenger::SessionPtr Hooks::getSession(const Passenger::PoolOptions&)' (Hooks.cpp:294)
 in 'int Hooks::handleRequest(request_rec*)' (Hooks.cpp:563)

已部署服务器上的 config/database.yml 文件是

production:
  adapter: mysql2
  encoding: utf8
  database: blog_production
  username: blog
  password: 
  host: blog.foo.com
  pool: 5

是否有任何其他信息可以帮助追查问题?

我现在要花两周时间尝试在 AWS 上部署该网站。这些天的某一天,我要付出代价。

谢谢,拉斯

我看到密码字段是空白的,所以在 Rubber-mysql.yml 中为 db_pass 变量设置一个值

db_user: "#{app_name[0,16]}"
db_pass: kickback
db_name: "#{app_name}_#{Rubber.env}"

我试着做一个cap rubber:bootstrap然后cap deploy希望能在 config/database.yml 文件中填写服务器上的密码值。那没有用,所以我做了一个完整的cap rubber:create_staging. yml 文件现在已填写密码

production:
  adapter: mysql2
  encoding: utf8
  database: blog_production
  username: blog
  password: kickback
  host: blog.foo.com
  pool: 5

但是 create_staging 命令的结尾显示了这个错误

 * executing "cd /mnt/blog-production/releases/20120914041247 && bundle exec rake RAILS_ENV=production  db:migrate"
    servers: ["blog.foo.com"]
    [blog.foo.com] executing command
 ** [out :: blog.foo.com] rake aborted!
 ** [out :: blog.foo.com] 
 ** [out :: blog.foo.com] Access denied for user 'blog'@'blog.foo.com' (using password: YES)
 ** [out :: blog.foo.com] 
 ** [out :: blog.foo.com] 
 ** [out :: blog.foo.com] Tasks: TOP => db:migrate
 ** [out :: blog.foo.com] 
 ** [out :: blog.foo.com] (See full trace by running task with --trace)
 ** [out :: blog.foo.com] 
    command finished in 25336ms
failed: "/bin/bash -l -c 'cd /mnt/blog-production/releases/20120914041247 && bundle exec rake RAILS_ENV=production  db:migrate'" on blog.foo.com

接下来要尝试什么?也许尝试rake db:migrate手动。

$ RAILS_ENV=production rake db:migrate --trace
** Invoke db:migrate (first_time)
** Invoke environment (first_time)
** Execute environment
Rails Error: Unable to access log file. Please ensure that /mnt/blog-production/releases/20120914041247/log/production.log exists and is chmod 0666. The log level has been raised to WARN and the output directed to STDERR until the problem is fixed.
** Invoke db:load_config (first_time)
** Invoke rails_env (first_time)
** Execute rails_env
** Execute db:load_config
** Execute db:migrate
rake aborted!
Access denied for user 'blog'@'blog.foo.com' (using password: YES)
/mnt/blog-production/shared/bundle/ruby/1.9.1/gems/mysql2-0.3.11/lib/mysql2/client.rb:44:in `connect'
/mnt/blog-production/shared/bundle/ruby/1.9.1/gems/mysql2-0.3.11/lib/mysql2/client.rb:44:in `initialize'
/mnt/blog-production/shared/bundle/ruby/1.9.1/gems/activerecord-3.1.0/lib/active_record/connection_adapters/mysql2_adapter.rb:16:in `new'
/mnt/blog-production/shared/bundle/ruby/1.9.1/gems/activerecord-3.1.0/lib/active_record/connection_adapters/mysql2_adapter.rb:16:in `mysql2_connection'
/mnt/blog-production/shared/bundle/ruby/1.9.1/gems/activerecord-3.1.0/lib/active_record/connection_adapters/abstract/connection_pool.rb:304:in `new_connection'
/mnt/blog-production/shared/bundle/ruby/1.9.1/gems/activerecord-3.1.0/lib/active_record/connection_adapters/abstract/connection_pool.rb:323:in `checkout_new_connection'
/mnt/blog-production/shared/bundle/ruby/1.9.1/gems/activerecord-3.1.0/lib/active_record/connection_adapters/abstract/connection_pool.rb:265:in `block (2 levels) in checkout'
/mnt/blog-production/shared/bundle/ruby/1.9.1/gems/activerecord-3.1.0/lib/active_record/connection_adapters/abstract/connection_pool.rb:261:in `loop'
/mnt/blog-production/shared/bundle/ruby/1.9.1/gems/activerecord-3.1.0/lib/active_record/connection_adapters/abstract/connection_pool.rb:261:in `block in checkout'
/usr/local/rvm/rubies/ruby-1.9.2-p290/lib/ruby/1.9.1/monitor.rb:201:in `mon_synchronize'
/mnt/blog-production/shared/bundle/ruby/1.9.1/gems/activerecord-3.1.0/lib/active_record/connection_adapters/abstract/connection_pool.rb:260:in `checkout'
/mnt/blog-production/shared/bundle/ruby/1.9.1/gems/activerecord-3.1.0/lib/active_record/connection_adapters/abstract/connection_pool.rb:162:in `connection'
/mnt/blog-production/shared/bundle/ruby/1.9.1/gems/activerecord-3.1.0/lib/active_record/connection_adapters/abstract/connection_pool.rb:409:in `retrieve_connection'
/mnt/blog-production/shared/bundle/ruby/1.9.1/gems/activerecord-3.1.0/lib/active_record/connection_adapters/abstract/connection_specification.rb:107:in `retrieve_connection'
/mnt/blog-production/shared/bundle/ruby/1.9.1/gems/activerecord-3.1.0/lib/active_record/connection_adapters/abstract/connection_specification.rb:89:in `connection'
/mnt/blog-production/shared/bundle/ruby/1.9.1/gems/activerecord-3.1.0/lib/active_record/migration.rb:633:in `initialize'
/mnt/blog-production/shared/bundle/ruby/1.9.1/gems/activerecord-3.1.0/lib/active_record/migration.rb:549:in `new'
/mnt/blog-production/shared/bundle/ruby/1.9.1/gems/activerecord-3.1.0/lib/active_record/migration.rb:549:in `up'
/mnt/blog-production/shared/bundle/ruby/1.9.1/gems/activerecord-3.1.0/lib/active_record/migration.rb:530:in `migrate'
/mnt/blog-production/shared/bundle/ruby/1.9.1/gems/activerecord-3.1.0/lib/active_record/railties/databases.rake:161:in `block (2 levels) in <top (required)>'
/mnt/blog-production/shared/bundle/ruby/1.9.1/gems/rake-0.9.2.2/lib/rake/task.rb:205:in `call'
/mnt/blog-production/shared/bundle/ruby/1.9.1/gems/rake-0.9.2.2/lib/rake/task.rb:205:in `block in execute'
/mnt/blog-production/shared/bundle/ruby/1.9.1/gems/rake-0.9.2.2/lib/rake/task.rb:200:in `each'
/mnt/blog-production/shared/bundle/ruby/1.9.1/gems/rake-0.9.2.2/lib/rake/task.rb:200:in `execute'
/mnt/blog-production/shared/bundle/ruby/1.9.1/gems/rake-0.9.2.2/lib/rake/task.rb:158:in `block in invoke_with_call_chain'
/usr/local/rvm/rubies/ruby-1.9.2-p290/lib/ruby/1.9.1/monitor.rb:201:in `mon_synchronize'
/mnt/blog-production/shared/bundle/ruby/1.9.1/gems/rake-0.9.2.2/lib/rake/task.rb:151:in `invoke_with_call_chain'
/mnt/blog-production/shared/bundle/ruby/1.9.1/gems/rake-0.9.2.2/lib/rake/task.rb:144:in `invoke'
/mnt/blog-production/shared/bundle/ruby/1.9.1/gems/rake-0.9.2.2/lib/rake/application.rb:116:in `invoke_task'
/mnt/blog-production/shared/bundle/ruby/1.9.1/gems/rake-0.9.2.2/lib/rake/application.rb:94:in `block (2 levels) in top_level'
/mnt/blog-production/shared/bundle/ruby/1.9.1/gems/rake-0.9.2.2/lib/rake/application.rb:94:in `each'
/mnt/blog-production/shared/bundle/ruby/1.9.1/gems/rake-0.9.2.2/lib/rake/application.rb:94:in `block in top_level'
/mnt/blog-production/shared/bundle/ruby/1.9.1/gems/rake-0.9.2.2/lib/rake/application.rb:133:in `standard_exception_handling'
/mnt/blog-production/shared/bundle/ruby/1.9.1/gems/rake-0.9.2.2/lib/rake/application.rb:88:in `top_level'
/mnt/blog-production/shared/bundle/ruby/1.9.1/gems/rake-0.9.2.2/lib/rake/application.rb:66:in `block in run'
/mnt/blog-production/shared/bundle/ruby/1.9.1/gems/rake-0.9.2.2/lib/rake/application.rb:133:in `standard_exception_handling'
/mnt/blog-production/shared/bundle/ruby/1.9.1/gems/rake-0.9.2.2/lib/rake/application.rb:63:in `run'
/mnt/blog-production/shared/bundle/ruby/1.9.1/gems/rake-0.9.2.2/bin/rake:33:in `<top (required)>'
/usr/local/rvm/gems/ruby-1.9.2-p290@global/bin/rake:19:in `load'
/usr/local/rvm/gems/ruby-1.9.2-p290@global/bin/rake:19:in `<main>'
/usr/local/rvm/gems/ruby-1.9.2-p290/bin/ruby_noexec_wrapper:14:in `eval'
/usr/local/rvm/gems/ruby-1.9.2-p290/bin/ruby_noexec_wrapper:14:in `<main>'
Tasks: TOP => db:migrate

我是时候放弃使用橡胶了吗?

4

1 回答 1

0

这是一个 MySQL 身份验证问题。它首先将您的用户与匿名帐户匹配(由于主机名),因此访问受到限制。

如果你 ssh 到你的服务器并输入这个,你应该以同样的方式失败:

$ mysql -u blog -h blog.foo.com -p kickback
ERROR 1045 (28000): Access denied for user 'blog'@'blog.foo.com' (using password: YES)

在这里查看我的详细解决方案。

于 2012-10-05T11:46:59.310 回答