SolrReplication 试用

Solr 1.4 版(未发布)开始有 SolrReplication 的东西,它是分布式复制组件。在 Solr 1.4 以下的版本完全靠 solr.home/bin 目录下的脚本来完成子机从主机复制索引文件。造成了平台有关了(只能在 unix 类操作系统下使用)。windows 平台下基本没戏(排除自己写复制的细节)。Solr 1.4 引进 SolrReplication 非常不错,这样 windows 平台下有福了,同时还提供 HTTP 的 API,可以方便做一些复杂的处理。

Solr 1.4 主要特性:

  • 复制不需要额外的脚本。
  • 仅仅在 solrconfig.xml 配置就行。
  • 同时还可以复制配置文件,如:schema.xml。
  • 使用相同的配置跨平台地工作。
  • 不依赖操作系统的硬链接
  • 紧密集成在 Solr 中,有管理界面、有足够的 api 控制复制的细节。

安装并试用:

到 nightly 下载:http://people.apache.org/builds/lucene/solr/nightly/,如我下载的是 solr-2009-07-15.zip。比较大 150 M 左右。

解压,结构如 F:\solr-2009-07-15\apache-solr-nightly\example。为了下面的解说把这目录称为“example.home”

复制 example.home/solr 目录为 example.home/solr-slave 作为子机的 solr。

修改 example.home/solr/conf/solrconfig.xml 配置,把下面的内容去掉注释。

  1. <requestHandler name="/replication" class="solr.ReplicationHandler" >  
  2.     <lst name="master">  
  3.         <str name="replicateAfter">commit</str>  
  4.          <str name="confFiles">schema.xml,stopwords.txt</str>  
  5.     </lst>  
  6. </requestHandler>  

修改slave 的 example.home/solr-slave/conf/solrconfig.xml 配置,把下面的内容去掉注释,看起来这样。

  1. <requestHandler name="/replication" class="solr.ReplicationHandler">  
  2.     <lst name="slave">  
  3.         <str name="masterUrl">http://localhost:8080/solr/replication</str>  
  4.         <str name="pollInterval">00:00:60</str>  
  5.      </lst>  
  6. </requestHandler>  

把两个 solr、solr-slave 安装到 tomat,安装与以前一样,请看:Solr 使用入门介绍,以搜索论坛帖子为示例

我这里用 solr.xml、solr-slave.xml 放到 F:\apache-tomcat-6.0.18\conf\Catalina\localhost 目录下。

安装好后到 example.home/exampledocs 目录提交数据做索引,上面给出的博文也讲到怎么提交数据给 solr。

提交完后,可以在 example.home/solr/data/index 看到索引文件。过一分钟,可以在 example.home/solr-slave/data/index 也索引文件。说明索引复制成功。

主索引的状态界面:http://localhost:8080/solr/admin/replication/index.jsp

master index face

master index face

子索引的状态界面:http://localhost:8080/solr-slave/admin/replication/index.jsp,它会不停地刷新状态。

slave index face

slave index face

主索引相关的 HTTP 管理 API:

子索引相关的 HTTP 管理 API:

有了这些复制索引的 HTTP api,做一些细节的控制就好多了。期待正式发布……

posted @ 2009-09-16 12:12  searchDM  阅读(376)  评论(0编辑  收藏  举报