Tomcat + Solr + MultiCore + MySql 配置过程

本文介绍如何在Tomcat中部署多个Solr核心(core),包括配置步骤与关键文件调整,如solr.xml和solrconfig.xml等。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

参考网址:
http://hadop.iteye.com/blog/1403337
http://lianj-lee.iteye.com/blog/425414
http://www.blogjava.net/conans/articles/379546.html

上一篇《Solr 3.6.2索引MySQL数据库配置过程》只是简单地简介solr + mysql的配置过程。由于项目需要,要在tomcat中运行多个solr的core。这一篇就此而来。


一、试运行多核

1.1首先下载solr3.6.2和tomcat-7.0.40。解压后,
solr3.6.2目录是:D:\Downloads\apache-solr-3.6.2
tomcat7.0.40目录是:D:\Downloads\apache-tomcat-7.0.40


1.2设置solr.home目录。本文章中solr.home路径是:D:\Downloads\apache-tomcat-7.0.40\solr.home


1.3将“\apache-solr-3.6.2\example\webapps”目录下的solr.war复制到“apache-tomcat-7.0.40\webapps”下。


1.4在“apache-tomcat-7.0.40\conf\Catalina\localhost”新建solr.xml文件。将其内容示例如下:

<?xmlversion="1.0"encoding="UTF-8"standalone="yes"?>

<ContextdocBase="D:\Downloads\apache-tomcat-7.0.40\webapps\solr.war"debug="0"crossContext="true">

<Environmentname="solr/home"type="java.lang.String"value="D:\Downloads\apache-tomcat-7.0.40\solr.home"override="true"/>

</Context>


1.5将“apache-solr-3.6.2\example\multicore”目录下的所有文件复制到“solr.home”目录:D:\Downloads\apache-tomcat-7.0.40\solr.home


1.6输入http://localhost:8080/solr/可以查看到core0和core1。


说明:上面配置的核心是solr.xml文件,主要涉及两个路径
docBase:solr.war文件路径。
solr/home:solr.home路径,即多核数据的根目录。



二、配置多核Solr


2.1首先你得熟悉如何在配置一个单核的solr。可以参考:《Solr 3.6.2索引MySQL数据库配置过程


2.2进入按照《Solr 3.6.2索引MySQL数据库配置过程》配置好的solr 3.6.2,进入目录:“apache-solr-3.6.2\example\solr”,将该目录下的所有文件复制到“D:\Downloads\apache-tomcat-7.0.40\solr.home\core0”目录下。


2.3正如《Solr 3.6.2索引MySQL数据库配置过程》提及到的几个配置文件:data-config.xml, schema.xml, solrconfig.xml。其中data-config.xml, schema.xml是数据库的相关的文件,可以根据修改自行修改。我们细看一下solrconfig.xml文件的,找到lib标签中的如下内容:

<libdir="../../dist/"regex="apache-solr-dataimporthandler-\d.*\.jar"/>

<libdir="../../dist/"regex="apache-solr-cell-\d.*\.jar"/>

<libdir="../../contrib/extraction/lib"regex=".*\.jar"/>

<libdir="../../dist/"regex="apache-solr-clustering-\d.*\.jar"/>

<libdir="../../contrib/clustering/lib/"regex=".*\.jar"/>

<libdir="../../dist/"regex="apache-solr-dataimporthandler-\d.*\.jar"/>

<libdir="../../contrib/dataimporthandler/lib/"regex=".*\.jar"/>

<libdir="../../dist/"regex="apache-solr-langid-\d.*\.jar"/>

<libdir="../../contrib/langid/lib/"regex=".*\.jar"/>

<libdir="../../dist/"regex="apache-solr-velocity-\d.*\.jar"/>

<libdir="../../contrib/velocity/lib"regex=".*\.jar"/>

这些目录都是相对路径,是运行solr需要一些jar包。它们的原路径是:
apache-solr-3.6.2\dis; apache-solr-3.6.2\contrib.

为了能够运行在tomcat下,需要将它们apache-solr-3.6.2\dis; apache-solr-3.6.2\contrib目录复制到solr.home目录下。solr.home的目录结构大致如下:

--solr.home

--contrib
--core0
--core1
​--dist
--exampledocs
--readme.txt
--solr.xml

2.4修改\solr.home\core0\conf\solrconfig.xml文件,将lib标签中dir属性改为”../dist/……”或”../contrib/……”。因为dist文件夹和contrib文件夹有变动。


2.5在solr.home\core0目录下新建一个lib文件夹,其中放入IK分词器jar包“IKAnalyzer2012_u6.jar”和mysql驱动文件“mysql-connector-java-5.1.25-bin.jar”。


2.6导入数据的URL地址是:http://localhost:8080/solr/core0/dataimport?command=full-import


2.7 在solr.home 目录下有个solr.xml文件,它的内容如下:

<solr persistent="false">

  <!--
  adminPath: RequestHandler path to manage cores.  
    If 'null' (or absent), cores will not be manageable via request handler
  -->
  <cores adminPath="/admin/cores">
    <core name="core0" instanceDir="core0"/>
    <core name="core1" instanceDir="core1"/>
  </cores>
</solr>
参数说明如下:

1)solr
The <solr> tag accepts two attributes:
persistent - By default, should runtime core manipulation be saved in solr.xml so that it is available after a restart.
sharedLib - Path to a directory containing .jar files that are added to the classpath of every core. The path is relative to solr.home (where solr.xml sits)
2)cores
The <cores> tag accepts two attribute:
adminPath - Relative path to access the CoreAdminHandler for dynamic core manipulation. For example, adminPath="/admin/cores" configures access via http://localhost:8983/solr/admin/cores. If this attribute is not specified, dynamic manipulation is unavailable.
3)core
The <core> tag accepts two attributes:
name - The registered core name. This will be how the core is accessed.
instanceDir - The solr.home directory for a given core.
dataDir - The data directory for a given core. The default is <instanceDir>/data . It can take an absolute path or a relative path w.r.t instanceDir . Solr1.4
4)property
The <property> tag accepts two attributes:
name - The name of the property
value - The value of the property


2.8 其中可能会有其他错误,查看tomcat控制台输出,自行google之。


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值