繁体   English   中英

Apache solr 配置 tomcat 6.0

[英]Apache solr configuration with tomcat 6.0

您能帮我配置Apache Solr使用Tomcat以及如何在MS SQL数据库中使用Solr。

以下是会有所帮助的分步过程。

第 1 部分:设置 SOLR 和 TOMCAT

第 1 步:下载 Solr。它只是一个 zip 文件。

第 2 步:从您的 SOLR_HOME_DIR/dist/apache-solr-1.3.0.war 复制到您的 tomcat webapps 目录:$CATALINA_HOME/webapps/solr.war – 注意 war 文件名更改。 这很重要。

第 3 步:在您选择的位置创建您的 solr 主目录。 这是 solr 安装的配置所在的位置。 最简单的方法是将 SOLR_HOME_DIR/examples/solr 目录复制到您希望 solr 主容器所在的位置。 说把它放在 C:\solr。

第 4 步:希望您已经设置了环境变量,如果没有请设置 JAVA_HOME、JRE_HOME、CATALINA_OPTS、CATALINA_HOME。 请注意,CATALINA_HOME 指的是您的 Tomcat 目录,而 CATALINA_OPTS 指的是您要提供给 Solr 的堆 memory 的数量。

第 5 步:启动 tomcat。请注意,这仅是允许 tomcat 解压您的 war 文件所必需的。 如果您在 $CATALINA_HOME/webapps 下查看,现在应该有一个 solr 目录。

第 6 步:停止 tomcat

第七步:Go进入solr目录,编辑WEB-INF/web.xml。 向下滚动,直到看到如下所示的条目:

<!-- People who want to hardcode their "Solr Home" directly into the
     WAR File can set the JNDI property here...
 -->
<!--
  <env-entry>
     <env-entry-name>solr/home</env-entry-name>
     <env-entry-value>/Path/To/My/solr/Home/solr/</env-entry-value>
     <env-entry-type>java.lang.String</env-entry-type>
  </env-entry>
-->

设置您的 Solr 主页(例如:C:\solr)并取消注释 env 条目。

第八步:再次启动Tomcat,应该一切顺利。 您应该能够通过尝试 url http://localhost:8080/solr/admin/来验证 solr 是否正在运行。

第 2 部分:使用数据导入处理程序在 MSSQL 服务器上设置 SOLR

第一步:下载微软SQL服务器JDBC驱动3.0。 只需提取内容。 在您的 solr 主目录下创建一个文件夹(示例:C:\solr\lib)。 将文件 sqljdbc4.jar 从上面下载的存档复制到其中。

第 2 步:因此,在您的 Solr 主目录下,所需的基本目录是 conf 和 lib。 第一个,即您可能在第 1 部分的第 3 步中获得的 conf 和 lib 是您在第 2 部分的第 1 步中创建的目录。

步骤 3. Go 到 conf 目录。 请在您的编辑器中打开 3 个文件:data-config.xml、schema.xml 和 solrconfig.xml。

步骤 4. 首先编辑 data-config.xml。 放置您的 SQL 查询、数据库名称、服务器名称等。例如:

•   <dataConfig>
•   <dataSource type="JdbcDataSource" driver="com.microsoft.sqlserver.jdbc.SQLServerDriver" url="jdbc:sqlserver://X.Y.Z.U:1433;databaseName=myDB" user="test" password="tester" /> 
•   <document>
•   <entity name="Text" query="select DocumentId, Data from Text">
•   <field column="DocumentId" name="DocumentId" /> 
•   <field column="Data" name="Data" /> 
•   </entity>
•   </document>
•   </dataConfig>

第 5 步:告诉 Solr 我们的 data-config.xml 文件。 这将通过将请求处理程序添加到 solrconfig.xml 文件(即 solr 配置文件)来完成。 将以下请求处理程序添加到 solrconfig.xml:

•   <requestHandler name="/dataimport"   class="org.apache.solr.handler.dataimport.DataImportHandler">
•   <lst name="defaults">
•   <str name="config">C:\solr\conf\data-config.xml</str> 
•   </lst>
•   </requestHandler>

第 6 步:配置 schema.xml - 在此文件中,您可以执行多项操作,例如设置字段的数据类型、设置搜索的唯一/主键等。

第七步:启动Tomcat

第 8 步:现在访问http://localhost:8080/solr/admin/dataimport.jsp?handler=/dataimport并开始完全导入。

一些方便的注意事项:

    •   There are a number of reasons a data import could fail, most likely due to problem with
 the configuration of data-config.xml. To see for sure what's going on you'll have to look in
 C:\tomcat6\logs\catalina.*.

    •   If you happen to find that your import is failing due to system running out of memory,
 however, there's an easy, SQL Server specific fix. Add responseBuffering=adaptive and
 selectMethod=cursor to the url attribute of the dataSource node in data-config.xml. That stops the
 JDBC driver from trying to load the entire result set into memory before reads can occur.

    •   Note that by default the index gets created in C:\Tomcat6\bin\solr\data\index. To change this path
 just edit solrconfig.xml & change <dataDir>${solr.data.dir:./solr/data}</dataDir>.

    •   In new Solr versions, I think 3.0 and above you have to place the 2 data import handler
 jars in your solr lib directory (i.e. for example apache-solr-dataimporthandler-3.3.0.jar & apache-
solr-dataimporthandler-extras-3.3.0.jar). Search for them in your Solr zip you downloaded. In older
 Solr versions this is not required because they are bundled with solr.war. Since we have placed the
 data import handlers in the lib directory so we need to specify their paths in solrconfig.xml. Add
 this line to solrconfig.xml: (Example: <lib dir="C:/solr/lib/" regex="apache-solr-dataimporthandler-
\d.*\.jar" />)

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM