2012-04-05 114 views
7

您能帮我使用Tomcat配置Apache Solr以及如何使用Solr在MS SQL数据库中建立索引。 配置Tomcat以在Tomcat中运行Apache Solr的步骤是什么?Apache solr配置与tomcat 6.0

+0

配置Solr的使用Tomcat - [SolrTomcat(http://wiki.apache.org/solr/SolrTomcat)对于来自SQL数据库索引,您可以检查[DataImportHandler] (http://wiki.apache.org/solr/DataImportHandler) – Jayendra 2012-04-05 09:53:30

+0

这是另一个简洁的解释,值得一提:http://www.javacilar.com/2012/08/indexing-mysql-db-using-solr- tomcat.html Cheers – Javatar 2012-08-27 13:45:55

+0

你是否浏览了http://wiki.apache.org/solr/DataImportHandler中显示的步骤?只需交换指定MySQL的驱动程序部分并使用SQLServer驱动程序即可。我很乐意回答您的任何更具体的问题!我建议你使用Solr 1.4,第一个发布候选版本实际上是在今晚发布的。 – 2009-10-13 18:29:23

回答

20

下面是一步一步的过程,这将有所帮助。

第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 home容器所在的位置。说它放在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 http://localhost:8080/solr/admin/来验证solr是否正在运行。

第2部分:建立与SOLR MSSQL Server中使用数据导入HANDLER

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

第2步:因此,在您的Solr主目录下,所需的基本目录是conf和lib。第一个例子,你可能已经得到第一部分的第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> 

第5步:告诉Solr的关于我们的数据-config.xml文件。这可以通过向solr配置文件solrconfig.xml文件添加请求处理程序来完成。 添加以下requesthandler到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" />) 
+0

Hi Yavar, 我在导入数据时发现以下错误。 HTTP Status 500 - null java.lang.AbstractMethodError at org.apache.solr.handler.RequestHandlerBase.handleRequest – 2012-04-06 08:09:08

+0

您好Vishal,如果您打开另一个问题,您可以粘贴您获得的所有错误日志,以便可能有人知道这可能会有所帮助。这将是一个更好的方法,也请粘贴你得到的整个错误,而不是一个片段。 – Yavar 2012-04-06 10:05:23

+0

嗨Yavar我添加新的问题与整个错误所以请检查它,让我做我的。谢谢。 – 2012-04-06 12:50:42