Apache Solr与Tomcat 6.0的配置

7

你能帮我配置Tomcat下的Apache Solr并教我如何使用Solr在MS SQL数据库中建立索引吗?如何配置Tomcat以运行Apache Solr?


你是否按照http://wiki.apache.org/solr/DataImportHandler中显示的步骤进行了操作?只需更换指定MySQL的驱动程序部分并使用SQLServer驱动程序即可。如果您有任何更具体的问题,我很乐意回答!我建议您使用Solr 1.4,第一个发布候选版实际上将在今晚发布。 - Eric Pugh
Thomas - 还要确保查看Data Import Handler FAQ sheet,因为其中有一条关于设置responseBuffering属性以避免使用Data Import Handler时出现内存错误的评论。我同意Eric的观点,使用Solr 1.4 RC版本是明智的选择,因为Shalin和其他人在Data Import Handler方面做出了很多改进(特别是增量导入方面)。 - Brian
配置Solr和Tomcat - SolrTomcat。如果要从SQL数据库进行索引,请查看DataImportHandler - Jayendra
这是另一个简明的解释,值得一提:http://www.javacilar.com/2012/08/indexing-mysql-db-using-solr-tomcat.html。干杯! - javatar
1个回答

20

以下是一步一步的操作指南。

PART 1: 使用TOMCAT设置SOLR

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

第2步:将SOLR_HOME_DIR/dist/apache-solr-1.3.0.war复制到您的Tomcat Web应用程序目录:$CATALINA_HOME/webapps/solr.war-请注意war文件名的更改。这很重要。

第3步:在您选择的位置创建solr主目录。这是该solr安装的配置所在的位置。最简单的方法是将SOLR_HOME_DIR/examples/solr目录复制到您想要的任何位置,比如将其放置在C:\solr中。

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

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

第6步:停止Tomcat。

第7步:进入该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条目。

步骤8:重新启动Tomcat,一切应该顺利进行。您应该能够通过尝试以下URL验证solr正在运行:http://localhost:8080/solr/admin/

第二部分:使用数据导入处理程序将Solr设置为MSSQL Server

步骤1:下载Microsoft SQL Server JDBC Driver 3.0。只需提取内容即可。在Solr主目录下创建一个文件夹(例如:C:\ solr \ lib)。将上面下载的存档中的sqljdbc4.jar文件复制到其中。

步骤2:所需的基本目录是conf和lib。 第一个即conf可能是在第1部分的第3步得到的,而lib则是第2部分的第1步中创建的目录。

步骤3:转到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>

第五步:告诉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>

第六步:配置schema.xml - 在这个文件中,你可以做很多事情,比如设置字段的数据类型,设置搜索的唯一/主键等。

第七步:启动Tomcat

第八步:现在访问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" />)

你好,Yavar, 在导入数据时我发现了以下错误。HTTP状态500 - 空值 java.lang.AbstractMethodError at org.apache.solr.handler.RequestHandlerBase.handleRequest - Vishal Ranapariya
嗨,Vishal,如果您打开另一个问题并将您在日志中收到的完整错误粘贴在其中,那么也许其他了解该问题的人可以帮助您。这将是更好的方法,而且请粘贴您收到的完整错误,而不仅仅是一小部分。 - Yavar
嗨Yavar,我添加了一个新问题并附上了完整的错误信息,请检查一下并告诉我该怎么做。谢谢。 - Vishal Ranapariya
感谢@Yavar,在两天后我终于让它跑起来了。你的回答中给我最关键的提示是,我在其他很多包含类似教程的网站上都没有找到的关于dataimporthandler jar文件必须被包含在新版本SOLR的lib目录中的提示。 - mrt
@Yavar,如果我为这个问题提供悬赏,你愿意更新Solr 4.3和Tomcat 7的答案吗? - soandos
显示剩余2条评论

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接