看起来您应该在使用 Capistrano 的部署中执行此操作。这是一个示例 config/deploy.rb 文件:
[basic parts omitted]
after "deploy", "bundler:bundle_install"
after "bundler:bundle_install", "db:db_migrate"
after "deploy:db_migrate", "deploy:elastic_search_indexing"
namespace :bundler do
desc 'call bundle install'
task :bundle_install do
run "cd #{deploy_to}/current && bundle install"
end
end
namespace :db do
desc 'fire the db migrations'
task :db_migrate do
run "cd #{deploy_to}/current && bundle exec rake db:migrate RAILS_ENV=\"production\""
end
end
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=YourObject FORCE=true "
end
end
[rest omitted]
确保您在 /etc/elasticsearch/elasticsearch.yml 中的目标机器(Linux)上有一个配置文件,其内容如下:
cluster:
name: elasticsearch_server
network:
host: 66.98.23.12
最后要提到的是,您应该创建一个初始化程序 config/initializers/tire.rb:
if Rails.env == 'production'
Tire.configure do
url "http://66.98.23.12:9200"
end
end
如您所见,这是完全相同的 IP 地址,但仅用于生产环境。我假设您通过 localhost 在本地(在开发模式下)访问 elasticsearch。elasticsearch 是默认连接到
http://0.0.0.0:9200
很棒的 Ryan Bates 和他的 Railscasts http://railscasts.com/episodes?utf8=%E2%9C%93&search=capistrano提供了一个很好的起点和深入的帮助