0

我最近建立了一个 VPS 并正在尝试部署一个 rails 应用程序。我观看了一个截屏视频:http : //railscasts.com/episodes/335-deploying-to-a-vps,它解释了如何使用 nginx 设置 capistrano 和 unicorn,但也给出了 apache 的示例。

我按照在线指南设置乘客并修改了 railscasts capistrano 食谱。当我运行cap deploy:setup一些目录时,会在我的服务器上的应用程序根目录中创建一些目录。然后,当我运行cap deployrails 应用程序时,它会被放入发布文件夹和以时间戳命名的目录中。所以这部分似乎工作得很好。

所以有一段时间,当我导航到http://dev.gregchapple.com/site/index时,我收到了一些乘客错误,说某些 gem 丢失了,所以我使用 bundler 将它们安装在服务器上,然后错误就消失了。这就是当前问题出现的时候。现在,当我访问http://dev.gregchapple.com/site/index时,它只显示:“我们很抱歉,但出了点问题。”

apache 日志包含以下内容:

cache: [GET /site/index] miss
cache: [GET /] miss

有谁知道问题是什么?我的 apache 配置文件已更改为将文档根设置为乘客文档指定的公共目录。我不知道问题是什么,它让我发疯!

任何帮助是极大的赞赏 :)

更新

这是 production.log 文件出现的内容:

Started GET "/site/index" for 109.255.221.170 at 2012-08-06 13:26:13 -0700

