设为首页 收藏本站
查看: 3123|回复: 0

[经验分享] Solr4.4中配置multicore

[复制链接]

尚未签到

发表于 2015-11-12 08:54:53 | 显示全部楼层 |阅读模式
  自己对solr也是新手,所以很多东西也不够了解,这里只是记录一下自己的学习过程。


  主要参考资料:
  


  • http://wiki.apache.org/solr/Solr.xml%204.4%20and%20beyond
  • http://wiki.apache.org/solr/Core%20Discovery%20%284.4%20and%20beyond%29
  • http://wiki.apache.org/solr/CoreAdmin
  
  本文主要记述SOLR4.4版本与旧版本在multicore配置方面的不同之处,所以引用了很多官方文档的内容,由于自己也是刚接触solr而且水平也低,因此可能介绍地不明不白,如果有疑问请移步到上面列出的官方wiki文档。
  



有关solr multicore的简介


  关于solr multicore的介绍请参照官方的相关wiki页面:
  http://wiki.apache.org/solr/CoreAdmin


  该wiki上有这样几句话来介绍solr multicore:
  In solr, the "multi core" concept refers to the ability to have multiple cores running in the same webapp.
  Multiple cores let you have a single Solr instance with separate configurations and indexes, with their own config and schema for very different applications, but still have the convenience of unified
administration. Individual indexes are still fairly isolated, but you can manage them as a single application, create new indexes on the fly by spinning up new SolrCores, and even make one SolrCore replace another SolrCore without ever restarting your Servlet
Container.



  自己的英文不好,就不试着翻译了,想必都能看出来大体意思。multicore是在solr1.3中加入的,其目的就是运行一个solr实例,可以有多个搜索应用(这是别人的原话,引用一下)。
  



solr4.4中的multicore


  在solr4.4之前的版本中,multicore都是在%SOLR_HOME%/solr.xml中配置的,虽然我没有使用过较旧版本的solr,但这从网上一些教程上可以看得出来。比如这里:
  


  • http://blog.chenlb.com/2009/01/try-solr-multicore.html
  • http://blog.iyunv.com/jiushuai/article/details/8080758
  
  大体配置如下所示:
  

<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>
  但solr4.4版本中的multicore相对于以前版本改变是非常大的,这些改变可以从以下两个页面看到:


  • http://wiki.apache.org/solr/Solr.xml%204.4%20and%20beyond
  • http://wiki.apache.org/solr/Core%20Discovery%20%284.4%20and%20beyond%29
  从上面的页面中可以看出,从solr4.4开始,%SOLR_HOME%下的solr.xml结构发生变化,这些变化在5.0中将会强制执行。下面是官方wiki的介绍:



  • Optionally as of Solr4.4 and mandatory for Solr5.0,
    the structure of the solr.xml file has changed. In a nutshell, <cores> and <core> have been replaced by auto-discovering cores. Whether to use old or new-style core definitions is determined by whether the <cores> tag is present in solr.xml. In 5.0, presence
    of the <cores> tag will generate an error on startup.

  • An optional property coreRootDirectory can cause the discovery process to start at an arbitrary directory other than SOLR_HOME.

  • We'll distribute a new-style solr.xml as the default in the example directory with Solr4.4

  • The sharedLib attribute on the top-level <solr> element is replaced by a child str element (see below). In theory, the old mechanism should continue to support sharedLib,
    but SOLR-4791 documents the fact that it doesn't work in 4.3.0.
  
  上面几段话的大体意思是从Solr4.4开始在solr.xml文件中取消了<cores/>节点,用自动探测cores来代替,这个改变在Solr4.4时是可选的,而从Solr5.0开始强制采用。
  



SOLR4.4中multicore的自动检测
  


  那么SOLR是如何自动探测cores的呢?wiki同样有相关的描述:


Core discovery process


  
Exploration of the core tree terminates when a file named core.properties is encountered. Discovery of a file of that name is assumed to define the root of a core. There is no a-priori limit
on the depth of the tree. That is, the directories under the core root are explored until a core.properties file is encountered, and that directory is assumed to be the instanceDir for that core. Subdirectories of any directory that has a core.properties file
are NOT examined for additional cores.

  从上面的介绍中可以看到,探测将从core root开始(core root可以在solr.xml文件中以coreRootDirectory属性定义),不限制深度地递归遍历其所有子目录,直到一个名为core.properties的配置文件被发现。含有该core.properties文件的目录将被当作一个core的instanceDir目录,并且该目录下的子目录即使再含有core.properties文件也不会被当作另外core的instanceDir。
  那么core.properties文件都可配置哪些信息呢?如下所示:


  • name - the name of the core. If not specified, the name comes from the containing directory.
  • config - the configuration file. Defaults to solrconfig.xml
  • dataDir - the directory where the index, tlog, etc. are stored. Again, since this is discovery-based, omit this unless you have special needs.
  • ulogDir - where the transaction log resides. It may be advantageous to put the transaction lot on a different disk than the index.
  • schema - the schema file. Defaults to schema.xml
  • shard - the shard ID.
  • collection - the collection to which this core belongs

  • roles - SolrCloud role definition
  • properties - properties file to override core definitions. TBD: This is probably obsolete since we're reading a properties file in the first place. Is there a use case for supporting this now?

  • loadOnStartup - [true|false] this core should be loaded and a searcher opened when Solr starts.

  • transient - [true|false] this core may be unloaded if the core cache exceeds transientCacheSize (defined in solr.propreties)

  • coreNodeName - SolrCloud core node name

