新手问题 将本地 rails 项目部署到 VM 的 cloudfoundry 中出现的错误

zjnxzy · 2013年04月18日 · 最后由 blueplanet 回复于 2013年04月19日 · 3322 次阅读

先说下应用的开发环境:ruby1.9.3,rails3.2.9,mongodb2.2 在window环境下开发的,并且在本地电脑下运行时没有问题,部署到VM的cloudfoundry中就出现找不到页面,查看日志时发现如下问题:

No Redis service bound to app.  Skipping auto-reconfiguration.
Loading MongoDB auto-reconfiguration.
No MongoDB Library Found. Skipping auto-reconfiguration.
No MySQL service bound to app.  Skipping auto-reconfiguration.
No PostgreSQL service bound to app.  Skipping auto-reconfiguration.
No RabbitMQ service bound to app.  Skipping auto-reconfiguration.
=> Booting WEBrick
=> Rails 3.2.9 application starting in production on http://0.0.0.0:8345
=> Call with -d to detach
=> Ctrl-C to shutdown server
Started GET "/" for 183.233.189.114 at 2013-04-18 02:21:42 +0000
Connecting to database specified by database.yml
Processing by ArticlesController#index as HTML
  Rendered articles/index.html.erb within layouts/application (90.5ms)
Completed 500 Internal Server Error in 144ms

