solr配置定時任務實現自動構建索引

安裝solr

參見博文:Apache solr入門

配置dataimport

參見博文:Apache solr進階----導入數據庫數據

配置定時任務

  1. 下載jar包,名字:solr-dataimport-scheduler.jar (jar包自行下載,csdn不允許我免費上傳重複資源)
  2. 將jar包上傳到$SOLR_INSTALL_HOME/server/solr-webapp/webapp/WEB-INF/lib目錄下
  3. 修改$SOLR_INSTALL_HOME/server/solr-webapp/webapp/WEB-INF/web.xml文件,加入以下內容:(注意ApplicationListener後不要多複製了空格)
<listener>
        <listener-class>
                org.apache.solr.handler.dataimport.scheduler.ApplicationListener
        </listener-class>
</listener>
  1. 在$SOLR_INSTALL_HOME/server/solr/conf目錄下新增文件 dataimport.properties
  2. 詳細配置文件參數意義如下:
#################################################
#                                               #
#      dataimport scheduler properties          #
#      數據端口調度程序                         #
#                                               #
#################################################
 
#  tosync or not to sync
#  1- active; anything else - inactive
# 1:啓動定時同步程序,其他值均是不啓動
syncEnabled=1
 
# which cores to schedule
#  ina multi-core environment you can decide which cores you want syncronized
# leave empty or comment it out if using single-core deployment
#  修改成你所使用的core,多個core用逗號(英文逗號)隔開
syncCores=instance,esbinstance
 
# 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=8983
 
# application name/context
# [defaults to current ServletContextListener's context (app) name]
#  這裏默認不改(\tomcat\webapp\ 下的solr目錄名)
webapp=solr
 
# URL params [mandatory]
# remainder of URL
# solr同步數據時請求的鏈接, 如果需要定時同步全部core,去掉連接中的entity參數,即爲同步全部core
params=/dataimport?command=delta-import&clean=false&commit=true&optimize=false&wt=json&indent=true&verbose=false&debug=false&entity=INSTANCE_DETAIL
 
# schedule interval
# number of minutes between two runs
# [defaults to 30 if empty]
#這裏是設置定時任務的,單位是分鐘,也就是多長時間你檢測一次數據同步,根據項目需求修改
interval=10
 
#  重做索引的時間間隔,單位分鐘,默認7200,即5天;
#  爲空,爲0,或者註釋掉:表示永不重做索引
reBuildIndexInterval=0
 
#  重做索引的參數
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
  1. 重啓solr,一方面可以通過觀察日誌查看同步情況,再者可以通過在界面查詢數據來驗證定時任務是否有在正常運作
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章