petrel919 发表于 2015-11-12 09:08:06

Solr Multicore意义

  转帖地址:http://aixiangct.blog.163.com/blog/static/9152246120111128114423633/

  Solr Multicore意义
         Solr Multicore 是 solr 1.3的新特性。其目的一个solr实例,可以有多个搜索应用。< xmlnamespace prefix =&quot;o&quot; ns =&quot;urn:schemas-microsoft-com:office:office&quot; />
         我们既可以把不同类型的数据放到同一index中,也可以使用分开的多indexes。基于这一点,你只需知道如何使用多indexes(实际上就是运行Solr的多实例)。尽管如此,为每一个类型添加一个完整的Solr实例会显得太臃肿庞大。
      Solr1.3引入了Solr core的概念,该方案使用一个Solr实例管理多个indexes,这样就有热点core(hotcore)的重读(reloading)与交换(swap,通常是读index与写index交换),那么管理一个core或index也容易些。每个Solr core由它自己的配置文件和索引数据组成。在多core执行搜索和索引几乎和没有使用core一样。你只是添加core的名字为各自不同的URL。单core情况下的如下搜索:
  http://localhost:8983/solr/select?q=dave%20matthews
  在多core环境下,你可以通过如下方式访问一个名为mbartists的core:
  http://localhost:8983/solr/core0/select?q=dave%20matthews
  并非在URL中引入core name的参数名值对,而是用不同的context。这样就可以像在单core中执行你的管理任务,搜索,更新操作。
  
  MultiCore的配置方法
  1、找到solr下载包中的example文件夹,在它的下面有个multicore文件夹,将这个文件夹下面的core0、core1和solr.xml拷贝到c:\solr-tomcat\solr下面。
  注意:有一个 solr.xml(这只是默认文件,当然也可以指定别的文件),如:
  <?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot; ?>
           <solr persistent=&quot;false&quot;>   
           <cores adminPath=&quot;/admin/cores&quot;>
               <core name=&quot;core0&quot; instanceDir=&quot;core0&quot; />
               <core name=&quot;core1&quot; instanceDir=&quot;core1&quot; />
           </cores>
           </solr>
  
  这个文件是告诉solr应该加载哪些core,<cores>……</cores>里有core0、core1。core0(可以类比以前的solr.home)/conf目录下有schema.xml与solrconfig.xml,可以把实际应用的/solr/conf/schema.xml复制过来(注意:solrconfig.xml不要复制)。
  
  2、启动tomcat,访问应用,就可以看到有 Admin core0和 Admin core1
  http://192.168.10.1:8080/solr/
  http://192.168.10.1:8080/solr/core0/admin/
  http://192.168.10.1:8080/solr/core1/admin/
  http://192.168.10.1:8080/solr/core1/admin/analysis.jsp
  
  3、采用上面的默认solr.xml,索引文件将存放在同一个目录下面,在这里将存放在C:\solr-tomcat\solr\data,如果你想更改目录,或者两个应用存放在不同的目录,请参见下面的xml。
  <core name=&quot;core0&quot; instanceDir=&quot;core0&quot;>
      <property name=&quot;dataDir&quot; value=&quot;/opt/solr-tomcat/solr/data/core0&quot; />
   </core>
  <core name=&quot;core1&quot; instanceDir=&quot;core1&quot;>
      <property name=&quot;dataDir&quot; value=&quot;/opt/solr-tomcat/solr/data/core1&quot; />
   </core>
  
  
  You can also specify properties in solr.xml which can be used in the solrconfig.xml and schema.xml files.
  <solr persistent=&quot;true&quot; sharedLib=&quot;lib&quot;>
  <property name=&quot;snapshooter&quot; value=&quot;/home/solr-user/solr/bin/snapshooter.sh&quot; />
  <cores adminPath=&quot;/admin/cores&quot;>
  <core name=&quot;core0&quot; instanceDir=&quot;core0&quot;>
  <property name=&quot;dataDir&quot; value=&quot;/data/core0&quot; />
  </core>
  <core name=&quot;core1&quot; instanceDir=&quot;core1&quot; />
  </cores>
  </solr>
  
一些关键的配置值是:  1.Persistent=&quot;false&quot;指明运行时的任何修改我们不做保存。如拷贝。如果你想保存从启动起的一些改动,那就把 persistent设置为true。如果你的index策略是完成建index到一个纯净的core中然后交换到活动core 那么你绝对应该设为true。
  2.sharedLib=&quot;lib&quot;指明了所有core的jar文件的lib目录。如果你有一个core有自己需要的jar文件,那么你可以把他们置入到core/lib目录。例如:karaoke core 使用 Solr Cell来索引化富文本内容,因此那些用来解析和抽取富文本的jar文件被放到./examples/cores/karaoke/lib/.
  
  为何使用多core
  Solr实例支持多core比启用多index要好(do more)。多core同时解决了在生产环境下的一些关键需求:
  1.重建索引
  2.测试配置变更
  3.合并索引
  4.运行时重命名core
  为何多core不是默认的?
  多core是1.3版本中才加的,1.4后更成熟。我们强烈建议你使用多core,既是你现在的solr.xml只配置了一个core,虽然会比单个索引稍复杂,但可以带来管理core上的好处。或许一天单个core可能最终RELOADand STATUS命令,又或许单个core最终会被废禁。多个core会是Solr将来支持大规模分布式索引的关键。因此,以后可以期待更多。
你可以得到更多的关于Solr的资料:http://wiki.apache.org/solr/CoreAdmin。
页: [1]
查看完整版本: Solr Multicore意义