【问题标题】:Errno::ECONNREFUSED (Connection refused... in production environmentErrno::ECONNREFUSED(连接被拒绝...在生产环境中
【发布时间】:2014-11-17 20:27:53
【问题描述】:

我已经完成了我的应用程序,我正在尝试检查生产环境。 该应用程序使用 sunspot_rails gem 进行搜索。它在开发服务器上运行良好,但在生产环境中不起作用。我的生产日志提供以下内容:

Errno::ECONNREFUSED (Connection refused -        {:data=>"fq=type%3AArticle&start=0&rows=1&q=%2A%3A%2A", :method=>:post, :params=>{:wt=>:ruby}, :query=>"wt=ruby", :headers=>{"Content-Type"=>"application/x-www-form-urlencoded; charset=UTF-8"}, :path=>"select", :uri=>#<URI::HTTP:0x007ff38e350578 URL:http://localhost:8983/solr/production/select?wt=ruby>, :open_timeout=>nil, :read_timeout=>nil, :retry_503=>nil, :retry_after_limit=>nil}):
app/controllers/articles_controller.rb:12:in `index'

我该如何解决这个问题?

这是我的articles_controller:

    class ArticlesController < ApplicationController
  before_filter :require_login, except: [:show, :index]
 def index
  @search = Article.search do
  fulltext params[:search]
  paginate :page => params[:page], :per_page => 1
  end
    @articles = @search.results 
  #@articles_by_month = Article.find(:all).group_by { |post| post.created_at.strftime("%B") }
 end
def show
  @article = Article.find(params[:id])
  @comment = Comment.new
 @comment.article_id = @article.id
end
def new
 @article = Article.new
end
def create
 @article = Article.new(article_params)
 @article.save
 redirect_to article_path(@article)
end
def edit
 @article = Article.find(params[:id])
end
def destroy
 @article = Article.find(params[:id])
 @article.destroy
 redirect_to articles_path
end
def update
 @article = Article.find(params[:id])
 @article.update(article_params)
 flash.notice = "Article '#{@article.title}' Updated!"
 redirect_to article_path(@article)
end
def article_params
 params.require(:article).permit(:title, :body, :tag_list, :picture)
end
end

这是我的 Gemfile:

source 'https://rubygems.org'
ruby '2.0.0'
#ruby-gemset=railstutorial_rails_4_0
gem 'rails', '4.0.8'
gem 'bcrypt','3.1.7'
gem 'bootstrap-sass', '3.2.0.0'
gem 'sprockets', '2.11.0'
gem 'carrierwave',             '0.10.0'
gem 'mini_magick',             '3.8.0'
gem 'fog',                     '1.23.0'
gem 'sorcery'
gem 'will_paginate',           '3.0.7'
gem 'bootstrap-will_paginate', '0.0.10'
gem 'sunspot_rails'
gem 'progress_bar'
group :development, :test do
gem 'sqlite3', '1.3.8'
gem 'rspec-rails', '2.13.1'
gem 'sunspot_solr'
end
group :test do
gem 'selenium-webdriver', '2.35.1'
gem 'capybara', '2.1.0'
end
gem 'sass-rails', '4.0.3'
gem 'uglifier', '2.1.1'
gem 'coffee-rails', '4.0.1'
gem 'jquery-rails', '3.0.4'
gem 'turbolinks', '1.1.1'
gem 'jbuilder', '1.0.2'
group :doc do
gem 'sdoc', '0.3.20', require: false
end
group :production do
gem 'pg', '0.15.1'
gem 'rails_12factor', '0.0.2'
end

我该如何解决这个问题?

【问题讨论】:

    标签: ruby-on-rails production-environment sunspot-solr


    【解决方案1】:

    您是否在生产服务器中启动了 solr 实例?

    bundle exec sunspot-solr start -p 8983
    

    【讨论】:

      【解决方案2】:

      我过去曾用 Solr 处理过一些类似的问题。我做了一个script 来为我处理启动它。它确保清理任何可能影响访问的粗劣文件。

      希望对您有所帮助!

      见下文:

      pkill -f solr
      
      #remove old data
      rm -rf solr/data
      rm -rf solr/default
      rm -rf solr/development
      rm -rf solr/pids
      rm -rf solr/test
      
      while getopts 'pdt' flag; do
        case "${flag}" in
          d) export RAILS_ENV=development ;;
          p) export RAILS_ENV=production ;;
          t) export RAILS_ENV=test ;;
          *) error "Unexpected option ${flag}" ;;
        esac
      done
      
      #startup solr
      bundle exec rake sunspot:solr:start
      
      echo "Solr started successfully."
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 2012-04-01
        • 1970-01-01
        • 2011-12-02
        • 1970-01-01
        • 1970-01-01
        • 2013-08-29
        • 2013-08-15
        相关资源
        最近更新 更多