我已经完成了我的应用程序,我正在尝试检查生产环境。 该应用程序使用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
如何解决此问题?
答案 0 :(得分:1)
您是否在生产服务器中启动了solr实例?
bundle exec sunspot-solr start -p 8983
答案 1 :(得分:0)
我过去曾与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."