【问题标题】:connection error with tire/elasticsearch remote server与轮胎/弹性搜索远程服务器的连接错误
【发布时间】:2013-04-06 12:44:27
【问题描述】:

我已经安装了一个带有 elasticsearch 的 ubuntu 12.04 远程服务器。

我已经安装了 elasticsearch:

sudo apt-get update
sudo apt-get install openjdk-7-jre-headless -y
wget https://download.elasticsearch.org/elasticsearch/elasticsearch/elasticsearch-0.20.6.deb
sudo dpkg -i elasticsearch-0.20.6.deb
sudo service elasticsearch start

我得到sudo elasticsearch status

* ElasticSearch Server is running with pid 2483

我的 elasticsearch 远程服务器工作正常:

ubuntu12@juan:~/Escritorio/myapp$ curl http:/111.111.111.111:9200
{
  "ok" : true,
  "status" : 200,
  "name" : "Hogan, Harold \"Happy\"",
  "version" : {
    "number" : "0.20.6",
    "snapshot_build" : false
  },
  "tagline" : "You Know, for Search"
}

或使用我的子域:

ubuntu12@juan:~/Escritorio/myapp$ curl http://elasticsearchserver.mydomain.com:9200
{
  "ok" : true,
  "status" : 200,
  "name" : "Hogan, Harold \"Happy\"",
  "version" : {
    "number" : "0.20.6",
    "snapshot_build" : false
  },
 "tagline" : "You Know, for Search"
}

我可以重启、启动和停止 elasticsearhc 服务器。

sudo service elasticsearch restart
 * Stopping ElasticSearch Server                                                                                                                                                                      [ OK ] 
 * Starting ElasticSearch Server                                                                                                                                                                      [ OK ]

我在config/initializer/ 文件夹中有一个tire.rb 文件,其中包含下一个代码:

if Rails.env == 'production'
  Tire.configure do
    url "http://elasticsearchserver.mydomain.com:9200"
  end
end

这是我重新索引的 capistrano 任务:

after "deploy:finalize_update", "deploy:elasticsearch:index_classes"
namespace :deploy do
  namespace :elasticsearch do
   desc 'run elasticsearch indexing via tire'
    task :index_classes do
      run "cd #{deploy_to}/current && bundle exec rake environment tire:import CLASS=Object FORCE=true "
    end
  end
 end

我使用 mongodb 作为数据库,所以在重新索引之前我没有进行迁移。

这是 capistrano 错误:

2013-04-06 14:25:50 executing `deploy:elasticsearch:index_classes'
 #
 #
 ** [out :: 111.111.111.111] Skipping index creation, cannot connect to Elasticsearch
 ** [out :: 111.111.111.111] 
 ** [out :: 111.111.111.111] (The original exception was: #<Errno::ECONNREFUSED: Connection refused - connect(2)>)
 ** [out :: 111.111.111.111] 
 ** [out :: 111.111.111.111] [IMPORT] Deleting index 'cvs'
 ** [out :: 111.111.111.111] 
 ** [out :: 111.111.111.111] rake aborted!
 ** [out :: 111.111.111.111] Connection refused - connect(2)
 ** [out :: 111.111.111.111]
 #
 #

我已经将轮胎.rb 文件上传到生产服务器,我已经尝试过:

bundle exec rake environment tire:import CLASS=Object FORCE=true

我得到相同的结果:

Skipping index creation, cannot connect to Elasticsearch
(The original exception was: #<Errno::ECONNREFUSED: Connection refused - connect(2)>)
[IMPORT] Deleting index objects'
rake aborted!
Connection refused - connect(2)

我做错了什么?如何修复轮胎/导轨应用和我的 elasticsearch 服务器之间的连接?

【问题讨论】:

    标签: ruby-on-rails ruby-on-rails-3 ruby-on-rails-3.2 elasticsearch tire


    【解决方案1】:

    我认为您的 config/initializers/tire.rb 中的语法有误, 见下文

    Tire.configure do
      url "http://localhost:9200"
      #you can uncomment the next line if you want to see the elasticsearch queries in their own seperate log
      #logger "#{Rails.root}/log/es.log" 
    end
    

    【讨论】:

    • 我在tire.rb 文件中添加了对我来说可以正常工作的语法。谢谢
    • 仅供本文其他读者注意,语法错误。它应该是 url "http...." 不等于。
    【解决方案2】:

    这是在tire.rb 文件中对我来说可以正常工作的语法

    require 'tire'
    Tire.configure { url "http://myremoteserver.com:9200" }
    

    现在它工作正常!

    谢谢!

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-02-14
      • 2020-08-03
      • 2012-03-13
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多