天天看點

二、Solr安裝(Tomcat)安裝環境安裝步驟總結

安裝環境

Windows 7 64bit

Apache-tomcat-8.0.9-windows-x64

Solr-4.9.0

JDK 1.8.0_05 64bit

安裝步驟

Tomcat和JDk的安裝在這裡就略過。

注意:solr4.9要求jdk1.7+

步驟一:

    解壓solr-4.9.0到任意檔案夾,我解壓到D:\Installed Applications\solr-4.9.0\solr-4.9.0目錄下。

步驟二:

    将solr-4.9.0\dist\ solr-4.9.0.war複制到Tomcat webapp/目錄下,最好重命名為solr.war。

步驟三:

    啟動Tomcat,會報錯,這步隻是為了将solr-4.9.0.war解壓,是以手動解壓放在webapp目錄下面也是可行的。

步驟四:

方法一:

    打開webapps\solr\WEB-INF\web.xml

    找到:

  

<!--
<env-entry>
   <env-entry-name>solr/home</env-entry-name>
   <env-entry-value>/put/your/solr/home/here</env-entry-value>
   <env-entry-type>java.lang.String</env-entry-type>
</env-entry>
-->      

這裡是需要配置solr/home,隻需要修改<env-entry-value>/put/your/solr/home/here</env-entry-value>

這個目錄可以自定義,建議就用步驟一解壓的目錄,這裡需要非常注意:在Solr官網的Tutorial裡面有如下一段話:

How Solr Works with Tomcat

The two basic steps for running Solr in any Web application container are as follows:

  1. Make the Solr classes available to the container. In many cases, the Solr Web application archive (WAR) file can be placed into a special directory of the application container. In the case of Tomcat, you need to place the Solr WAR file in Tomcat's webapps directory. If you installed Tomcat with Solr, take a look in tomcat/webapps:you'll see the solr.war file is already there.
  2. Point Solr to the Solr home directory that contains conf/solrconfig.xml and conf/schema.xml. There are a few ways to get this done. One of the best is to define the solr.solr.home Java system property. With Tomcat, the best way to do this is via a shell environment variable, JAVA_OPTS. Tomcat puts the value of this variable on the command line upon startup

從這裡可以看出,<env-entry-value>指向的目錄需要包含conf/solrconfig.xml和conf/schema.xml這兩個檔案,也就意味着在<env-entry-value>所指向的目錄中需要有conf子目錄,我就是因為官網的這段解釋,搞了半天沒有成功,其實是我了解錯了,我認為在solr.solr.home目錄下必須要有子目錄conf,conf裡面包含solrconfig.xml和schema.xml。但是其實conf目錄是放在collection1目錄下面的,collection是solr的一個Instance執行個體,solr中可以配置多個collection,可以有獨立的配置檔案。

我這邊web.xml的配置為:

  

<env-entry>
<env-entry-name>solr/home</env-entry-name>
<env-entry-value>D:/Installed Applications/solr-4.9.0/solr-4.9.0/example</env-entry-value>
<env-entry-type>java.lang.String</env-entry-type>
</env-entry>      

特别需要注意配置裡面使用的是反斜杠"/",而不是windows下預設的"\"。

這裡我是直接指向example檔案夾。

方法二(個人推薦):

在$TOMCAT_HOME/conf/Catalina/localhost目錄下建立solr.xml檔案,内容為:

 

<Context path="/solr" docBase="… /tomcat/webapps/solr.war" debug="0" crossContext="true">
  <Environment name="solr/home" type="java.lang.String" value=" D:/Installed Applications/solr-4.9.0/solr-4.9.0/example " override="true"/>
  這邊需要注意,override需要設定為false,否則每次啟動tomcat都會重新解壓war檔案覆寫掉之前的配置,或者手動解壓後,把context path直接指向檔案夾
</Context>      

步驟五:

    将solr-4.9.0\example\solr目錄下的collection1目錄整體copy到solr-4.9.0\example目錄下。讀者可以自己自定義路徑,web.xml中定義的<env-entry-value></env-entry-type>,這個指向的目錄包含collection1目錄就好了。

步驟六:

    将D:\Installed Applications\solr-4.9.0\solr-4.9.0\example\lib\ext目錄下的jar包copy到apache-tomcat-8.0.9\lib目錄下,也可以copy到webapps\solr\WEB-INF\lib下,讀者可以自行選擇(全局和局部的問題而已)。(如果啟動還是報錯,可以根據提示在solr-4.9.0\dist中找相應的jar包)。

步驟七:

    打開Tomcat conf目錄下的server.xml,找到下面一段代碼添加URIEncoding="UTF-8",添加中文支援。

<Connector port="8080" protocol="HTTP/1.1"
           connectionTimeout="20000"
           redirectPort="8443"
           URIEncoding="UTF-8" />      

步驟八:

    啟動Tomcat,打開浏覽器輸入:http://localhost:8080/solr/admin/,看到啟動畫面就說明安裝成功。

二、Solr安裝(Tomcat)安裝環境安裝步驟總結

總結

由上面的安裝步驟可以看出來,其中步驟四是最核心的一步,這裡面需要了解Solr的運作原理:Solr是類似于Http接口的一種服務,它需要在Web容器(這裡是Tomcat)中部署,運作後,應用程式用Http請求的方式和Solr互動,包括添加索引、查詢等等。是以我們需要在Web容器中部署Solr,并且在Tomcat配置中指明Solr配置的目錄。

在Linux下的安裝方法跟Windows下沒有大的差別。

轉載于:https://www.cnblogs.com/edwinchen/p/3973951.html