ActionView::Template::Error (
Problem:
  No sessions configuration provided.
Summary:
  Mongoid's configuration requires that you provide details about each session t
hat can be connected to, and requires in the sessions config at least 1 default
session to exist.
Resolution:
  Double check your mongoid.yml to make sure that you have a top-level sessions
key with at least 1 default session configuration for it. You can regenerate a n
ew mongoid.yml for assistance via `rails g mongoid:config`.

 Example:
 \_\_development:
 \_\_\_\_sessions:
 \_\_\_\_\_\_default:
 \_\_\_\_\_\_\_\_database: mongoid_dev
 \_\_\_\_\_\_\_\_hosts:
 \_\_\_\_\_\_\_\_\_\_- localhost:27017

但是所说的mongoid.yml配置,我是已经配置好的,配置如下:

development:
  # Configure available database sessions. (required)
  sessions:
    # Defines the default session. (required)
    default:
      # Defines the name of the default database that Mongoid can connect to.
      # (required).
      database: spec_mongoid_development
      # Provides the hosts the default session can connect to. Must be an array
      # of host:port pairs. (required)
      hosts:
        - localhost:27017

求在VM的cloudfoundry部署成功过的朋友给建议。。。。谢谢啦

共收到 11 条回复

上传之前 bundle package过吗? 上传的时候, vmc会提示你要创建service, 你应该选择创建一个mongodb的service的, 创建了吗?

另外, development的配置 貌似是不会用到的。

这里有个有用的链接:http://docs.cloudfoundry.com/frameworks/ruby/rails-3-1.html

#1楼 @Eagle 你说的这些我都弄了,现在我又加了:

production:
  sessions:
    default:
      hosts:
        - localhost:27017
      database: spec_mongoid_development

但还是没有用,求帮忙呀。。。。

#1楼 @Eagle 新的错误:

ActionView::Template::Error (Could not connect to any secondary or primary nodes
 for replica set <Moped::Cluster nodes=[<Moped::Node resolved_address="127.0.0.1
:27017">]>):

好像是数据库连不上

@zjnxzy 我的理解是 production的部分你根本不用管, 因为cloudfoundry会给你替换掉的, 所以你写的是对是错也无所谓。 是不是你的代码里hard code了一些 localhost 或者 127.0.0.1的地址?

#4楼 @Eagle 代码里没有,我把完整的日志发给你看看:

** Invoke db:migrate (first_time)
** Invoke environment (first_time)
** Execute environment
** Invoke db:load_config (first_time)
** Execute db:load_config
** Execute db:migrate
** Invoke db:_dump (first_time)
** Execute db:_dump
** Invoke db:schema:dump (first_time)
** Invoke environment
** Invoke db:load_config
** Execute db:schema:dump
No Redis service bound to app.  Skipping auto-reconfiguration.
Loading MongoDB auto-reconfiguration.
No MongoDB Library Found. Skipping auto-reconfiguration.
No MySQL service bound to app.  Skipping auto-reconfiguration.
No PostgreSQL service bound to app.  Skipping auto-reconfiguration.
No RabbitMQ service bound to app.  Skipping auto-reconfiguration.


DEPRECATION WARNING: You have Rails 2.3-style plugins in vendor/plugins! Support
 for these plugins will be removed in Rails 4.0. Move them out and bundle them i
n your Gemfile, or fold them in to your app as lib/myplugin/* and config/initial
izers/myplugin.rb. See the release notes for more on this: http://weblog.rubyonr
ails.org/2012/1/4/rails-3-2-0-rc2-has-been-released. (called from <top (required
)> at /var/vcap/data/dea/apps/spec_mongoid-0-0040c3bd9e2789749fd8f4a014f45974/ap
p/config/environment.rb:5)
        SECURITY WARNING: No secret option provided to Rack::Session::Cookie.
        This poses a security threat. It is strongly recommended that you
        provide a secret to prevent exploits that may be possible from crafted
        cookies. This will not be supported in future versions of Rack, and
        future versions will even invalidate your existing user cookies.

        Called from: /var/vcap/data/dea/apps/spec_mongoid-0-0040c3bd9e2789749fd8
f4a014f45974/app/rubygems/ruby/1.9.1/gems/actionpack-3.2.9/lib/action_dispatch/m
iddleware/session/abstract_store.rb:28:in `initialize'.

Reading logs/stdout.log... OK
No Redis service bound to app.  Skipping auto-reconfiguration.
Loading MongoDB auto-reconfiguration.
No MongoDB Library Found. Skipping auto-reconfiguration.
No MySQL service bound to app.  Skipping auto-reconfiguration.
No PostgreSQL service bound to app.  Skipping auto-reconfiguration.
No RabbitMQ service bound to app.  Skipping auto-reconfiguration.
=> Booting WEBrick
=> Rails 3.2.9 application starting in production on http://0.0.0.0:14795
=> Call with -d to detach
=> Ctrl-C to shutdown server
Started GET "/" for 183.233.189.114 at 2013-04-18 07:30:28 +0000
Connecting to database specified by database.yml
Processing by AuthorsController#new as HTML
  Rendered authors/_form.html.erb (5.2ms)
  Rendered authors/new.html.erb within layouts/application (51.0ms)
Completed 200 OK in 85ms (Views: 84.8ms | ActiveRecord: 0.0ms)
Started POST "/authors" for 183.233.189.114 at 2013-04-18 07:30:37 +0000
Processing by AuthorsController#create as HTML
  Parameters: {"utf8"=>"���", "authenticity_token"=>"uWY5eCYA5IkSS4hjd4luOoI4fw
SVwk2uxadhl2x1g0=", "author"=>{"name"=>"hello"}, "commit"=>"Create Author"}
Completed 500 Internal Server Error in 17ms

NoMethodError (undefined method `[]' for nil:NilClass):
  app/controllers/authors_controller.rb:46:in `block in create'
  app/controllers/authors_controller.rb:45:in `create'


Started GET "/authors" for 183.233.189.114 at 2013-04-18 07:32:11 +0000
Processing by AuthorsController#index as HTML
  Rendered authors/index.html.erb within layouts/application (54.4ms)
Completed 500 Internal Server Error in 56ms

ActionView::Template::Error (undefined method `[]' for nil:NilClass):
    8:     <th></th>
    9:   </tr>
    10:
    11: <% @authors.each do |author| %>
    12:   <tr>
    13:     <td><%= author.name %></td>
    14:     <td><%= link_to 'Show', author %></td>
  app/views/authors/index.html.erb:11:in `_app_views_authors_index_html_erb__45
7789873894052545_28393640'
  app/controllers/authors_controller.rb:7:in `index'

#4楼 @Eagle 我感觉还是数据库没有弄好,没有连上。。。才会造成的。。。。

#4楼 @Eagle 还有我使用的gem是”mongoid“而不是”mongo_mapper“会不会有影响呢?

@zjnxzy 我个人没有部署过mongodb, 可能mogoid有问题, 你可以看看这篇文章 http://alexle.net/archives/312

#8楼 @Eagle 还是没有解决呀。。。。

@zjnxzy 那换mongo_mapper行吗? 我看mongodb官网上有篇介绍cloudfoundry的文章中就是用的mongo_mapper

Loading MongoDB auto-reconfiguration. 
No MongoDB Library Found. Skipping auto-reconfiguration

这段log看起来就是这个问题。

还不行的话, 你就把env.log打印出来吧, 里面有你的mongodb的连接字符串信息, 你需要在rails的database.yml的production部分填入这些信息。

#10楼 @Eagle +1 应该是你的VM的CloudFoundry的问题。 你的VM是怎么弄的?Micro么?还是自己装的?

需要 登录 后方可回复, 如果你还没有账号请点击这里 注册