2012-04-05 118 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