天天看點

solr7.4定時/實時更新/重建索引配置,及報錯404問題解決方案

本文分兩部分:

一、Solr定時/實時更新/重建索引配置。

二、Solr7+版本,伺服器啟動報錯,頁面404解決方案。(重點)

一、solr定時/實時更新/重建索引配置

準備工作要做好:

    1、下載下傳jar包:solr-dataimportscheduler-1.1.jar (網上也有1.0版本,但是具體對應solr版本請自行查找)

下載下傳位址:http://pan.baidu.com/s/1hsySs2S

     注意注意注意(重要的事情說三遍):當solr7+以上版本時,該jar包會有問題,配置後伺服器啟動會報錯,頁面404,具體詳情後面會有解決方案。

     2、建立檔案:dataimport.properties,檔案複制下面的就好,具體配置含義已給出注釋:

#################################################
#                                               #
#       dataimport scheduler properties         #
#                                               #
#################################################
 
#  to sync or not to sync
#  1 - active; anything else - inactive
# 這裡的配置不用修改
syncEnabled=1
 
#  which cores to schedule
#  in a multi-core environment you can decide which cores you want syncronized
#  leave empty or comment it out if using single-core deployment
#  修改成你所使用的core,我這裡是我自定義的core:simple
syncCores=product_auto
 
#  solr server name or IP address
#  [defaults to localhost if empty]
這個一般都是localhost不會變
server=localhost
 
#  solr server port
#  [defaults to 80 if empty]
#  安裝solr的tomcat端口,如果你使用的是預設的端口,就不用改了,否則改成自己的端口就好了
port=8080
 
#  application name/context
#  [defaults to current ServletContextListener's context (app) name]
#  這裡預設不改
webapp=solr
 
#  URL params [mandatory]
#  remainder of URL
#  這裡改成下面的形式,solr同步資料時請求的連結
params=/dataimport?command=delta-import&clean=false&commit=true
 
#  schedule interval
#  number of minutes between two runs
#  [defaults to 30 if empty]
#這裡是設定定時任務的,機關是分鐘,也就是多長時間你檢測一次資料同步,根據項目需求修改
#  開始測試的時候為了友善看到效果,時間可以設定短一點
interval=1
 
#  重做索引的時間間隔,機關分鐘,預設7200,即5天; 
#  為空,為0,或者注釋掉:表示永不重做索引
reBuildIndexInterval=7200
 
#  重做索引的參數
reBuildIndexParams=/select?qt=/dataimport&command=full-import&clean=true&commit=true
 
#  重做索引時間間隔的計時開始時間,第一次真正執行的時間=reBuildIndexBeginTime+reBuildIndexInterval*60*1000;
#  兩種格式:2012-04-11 03:10:00 或者  03:10:00,後一種會自動補全日期部分為服務啟動時的日期
reBuildIndexBeginTime=03:10:00
           

準備好這一個jar包和dataimport.properties檔案,開始下面的步驟……

步驟一:将solr-dataimportscheduler-1.1.jar包複制到apache-tomcat-7.0.72\webapps\solr\WEB-INF\lib中。

步驟二:在apache-tomcat-7.0.72\webapps\solr\WEB-INF目錄下的web.xml檔案中添加監聽配置(<servlet>标簽前面):

<listener>
   <listener-class>org.apache.solr.handler.dataimport.scheduler.ApplicationListener</listener-class>
 </listener>           

注意(又一個注意的地方):org.apache.solr.handler.dataimport.scheduler.ApplicationListener 後面不能有空格,否則可能會報錯,且很難發現問題原因。

步驟三:在\solrhome目錄下建立一個conf檔案夾(與simple檔案夾同目錄),将dataimport.properties檔案放在conf檔案夾中。

步驟四:重新開機tomcat,通路Solr。

大部分人應該到這裡就搞定了。

但是,但是,但是 這個坑被我踩到了!!!

二、Solr7+版本,伺服器啟動報錯,頁面404解決方案。

但是本人使用Solr版本為7.4 在按照上述教程配置後,Tomcat無法啟動,頁面報錯404。

檢視日志,内容如下:

31-Aug-2018 09:47:43.139 資訊 [localhost-startStop-1] org.apache.catalina.core.ApplicationContext.log ContextListener: contextInitialized()
31-Aug-2018 09:47:43.140 資訊 [localhost-startStop-1] org.apache.catalina.core.ApplicationContext.log SessionListener: contextInitialized()
31-Aug-2018 09:47:43.141 資訊 [localhost-startStop-1] org.apache.catalina.core.ApplicationContext.log ContextListener: attributeAdded('StockTicker', 'async.Stockticker@4f752dd7')
31-Aug-2018 09:47:47.637 嚴重 [localhost-startStop-1] org.apache.catalina.core.StandardContext.listenerStart Exception sending context initialized event to listener instance of class [org.apache.solr.handler.dataimport.scheduler.ApplicationListener]
 java.lang.NoSuchMethodError: org.apache.solr.core.SolrResourceLoader.<init>(Ljava/lang/String;)V
    at org.apache.solr.handler.dataimport.scheduler.SolrDataImportProperties.loadProperties(SolrDataImportProperties.java:36)
    at org.apache.solr.handler.dataimport.scheduler.BaseTimerTask.reloadParams(BaseTimerTask.java:57)
    at org.apache.solr.handler.dataimport.scheduler.BaseTimerTask.<init>(BaseTimerTask.java:39)
    at org.apache.solr.handler.dataimport.scheduler.DeltaImportHTTPPostScheduler.<init>(DeltaImportHTTPPostScheduler.java:20)
    at org.apache.solr.handler.dataimport.scheduler.ApplicationListener.contextInitialized(ApplicationListener.java:47)
    at org.apache.catalina.core.StandardContext.listenerStart(StandardContext.java:4792)
    at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5256)
    at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150)
    at org.apache.catalina.core.ContainerBase.addChildInternal(ContainerBase.java:754)
    at org.apache.catalina.core.ContainerBase.addChild(ContainerBase.java:730)
    at org.apache.catalina.core.StandardHost.addChild(StandardHost.java:734)
    at org.apache.catalina.startup.HostConfig.deployDirectory(HostConfig.java:1140)
    at org.apache.catalina.startup.HostConfig$DeployDirectory.run(HostConfig.java:1875)
    at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511)
    at java.util.concurrent.FutureTask.run(FutureTask.java:266)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
    at java.lang.Thread.run(Thread.java:748)           

經過重重困難,終于找到了解決方案,問題原因是 引入的apache-solr-dataimportscheduler-1.0.jar或者1.1 這個jar包針對高版本solr 有并未及時維護。也就是版本沒有跟上是以産生bug。

有大神已經解決了該問題,且針對該jar反編譯且重新打包了。

solr-dataimport-scheduler.jar

下載下傳位址: https://download.csdn.net/download/vikasdhanve/10637569

更換這個jar包後,然後該問題迎刃而解。

在處理該問題的時候,在網上的确是碰到了很多人跟我一樣的問題,但是始終就沒有人給出一個解決方案。

我這兒就借着大神們的磚搬給大家,也算是個人記錄一下該問題的處理方法吧。

大家有什麼問題可以留言,一起讨論。