所有的配置项都有相应的解释,也很简单,这里就不作过多解释。  


  • 注1:如果core.properties文件是空的,也就是说里面没有任何文字内容,那么这个core的名字将与core.properties文件所在的目录名相同。比如一个空的core.properties文件出现在目录/solr/home/core1中, 则core的名字默认为 &quot;core1&quot;,instanceDir 就是 /solr/home/core1,dataDir 就是 /solr/home/core1/data目录等。
  • 注2:很容易想像地到,如果要临时忽略掉一个core,那么最简单的方式就是将该core对应的instanceDir目录中的core.properites文件重命名,比如core.properties.bak。
  • 注3:上面提到在SOLR4.4版本solr.xml中的cores节点是可选的,也就是可有可无。是否含有cores节点将作为该solr.xml被按照新样式还是旧样式解析的依据,如果我们既在solr.xml文件中配置的了cores节点又在instanceDir目录中放置了core.properties文件,那么solr.xml文件中的配置优先。
  



实例配置
  


  前面的内容都是空泛的理论,下面记一下自己的配置。
  我的SOLR_HOME定义在/opt/tomcat-6.0.37/webapps/solr/solr_home目录,目录结构如下:
DSC0000.jpg


  其中我的solr.xml文件中没有定义<cores/>节点,那么该solr.xml将被当作新样式的配置文件解析,也就是说SOLR将自动探测cores的定义。另外该目录下的collection1和core1子目录均含有core.properties配置文件,其中core1目录下的core.properties文件是空的,collection1目录下的core.properties文件只有一行内容:
  name=core0
  &#20540;得注意的是collection1和core1两个目录结构是相&#20284;的,不同的仅是core.properties文件和各自的schema.xml配置文件,其目录结构大体如下所示:
DSC0001.jpg


  


  那么,根据上面的介绍,collection1和core1目录都会被当作core的instanceDir,两个core的名字分别为core0和core1。
  启动Tomcat,浏览器访问的时候就可以看到在core选择列表上有两个core,分别为core0和core1,贴张图片验证一下:
DSC0002.jpg


  



配置了多core后mmseg4j中自定义词库的配置


  如果是使用绝对路径的话比较简单,直接指定就可以了,如果是使用相对路径,需要注意的是“相对”是相对于当前的core所在路径来说的。
  举个例子就比较清晰了:
  假设我在solr.home中配置了两个core:core1和core2,然后把自定义词库文件放在solr.home中的dict目录,也就是说core1、core2和dict三个目录平级,都存在于solr.home目录中。那么core1和core2中的schema.xml文件中文分词就应该这样配置:
  

<!-- 中文分词 -->
<fieldType name=&quot;text_zh&quot; class=&quot;solr.TextField&quot; positionIncrementGap=&quot;100&quot;>
<analyzer>
<tokenizer class=&quot;com.chenlb.mmseg4j.solr.MMSegTokenizerFactory&quot; mode=&quot;complex&quot;
dicPath=&quot;../dict&quot; />
<filter class=&quot;com.chenlb.mmseg4j.solr.CutLetterDigitFilterFactory&quot;/>
</analyzer>
</fieldType>
<!-- 中文分词 -->
  另外也可以从Solr启动日志中查看词库载入信息,可以发现是相对于core所在目录来说的:
  


DSC0003.jpg


  


  自定义词库文件名需要以words开关,后缀为.dic,例如:words-sg.dic ,词库&#26684;式描述如下:
  http://blog.chenlb.com/2009/04/chinese-segment-mmseg4j-dictionary-format.html


  


  

版权声明:本文为博主原创文章,未经博主允许不得转载。

运维网声明 1、欢迎大家加入本站运维交流群:群②:261659950 群⑤:202807635 群⑦870801961 群⑧679858003
2、本站所有主题由该帖子作者发表,该帖子作者与运维网享有帖子相关版权
3、所有作品的著作权均归原作者享有,请您和我们一样尊重他人的著作权等合法权益。如果您对作品感到满意,请购买正版
4、禁止制作、复制、发布和传播具有反动、淫秽、色情、暴力、凶杀等内容的信息,一经发现立即删除。若您因此触犯法律,一切后果自负,我们对此不承担任何责任
5、所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其内容的准确性、可靠性、正当性、安全性、合法性等负责,亦不承担任何法律责任
6、所有作品仅供您个人学习、研究或欣赏,不得用于商业或者其他用途,否则,一切后果均由您自己承担,我们对此不承担任何法律责任
7、如涉及侵犯版权等问题,请您及时通知我们,我们将立即采取措施予以解决
8、联系人Email:admin@iyunv.com 网址:www.yunweiku.com

所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其承担任何法律责任,如涉及侵犯版权等问题,请您及时通知我们,我们将立即处理,联系人Email:kefu@iyunv.com,QQ:1061981298 本贴地址:https://www.yunweiku.com/thread-138135-1-1.html 上篇帖子: solr空间搜索实现附近酒店的搜索 下篇帖子: Solr DataImportHandler 之一 关系数据库批量和增量导数据
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

扫码加入运维网微信交流群X

扫码加入运维网微信交流群

扫描二维码加入运维网微信交流群,最新一手资源尽在官方微信交流群!快快加入我们吧...

扫描微信二维码查看详情

客服E-mail:kefu@iyunv.com 客服QQ:1061981298


QQ群⑦:运维网交流群⑦ QQ群⑧:运维网交流群⑧ k8s群:运维网kubernetes交流群


提醒:禁止发布任何违反国家法律、法规的言论与图片等内容;本站内容均来自个人观点与网络等信息,非本站认同之观点.


本站大部分资源是网友从网上搜集分享而来,其版权均归原作者及其网站所有,我们尊重他人的合法权益,如有内容侵犯您的合法权益,请及时与我们联系进行核实删除!



合作伙伴: 青云cloud

快速回复 返回顶部 返回列表