solr與.net系列課程(六)solr定時增量索引與安全

來源:互聯網
上載者:User

標籤:style   blog   http   color   io   os   ar   使用   strong   

  solr與.net系列課程(六)solr定時增量索引與安全

         solr增量索引的方式,就是一個Http請求,但是這樣的請求顯然不能滿足要求,我們需要的是一個自動的增量索引,solr官方提供了一個定時器執行個體,來完成增量索引,

首先下載 apache-solr-dataimportscheduler-1.0.jar,:http://solr-dataimport-scheduler.googlecode.com/files/apache-solr-dataimportscheduler-1.0.jar

官方地址有時候訪問不了,請點擊這個http://pan.baidu.com/s/1pJt3KZD

下面開始配置

1.將apache-solr-dataimportscheduler-1.0.jar複製到C:\Program Files\Apache Software Foundation\Tomcat 7.0\webapps\solr\WEB-INF\lib (C:\Program Files\Apache Software Foundation\Tomcat 7.0為tomcat安裝路徑)

2.修改C:\Program Files\Apache Software Foundation\Tomcat 7.0\webapps\solr\WEB-INF下的web.xml檔案, 在servlet節點前面增加

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

3.將apache-solr-dataimportscheduler-.jar 中 dataimport.properties 取出,放入C:\Program Files\Apache Software Foundation\Tomcat 7.0\solr\conf,沒有conf建立一個

4.重啟tomcat即可

dataimport.properties 配置項說明

##################################################                                               ##       dataimport scheduler properties         ##                                               ###################################################  to sync or not to sync#  1 - active; anything else - inactivesyncEnabled=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 deploymentsyncCores=game,resource#  solr server name or IP address#  [defaults to localhost if empty]server=localhost#  solr server port#  [defaults to 80 if empty]port=8080#  application name/context#  [defaults to current ServletContextListener‘s context (app) name]webapp=solr#  URL params [mandatory]#  remainder of URLparams=/select?qt=/dataimport&command=delta-import&clean=false&commit=true#  schedule interval#  number of minutes between two runs#  [defaults to 30 if empty]interval=1#  重做索引的時間間隔,單位分鐘,預設7200,即1天; #  為空白,為0,或者注釋掉:表示永不重做索引reBuildIndexInterval=2#  重做索引的參數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

以上是原文,#後面的是注釋,我們來翻譯一下

##################################################                                               ##       dataimport scheduler properties         ##                                               ##################################################syncEnabled=1#要定時的增量索引的核心,多核逗號隔開 collection1, collection2syncCores= collection1# 這個就不用說了,伺服器位址server=192.168.0.9port=8080webapp=solr# 增量索引執行的命令params=/dataimport?command=delta-import&clean=false&commit=true #多長時間執行一次,預設單位分鐘interval=30#下面的,是有人更改了該檔案,新加的定時重建索引,原包是不帶定時重建索引的,只有增量索引,官方的包是不支援下面三句話的,不需要可以刪掉reBuildIndexInterval=7200reBuildIndexParams=/dataimport?command=full-import&clean=true&commit=truereBuildIndexBeginTime=03:10:00

如果大家搜尋其他的文章,會看見有人說官方提供的包有bug,因為官方是用post提交的,但我經過測試,官方的可以正常使用,以上的在本人的項目中可以正常使用.

如果想瞭解在原包中增加定時從建索引的,和該包中的bug的請參考下面的文章  http://www.denghuafeng.com/post-242.html

好了,上述工作完成後,你的solr就可以定時增量索引了,

下面我們來講解一下solr安全性的問題

       瞭解solr後,大家都知道了,solr是通過Http請求去執行所有操作的,那問題就來了,如果別人知道了你的solr伺服器的地址就很危險了,solr的新增和刪除也都是通過http請求來完成的,地址暴漏後,你的資料就容易受到攻擊了.我這裡的解決辦法是,設定tomcat的存取權限,只有固定ip可以訪問,這樣別人就訪問不了你的solr了

修改C:\Program Files\Apache Software Foundation\Tomcat 7.0\conf\server.xml,加入ip限制即可

全域設定,對Tomcat下所有應用生效
                server.xml中添加下面一行,重啟伺服器即可:
               <Valve className="org.apache.catalina.valves.RemoteAddrValve" allow="192.168.1.*" deny=""/> 此行放在</Host>之前。

                例:
               1,只允許192.168.1.10訪問:

                <Valve className="org.apache.catalina.valves.RemoteAddrValve"allow="192.168.1.10" deny=""/>

               2,只允許192.168.1.*網段訪問:<Valve className="org.apache.catalina.valves.RemoteAddrValve" allow="192.168.1.*" deny=""/>

               3,只允許192.168.1.10、192.168.1.30訪 <Valve className="org.apache.catalina.valves.RemoteAddrValve" allow="192.168.1.10,192.168.1.30" deny=""/>

               4,根據主機名稱進行限制:

                  <Valve className="org.apache.catalina.valves.RemoteHostValve" allow="abc.com" deny=""/>

 

 

   

solr與.net系列課程(六)solr定時增量索引與安全

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.