我已安装了带有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 ]
我在tire.rb
文件夹中有一个config/initializer/
文件,其中包含下一个代码:
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]
#
#
我已经将tire.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)
我做错了什么?如何修复轮胎/轨道应用程序与弹性搜索服务器之间的连接?
答案 0 :(得分:4)
我认为你的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
答案 1 :(得分:1)
这是tire.rb
文件
require 'tire'
Tire.configure { url "http://myremoteserver.com:9200" }
现在它工作正常!
谢谢!