在生产环境中使用 Rails 设置 sunspot solr
我尝试了各种链接,但我似乎找不到关于创建与生产中的 Rails 一起运行的 solr 实例的好资源。
我知道您必须为生产设置 solr 服务器。我已经尝试使用 tomcat 设置 solr,但我似乎无法将其链接到 Rails 应用程序。
有什么好的资源可供我使用吗?
谢谢
I have tried various links but I can't seem to find a good resource on creating a running solr instance that works with rails in production.
I understand that you have to setup the solr server for production. I have tried the setup of solr with tomcat but I cant seem to link it to the rails app.
Is there any good resource out there that I could use?
Thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
Sunspot gem 包含
sunspot-solr
二进制文件。最简单的设置就是运行sunspot-solr start
。根据应用程序的部署方式,您还可以在 Capistrano 部署中包含一个任务,该任务使用 Sunspot 提供的 rake 任务来启动 Solr 服务器。即,rake sunspot:solr:start RAILS_ENV=product
。更深入地了解可能涉及:将 Tomcat 安装为独立服务,使用其自己的 init 脚本启动和停止(或 Upstart config),最好由 monit 或 god 监控;在 Tomcat 中下载并部署 solr.war,并配置 solr.xml 以引用磁盘上索引数据的方便位置,
solrconfig.xml
和schema.xml
被存储。Solr wiki 还包含一个关于使用 Tomcat 安装 Solr 和 其他 servlet 容器。
在上述任一自托管选项中,对于 Sunspot 有一点需要牢记:禁用其自动提交,并依赖
solrconfig.xml
autoCommit 设置>。您可以通过在config/sunspot.yml
中设置auto_commit_after_request: false
来禁用这些提交。最后,如果您对外包所有这些更感兴趣,还有我自己的托管 Solr 服务 http://websolr .com/ — 只需点击几下,我们就可以让您启动并运行。
The Sunspot gem includes the
sunspot-solr
binary. The simplest setup would be just to runsunspot-solr start
. Depending on how your application is deployed, you might also include a task in your Capistrano deploy that uses Sunspot's provided rake task to start a Solr server. Namely,rake sunspot:solr:start RAILS_ENV=production
.Getting more in-depth from that could involve: installing Tomcat as a standalone service, started and stopped with its own init script (or Upstart config), ideally monitored by monit or god; downloading and deploying solr.war within Tomcat, and configuring the solr.xml to refer to a convenient location on disk for your index data,
solrconfig.xml
andschema.xml
to be stored.The Solr wiki also includes a page on installing Solr with Tomcat and other servlet containers.
In either of the above self-hosted options, there's an important point to keep in mind with Sunspot: disable its automatic commits, and rely on Solr's own
autoCommit
settings insolrconfig.xml
. You can disable those commits by settingauto_commit_after_request: false
in yourconfig/sunspot.yml
.Finally, if you're more interested in just outsourcing all of this, there's also my own humble hosted Solr service over at http://websolr.com/ — we can have you up and running in just a few clicks.
这篇博客可能会解决您的问题:
在 CentOS 中使用 Jetty 安装 Solr 4.4,并设置 Solr 服务器以与 Sunspot Gem 配合使用。 ( http://blogs.pigrider.com/blogs/26 )
以下是来自博客:
......
8) 将此配置文件 schema.yml 从 Rails 应用程序复制到正在运行的 Solr 4.4 实例的主目录。它将覆盖那里的 Solr 示例配置文件,并将设置 Solr 4.4 服务器以与 Sunspot Gem 一起使用。
cp /RailsApplicationPath/Solr/conf/schema.yml /opt/solr/solr/collection1/conf/。
正在运行的 Solr 4.4 实例的主目录是 /opt/solr/solr/collection1/。您可以从 Solr 管理页面 http:// localhost :8983/solr/admin 找到此信息
9) 将 version 字段添加到配置文件 schema.yml 以满足 Solr 4.4 初始化要求。实际上,需要在文件中添加两行代码。它们是:
配置文件 schema.yml 最终会是这样的:
......
This blog may solve your question:
Install Solr 4.4 with Jetty in CentOS, and set up Solr server to work with Sunspot Gem. ( http://blogs.pigrider.com/blogs/26 )
Below are some parts from the blog:
......
8) Copy this configuration file schema.yml from your Rails application to the home directory of the running Solr 4.4 instance. It will overrider the Solr example configuration file there, and it will set up Solr 4.4 server to work with Sunspot Gem.
cp /RailsApplicationPath/Solr/conf/schema.yml /opt/solr/solr/collection1/conf/.
The home directory of the running Solr 4.4 instance is /opt/solr/solr/collection1/. You can find this information from Solr admin page http:// l o c a l h o s t :8983/solr/admin
9) Add version field into the configuration file schema.yml to satisfy Solr 4.4 initialization requirement. Actually, two lines of code need to be added into the file. They are:
The configuration file schema.yml eventually will look like:
......