简体   繁体   English

Apache solr 配置 tomcat 6.0

[英]Apache solr configuration with tomcat 6.0

Can you help me configuring Apache Solr using Tomcat and how to index in MS SQL database using Solr. What are the steps to configure Tomcat to run Apache Solr in Tomcat.您能帮我配置Apache Solr使用Tomcat以及如何在MS SQL数据库中使用Solr。

Here is the step by step procedure that would help.以下是会有所帮助的分步过程。

PART 1: SETTING UP SOLR with TOMCAT第 1 部分:设置 SOLR 和 TOMCAT

Step 1: Download Solr. It's just a zip file.第 1 步:下载 Solr。它只是一个 zip 文件。

Step 2: Copy from your SOLR_HOME_DIR/dist/apache-solr-1.3.0.war to your tomcat webapps directory: $CATALINA_HOME/webapps/solr.war – Note the war file name change.第 2 步:从您的 SOLR_HOME_DIR/dist/apache-solr-1.3.0.war 复制到您的 tomcat webapps 目录:$CATALINA_HOME/webapps/solr.war – 注意 war 文件名更改。 That's important.这很重要。

Step 3: Create your solr home directory at a location of your choosing.第 3 步:在您选择的位置创建您的 solr 主目录。 This is where the configuration for that solr install resides.这是 solr 安装的配置所在的位置。 The easiest way to do this is to copy the SOLR_HOME_DIR/examples/solr directory to wherever it is you want your solr home container to be.最简单的方法是将 SOLR_HOME_DIR/examples/solr 目录复制到您希望 solr 主容器所在的位置。 Say place it in C:\solr.说把它放在 C:\solr。

Step 4: Hope you have set your environment variables, if not then please set JAVA_HOME, JRE_HOME, CATALINA_OPTS, CATALINA_HOME.第 4 步:希望您已经设置了环境变量,如果没有请设置 JAVA_HOME、JRE_HOME、CATALINA_OPTS、CATALINA_HOME。 Note that CATALINA_HOME refers to your Tomcat directory & CATALINA_OPTS refers to the amount of heap memory you want to give to your Solr.请注意,CATALINA_HOME 指的是您的 Tomcat 目录,而 CATALINA_OPTS 指的是您要提供给 Solr 的堆 memory 的数量。

Step 5: Start tomcat. Note this is only necessary to allow tomcat to unpack your war file.第 5 步:启动 tomcat。请注意,这仅是允许 tomcat 解压您的 war 文件所必需的。 If you look under $CATALINA_HOME/webapps there should now be a solr directory.如果您在 $CATALINA_HOME/webapps 下查看,现在应该有一个 solr 目录。

Step 6: Stop tomcat第 6 步:停止 tomcat

Step 7: Go into that solr directory and edit WEB-INF/web.xml.第七步:Go进入solr目录,编辑WEB-INF/web.xml。 Scroll down until you see an entry that looks like this:向下滚动,直到看到如下所示的条目:

<!-- 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>
-->

Set your Solr home (for example: C:\solr) and uncomment the env entry.设置您的 Solr 主页(例如:C:\solr)并取消注释 env 条目。

Step 8: Start Tomcat again, and things should be going splendidly.第八步:再次启动Tomcat,应该一切顺利。 You should be able to verify that solr is running by trying the url http://localhost:8080/solr/admin/ .您应该能够通过尝试 url http://localhost:8080/solr/admin/来验证 solr 是否正在运行。

PART 2: SETTING UP SOLR WITH MSSQL SERVER USING DATA IMPORT HANDLER第 2 部分:使用数据导入处理程序在 MSSQL 服务器上设置 SOLR

Step 1: Download Microsoft SQL Server JDBC Driver 3.0.第一步:下载微软SQL服务器JDBC驱动3.0。 Just extract the contents.只需提取内容。 Create a folder under your solr home directory (Example: C:\solr\lib).在您的 solr 主目录下创建一个文件夹(示例:C:\solr\lib)。 Copy the file sqljdbc4.jar out of the archive downloaded above into it.将文件 sqljdbc4.jar 从上面下载的存档复制到其中。

Step 2: So under your Solr home the basic directories needed are conf and lib.第 2 步:因此,在您的 Solr 主目录下,所需的基本目录是 conf 和 lib。 The first one ie conf you might have got with Step 3 of part 1 & lib is the directory you have created in Step 1 of part 2.第一个,即您可能在第 1 部分的第 3 步中获得的 conf 和 lib 是您在第 2 部分的第 1 步中创建的目录。

Step 3. Go to conf directory.步骤 3. Go 到 conf 目录。 Please open 3 files in your editor: data-config.xml, schema.xml & solrconfig.xml.请在您的编辑器中打开 3 个文件:data-config.xml、schema.xml 和 solrconfig.xml。

Step 4. Start by editing data-config.xml.步骤 4. 首先编辑 data-config.xml。 Place your SQL query, DB Name, Server name etc. For an example:放置您的 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>

Step 5: Tell Solr about our data-config.xml file.第 5 步:告诉 Solr 我们的 data-config.xml 文件。 This would be done by adding a request handler to the solrconfig.xml file which is solr configuration file.这将通过将请求处理程序添加到 solrconfig.xml 文件(即 solr 配置文件)来完成。 Add the following requesthandler to solrconfig.xml:将以下请求处理程序添加到 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>

Step 6: Configure schema.xml - In this file you can do several stuff like setting up datatypes of your fields, setting unique/primary key of your search etc.第 6 步:配置 schema.xml - 在此文件中,您可以执行多项操作,例如设置字段的数据类型、设置搜索的唯一/主键等。

Step 7: Start Tomcat第七步:启动Tomcat

Step 8: Now visit http://localhost:8080/solr/admin/dataimport.jsp?handler=/dataimport & start your full import.第 8 步:现在访问http://localhost:8080/solr/admin/dataimport.jsp?handler=/dataimport并开始完全导入。

Some handy Notes:一些方便的注意事项:

    •   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