標籤:
上一篇我們初識了Solr並且學習了Jetty的啟動方式,查看了Solr的管理介面,這一篇我們來實現在Tomcat上部署運行Solr。
部署環境:
window7
jdk1.6.0_14
Solr-4.7.2
tomcat-6.0.37
Solr的安裝配置Solr home ,主要介紹基於JNDI的配置,其它方式可以參考Solr的wiki。
基於JNDI配置
1:首先建立一個Solr的運行目錄。
C:\solr-tomcat
將解壓縮包中的D:\work\work-tools\solr\solr-4.7.2\solr-4.7.2\example\下的solr目錄拷貝到C:\solr-tomcat下。
2:建立JNDI檔案
在tomcat的D:\work\work-tools\webserver\tomcat-6.0.37\conf\Catalina\localhost下面建立solr.xml檔案。
內容如下:
view sourceprint?
1.<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
2.<Context docBase="D:\work\work-tools\webserver\tomcat-6.0.37\webapps\solr.war" debug="0" crossContext="true" >
3.? <Environment name="solr/home" type="java.lang.String" value="C:\solr-tomcat\solr" override="true" />
4.</Context>
3:修改server.xml的URI編碼
在tomcat的D:\work\work-tools\webserver\tomcat-6.0.37\conf下編輯server.xml
view sourceprint?
1.<Connector port="8080" protocol="HTTP/1.1"
2. connectionTimeout="20000"
3. redirectPort="8443" URIEncoding="UTF-8" />
4:部署solr.war包
把D:\work\work-tools\solr\solr-4.7.2\solr-4.7.2\dist下的solr-4.7.2.war修改為solr.war拷貝到D:\work\work-tools\webserver\tomcat-6.0.37\webapp下。
5:配置日誌
這一步很關鍵,如果不配置會出現以下錯誤
Error filterStart
Context [/solr] startup failed due to previous errors
在這裡看不出到底出現了什麼錯誤,大致只知道在啟動Context /solr的時候,之前有配置出現了錯誤,但是什麼配置我們不知道,這時候可以查看一下tomcat的\tomcat-6.0.37\logs目錄下查看localhost.2014-08-23.log日誌,我們會看到詳細出錯資訊。
view sourceprint?
1.嚴重: Exception starting filter SolrRequestFilter
2.java.lang.NoClassDefFoundError: Failed to initialize Apache Solr: Could not find necessary SLF4j logging jars. If using Jetty, the SLF4j logging jars need to go in the jetty lib/ext directory. For other containers, the corresponding directory should be used. For more information, see: http://wiki.apache.org/solr/SolrLogging
這裡說的很清楚是SLF4J的jar沒有,我們到solr-4.7.2\example\lib\ext下把所有的包都考到tomcat\lib目錄下。
6:啟動tomcat
6:查看solr的admin頁面http://127.0.0.1:8080/solr
總結:這些配置在solr的wiki上都有說明,並且都按照linux和windows分類,其實solr真正的生產環境還是要部署在linux上的,因為Solr提供了一些用於測試及管理、維護較為方便的shell指令碼,這樣在linux營運solr是非常方便的。
註:wiki地址http://wiki.apache.org/solr/SolrTomcat
Solr學習筆記 在Tomcat上部署運行Solr