尝试在 Vagrant vm 上启动 rails 服务器时出错

Posted

技术标签:

【中文标题】尝试在 Vagrant vm 上启动 rails 服务器时出错【英文标题】:Getting error trying to start rails server on Vagrant vm 【发布时间】:2014-07-28 18:25:09 【问题描述】:

下面是我在 vagrant VM 上尝试运行“rails s”时收到的控制台错误消息。它退出所有这些错误消息,第一行是 /home/vagrant/.rvm/rubies/ruby-2.0.0-p247/lib/ruby/2.0.0/net/http.rb:878:in `initialize': 连接被拒绝-connect(2) (Errno:: ECONNREFUSED)

不知道这里发生了什么......

非常感谢


config\initializers\tire.rb 子域 = ""

if Rails.env.alpha?
  subdomain = ".alpha."
end

if Rails.env.development?
  Tire.configure  logger 'log/elasticsearch_development.log', :level => 'debug' 
else
  Tire.configure  logger "log/elasticsearch.#Rails.env.to_s.downcase.log" 
end

prefix = "org.#Rails.application.class.parent_name.downcase#subdomain_#Rails.env.to_s.downcase"
Tire::Model::Search.index_prefix(prefix)


def get_indices_for_env(prefix)
  aliases = Tire::Configuration.client.get(Tire::Configuration.url + '/_aliases').body
  global_indices = MultiJson.load(aliases).keys

  all_indices = global_indices.select do |index|
    index.start_with? prefix
  end
  all_indices.freeze
end

ALL_INDICES = get_indices_for_env(prefix)

错误信息


vagrant@precise32:/vagrant$ bundle exec rails s => 启动 WEBrick => Rails 3.2.17 应用程序在http://x.x.x.x:3000 开始开发 => 使用 -d 调用以分离 => Ctrl-C 关闭服务器退出 /home/vagrant/.rvm/rubies/ruby-2.0.0-p247/lib/ruby/2.0.0/net/http.rb:878:in initialize': Connection refused - connect(2) (Errno::ECONNREFUSED) from /home/vagrant/.rvm/rubies/ruby-2.0.0-p247/lib/ruby/2.0.0/net/http.rb:878:in open' 来自/home/vagrant/.rvm/rubies/ruby-2.0.0-p247/lib/ruby/2.0.0/net/http.rb:878:in block in connect' from /home/vagrant/.rvm/rubies/ruby-2.0.0-p247/lib/ruby/2.0.0/timeout.rb:52:in timeout' 来自/home/vagrant/.rvm/rubies/ruby-2.0.0-p247/lib/ruby/2.0.0/net/http.rb:877:in connect' from /home/vagrant/.rvm/rubies/ruby-2.0.0-p247/lib/ruby/2.0.0/net/http.rb:862:in do_start' 来自/home/vagrant/.rvm/rubies/ruby-2.0.0-p247/lib/ruby/2.0.0/net/http.rb:851:in start' from /home/vagrant/.rvm/gems/ruby-2.0.0-p247/gems/rest-client-1.6.7/lib/restclient/request.rb:172:in transmit' 来自/home/vagrant/.rvm/gems/ruby-2.0.0-p247/gems/rest-client-1.6.7/lib/restclient/request.rb:64:in execute' from /home/vagrant/.rvm/gems/ruby-2.0.0-p247/gems/tire-0.6.2/lib/tire/http/client.rb:11:in get' 来自 /vagrant/config/initializers/tire.rb:20:in get_indices_for_env' from /vagrant/config/initializers/tire.rb:29:in' 来自/home/vagrant/.rvm/gems/ruby-2.0.0-p247/gems/activesupport-3.2.17/lib/active_support/dependencies.rb:245:in load' from /home/vagrant/.rvm/gems/ruby-2.0.0-p247/gems/activesupport-3.2.17/lib/active_support/dependencies.rb:245:in block 加载中' 来自/home/vagrant/.rvm/gems/ruby-2.0.0-p247/gems/activesupport-3.2.17/lib/active_support/dependencies.rb:236:in load_dependency' from /home/vagrant/.rvm/gems/ruby-2.0.0-p247/gems/activesupport-3.2.17/lib/active_support/dependencies.rb:245:in load' 来自/home/vagrant/.rvm/gems/ruby-2.0.0-p247/gems/railties-3.2.17/lib/rails/engine.rb:593:in block (2 levels) in <class:Engine>' from /home/vagrant/.rvm/gems/ruby-2.0.0-p247/gems/railties-3.2.17/lib/rails/engine.rb:592:in each' 来自/home/vagrant/.rvm/gems/ruby-2.0.0-p247/gems/railties-3.2.17/lib/rails/engine.rb:592:in block in <class:Engine>' from /home/vagrant/.rvm/gems/ruby-2.0.0-p247/gems/railties-3.2.17/lib/rails/initializable.rb:30:in instance_exec' 来自/home/vagrant/.rvm/gems/ruby-2.0.0-p247/gems/railties-3.2.17/lib/rails/initializable.rb:30:in run' from /home/vagrant/.rvm/gems/ruby-2.0.0-p247/gems/railties-3.2.17/lib/rails/initializable.rb:55:in block in run_initializers' 来自/home/vagrant/.rvm/gems/ruby-2.0.0-p247/gems/railties-3.2.17/lib/rails/initializable.rb:54:in each' from /home/vagrant/.rvm/gems/ruby-2.0.0-p247/gems/railties-3.2.17/lib/rails/initializable.rb:54:in run_initializers' 来自/home/vagrant/.rvm/gems/ruby-2.0.0-p247/gems/railties-3.2.17/lib/rails/application.rb:136:in initialize!' from /home/vagrant/.rvm/gems/ruby-2.0.0-p247/gems/railties-3.2.17/lib/rails/railtie/configurable.rb:30:in method_missing' 来自 /vagrant/config/environment.rb:5:in <top (required)>' from /vagrant/config.ru:3:inrequire' 来自 /vagrant/config.ru:3:in block in <main>' from /home/vagrant/.rvm/gems/ruby-2.0.0-p247/gems/rack-1.4.5/lib/rack/builder.rb:51:in instance_eval' 来自/home/vagrant/.rvm/gems/ruby-2.0.0-p247/gems/rack-1.4.5/lib/rack/builder.rb:51:in initialize' from /vagrant/config.ru:in新' 来自 /vagrant/config.ru:in <main>' from /home/vagrant/.rvm/gems/ruby-2.0.0-p247/gems/rack-1.4.5/lib/rack/builder.rb:40:in eval' 来自/home/vagrant/.rvm/gems/ruby-2.0.0-p247/gems/rack-1.4.5/lib/rack/builder.rb:40:in parse_file' from /home/vagrant/.rvm/gems/ruby-2.0.0-p247/gems/rack-1.4.5/lib/rack/server.rb:200:in app' 来自/home/vagrant/.rvm/gems/ruby-2.0.0-p247/gems/railties-3.2.17/lib/rails/commands/server.rb:46:in app' from /home/vagrant/.rvm/gems/ruby-2.0.0-p247/gems/rack-1.4.5/lib/rack/server.rb:304:in wrapped_app' 来自 /home/vagrant/.rvm/gems/ruby-2.0.0-p247/gems/rack-1.4.5/lib/rack/server.rb:254:in start' from /home/vagrant/.rvm/gems/ruby-2.0.0-p247/gems/railties-3.2.17/lib/rails/commands/server.rb:70:in start' 来自/home/vagrant/.rvm/gems/ruby-2.0.0-p247/gems/railties-3.2.17/lib/rails/commands.rb:55:in block in <top (required)>' from /home/vagrant/.rvm/gems/ruby-2.0.0-p247/gems/railties-3.2.17/lib/rails/commands.rb:50:in tap' 来自/home/vagrant/.rvm/gems/ruby-2.0.0-p247/gems/railties-3.2.17/lib/rails/commands.rb:50:in <top (required)>' from script/rails:6:inrequire' 来自脚本/rails:6:in `'