Mysql2::Error (Access denied for user 'root'@'localhost' (using password: NO)):
mysql2 (0.3.11) lib/mysql2/client.rb:44:in `connect'
mysql2 (0.3.11) lib/mysql2/client.rb:44:in `initialize'
activerecord (3.2.1) lib/active_record/connection_adapters/mysql2_adapter.rb:16:in `new'
activerecord (3.2.1) lib/active_record/connection_adapters/mysql2_adapter.rb:16:in `mysql2_connection'
activerecord (3.2.1) lib/active_record/connection_adapters/abstract/connection_pool.rb:277:in `new_connection'
activerecord (3.2.1) lib/active_record/connection_adapters/abstract/connection_pool.rb:287:in `checkout_new_connection'
activerecord (3.2.1) lib/active_record/connection_adapters/abstract/connection_pool.rb:235:in `block (2 levels) in checkout'
activerecord (3.2.1) lib/active_record/connection_adapters/abstract/connection_pool.rb:230:in `loop'
activerecord (3.2.1) lib/active_record/connection_adapters/abstract/connection_pool.rb:230:in `block in checkout' /home/greg/.rvm/rubies/ruby-1.9.3-p194/lib/ruby/1.9.1/monitor.rb:211:in `mon_synchronize'
activerecord (3.2.1) lib/active_record/connection_adapters/abstract/connection_pool.rb:229:in `checkout'
activerecord (3.2.1) lib/active_record/connection_adapters/abstract/connection_pool.rb:95:in `connection'
activerecord (3.2.1) lib/active_record/connection_adapters/abstract/connection_pool.rb:374:in `retrieve_connection'
activerecord (3.2.1) lib/active_record/connection_adapters/abstract/connection_specification.rb:168:in `retrieve_connection'
activerecord (3.2.1) lib/active_record/connection_adapters/abstract/connection_specification.rb:142:in `connection'
activerecord (3.2.1) lib/active_record/query_cache.rb:67:in `rescue in call'
activerecord (3.2.1) lib/active_record/query_cache.rb:61:in `call'
activerecord (3.2.1) lib/active_record/connection_adapters/abstract/connection_pool.rb:443:in `call'
actionpack (3.2.1) lib/action_dispatch/middleware/callbacks.rb:28:in `block in call'
activesupport (3.2.1) lib/active_support/callbacks.rb:405:in `_run__3520547282522082875__call__1971459733125288916__callbacks'
activesupport (3.2.1) lib/active_support/callbacks.rb:405:in `__run_callback'
activesupport (3.2.1) lib/active_support/callbacks.rb:385:in `_run_call_callbacks'
activesupport (3.2.1) lib/active_support/callbacks.rb:81:in `run_callbacks'
actionpack (3.2.1) lib/action_dispatch/middleware/callbacks.rb:27:in `call'
actionpack (3.2.1) lib/action_dispatch/middleware/remote_ip.rb:31:in `call'
actionpack (3.2.1) lib/action_dispatch/middleware/debug_exceptions.rb:16:in `call'
actionpack (3.2.1) lib/action_dispatch/middleware/show_exceptions.rb:56:in `call'
railties (3.2.1) lib/rails/rack/logger.rb:26:in `call_app'
railties (3.2.1) lib/rails/rack/logger.rb:16:in `call'
actionpack (3.2.1) lib/action_dispatch/middleware/request_id.rb:22:in `call'
rack (1.4.1) lib/rack/methodoverride.rb:21:in `call'
rack (1.4.1) lib/rack/runtime.rb:17:in `call'
activesupport (3.2.1) lib/active_support/cache/strategy/local_cache.rb:72:in `call'
rack (1.4.1) lib/rack/lock.rb:15:in `call'
rack-cache (1.2) lib/rack/cache/context.rb:136:in `forward'
rack-cache (1.2) lib/rack/cache/context.rb:245:in `fetch'
rack-cache (1.2) lib/rack/cache/context.rb:185:in `lookup'
rack-cache (1.2) lib/rack/cache/context.rb:66:in `call!'
rack-cache (1.2) lib/rack/cache/context.rb:51:in `call'
railties (3.2.1) lib/rails/engine.rb:479:in `call'
railties (3.2.1) lib/rails/application.rb:220:in `call'
railties (3.2.1) lib/rails/railtie/configurable.rb:30:in `method_missing'
passenger (3.0.15) lib/phusion_passenger/rack/request_handler.rb:96:in `process_request'
passenger (3.0.15) lib/phusion_passenger/abstract_request_handler.rb:516:in `accept_and_process_next_request'
passenger (3.0.15) lib/phusion_passenger/abstract_request_handler.rb:274:in `main_loop'
passenger (3.0.15) lib/phusion_passenger/rack/application_spawner.rb:206:in `start_request_handler'
passenger (3.0.15) lib/phusion_passenger/rack/application_spawner.rb:171:in `block in handle_spawn_application'
passenger (3.0.15) lib/phusion_passenger/utils.rb:470:in `safe_fork'
passenger (3.0.15) lib/phusion_passenger/rack/application_spawner.rb:166:in `handle_spawn_application'
passenger (3.0.15) lib/phusion_passenger/abstract_server.rb:357:in `server_main_loop'
passenger (3.0.15) lib/phusion_passenger/abstract_server.rb:206:in `start_synchronously'
passenger (3.0.15) lib/phusion_passenger/abstract_server.rb:180:in `start'
passenger (3.0.15) lib/phusion_passenger/rack/application_spawner.rb:129:in `start'
passenger (3.0.15) lib/phusion_passenger/spawn_manager.rb:253:in `block (2 levels) in spawn_rack_application'
passenger (3.0.15) lib/phusion_passenger/abstract_server_collection.rb:132:in `lookup_or_add'
passenger (3.0.15) lib/phusion_passenger/spawn_manager.rb:246:in `block in spawn_rack_application'
passenger (3.0.15) lib/phusion_passenger/abstract_server_collection.rb:82:in `block in synchronize'
<internal:prelude>:10:in `synchronize'
passenger (3.0.15) lib/phusion_passenger/abstract_server_collection.rb:79:in `synchronize'
passenger (3.0.15) lib/phusion_passenger/spawn_manager.rb:244:in `spawn_rack_application'
passenger (3.0.15) lib/phusion_passenger/spawn_manager.rb:137:in `spawn_application'
passenger (3.0.15) lib/phusion_passenger/spawn_manager.rb:275:in `handle_spawn_application'
passenger (3.0.15) lib/phusion_passenger/abstract_server.rb:357:in `server_main_loop'
passenger (3.0.15) lib/phusion_passenger/abstract_server.rb:206:in `start_synchronously'
passenger (3.0.15) helper-scripts/passenger-spawn-server:99:in `<main>'

更新 2

数据库.yml

development:
  adapter: mysql2
  encoding: utf8
  reconnect: false
  database: gregchapple_development
  pool: 5
  host: localhost
  username: root
  password: *****
  socket: /tmp/mysql.sock

test:
  adapter: mysql2
  encoding: utf8
  reconnect: false
  database: gregchapple_test
  pool: 5
  host: localhost
  username: root
  password: *****
  socket: /tmp/mysql.sock

production:
  adapter: mysql2
  encoding: utf8
  reconnect: false
  database: gregchapple_production
  pool: 5
  host: localhost
  username: root
  password: *****
  socket: /tmp/mysql.sock
4

3 回答 3

1

I had similar problem like you. I changed these rows in database.yml add

host: 127.0.0.1

remove

socket: /tmp/mysql.sock

Then:

cap deploy:setup
cap deploy:check
cap deploy:cold
#some updates with custom code
cap deploy:update

You must update everything in code with capistrano, DON'T CHANGE CODE ON VPN (you can create only tmp dir). You check your sql connection manualy with ssh on vpn. For example

mysql -u gregchapple -p

Your virtual host is ok?

于 2012-08-07T12:46:30.830 回答
1

您的应用正在寻找 mysql2 适配器,因此请确保您的 Gemfile 中有

gem 'mysql2'

并且你bundle install和你的database.yml文件中你正在使用 mysql2 适配器。

production:
  adapter: mysql2
  ...

并且不要忘记touch tmp/restart.txt从 Rails 应用程序的根目录重新启动Passenger。

恭喜!您快到了!

于 2012-08-06T22:39:30.693 回答
0

您的 Rails 应用程序的database.yml生产部分配置不正确。

  1. 在您的服务器上配置 mysql 数据库。
  2. 在 Rails 应用程序的 database.yml 中配置生产部分,并为生产服务器提供数据库用户名和密码。
  3. 再次部署。
  4. 测试。
于 2012-08-06T21:10:56.863 回答