【问题讨论】:

看看代码:'config/initializers/tire.rb:20' 基于它发出http请求并失败的错误 @house9 感谢 house9,我用 config/initializers/tire.rb 中的 ruby​​ 文件编辑了原始帖子,但不确定问题出在哪里……我看到这个 Rails 项目是为了第一次,通过 Vagrant 从别人那里传下来。 先注释掉那个文件,看看能不能启动rails @house9 谢谢,评论了那个愚蠢的文件有效,但现在我有另一个问题......也许我可以在另一个问题上处理它,但你对此有任何想法吗? Rails 服务器显示错误:ActiveRecord::StatementInvalid in PostsController#homepage mysql2::Error: Unknown column 'posts.status' in 'where clause': SELECT posts.* FROM posts WHERE postsstatus = 'PUBLISHED' AND posts.post_type = 'About' AND (title LIKE 'About Ourgoods%') ORDER BY created_at DESC LIMIT 1.... 我在 *.sql 文件中有数据库快照,所以我想我必须把它挂起来 @house9 没关系,我想通了,谢谢!!!! 【参考方案1】:

就像上面评论的house9一样,我基本上注释掉了导致我出现问题的整个ruby文件。

然后我在启动 Rails 服务器时遇到了问题,因为它找不到数据库。所以它抛出了一个 ActiveRecord 错误:

ActiveRecord::StatementInvalid in PostsController#homepage Mysql2::Error:'where 子句'中的未知列'posts.status':SELECT posts.* FROM posts WHERE posts.status = 'PUBLISHED' AND posts.post_type = 'About' AND (title LIKE 'About Ourgoods%') ORDER BY created_at DESC LIMIT 1....

在将我必须的 .sql 文件连接到 Rails 应用程序(按照来自:How do I connect a mysql database file to a local ruby on rails application 的说明)并运行 rake db:migrate 后,我终于让 rails s 工作了!

【讨论】:

以上是关于尝试在 Vagrant vm 上启动 rails 服务器时出错的主要内容,如果未能解决你的问题,请参考以下文章

如何通过Vagrant设置VM名称?

Vagrant上的Rails 4.2服务器端口转发不起作用

如何通过“vagrant ssh”使用 ssh 代理转发?

获取在 Vagrant VM 上运行的 LAMP 堆栈(在 Windows 7 主机下),完整说明?

使用 Vagrant 配置 Windows VM 无法执行远程 WinRM 命令

是否可以通过Packer重新打包在Modern.ie VM或Vagrant Box中启用WinRM?