標籤:solr mongodb replset mongo-connector
Mongo-connector整合MongoDB到Solr實現增量索引
配置MongoDB複製集
參考:《部署一個用於測試和開發的複製集》
安裝Solr5.3
參考:《在CentOS下安裝Solr5.3》
安裝Python2.7
參考:《在CentOS下安裝Python2.7》
安裝pip
參考:《在CentOS下安裝pip》
安裝mongo-connector
方法一:使用pip安裝
pip install mongo-connector
安裝到了ython的預設包目錄下:
/usr/local/lib/python2.7/site-packages
方法二:安裝為服務
1. 去https://github.com/mongodb-labs/mongo-connector/archive/master.zip下載mongo-connector-master.zip。
2. 解壓縮進入目錄。
unzip mongo-connector-master.zipcd mongo-connector-master
3. 編輯設定檔。
vi config.json
4. 安裝為服務。
python setup.py install_service
在/etc/init.d下建立了mongo-connector服務,並拷貝config.json檔案到/etc/mongo-connector.json。
卸載mongo-connector服務
python setup.py uninstall_service
它將移除/etc/init.d/mongo-connector和/etc/mongo-connector.json
查看服務狀態
service mongo-connector status
配置Solr
在Solr資料目錄/data/solr/data/下有Solr設定檔solr.xml
建立core
su - solr -c "/usr/local/solr/solr/bin/solr create -c card -n data_driven_schema_configs"
產生了檔案夾/data/solr/data/card,在/data/solr/data/card/conf目錄下是card的配置目錄,可以配置同義字、停止詞。
配置solrconfig.xml
1. 確保啟用了LukeRequestHandler
以下行應用出現在solrconfig.xml檔案中。
<requestHandler name="/admin/luke" class="org.apache.solr.handler.admin.LukeRequestHandler" />
2. 配置硬提交(重新整理到硬碟上的頻率)和軟提交(提交到記憶體中的頻率)
在solrconfig.xml檔案中配置<autoCommit>和<autoSoftCommit>
<autoCommit><maxTime>300000</maxTime><maxDocs>10000</maxDocs><openSearcher>true</openSearcher></autoCommit><!-- softAutoCommit is like autoCommit except it causes a‘soft‘ commit which only ensures that changes are visiblebut does not ensure that data is synced to disk. This isfaster and more near-realtime friendly than a hard commit.--><autoSoftCommit><maxDocs>1000</maxDocs><maxTime>60000</maxTime></autoSoftCommit>
配置schema.xml
1. Mongo Connector儲存中繼資料在每個文檔中協助處理復原。為了支援這些資料,你需要添加如下資訊到你的schema.xml中:
<field name="_ts" type="long" indexed="true" stored="true" /><field name="ns" type="string" indexed="true" stored="true"/>
2. 在schema.xml中配置配置<uniqueKey>、<field>
啟動mongo-connector
方法一:以命令列啟動
nohup sudo mongo-connector -m localhost:27019 -t http://localhost:8983/solr/card -o oplog_progress.txt -n example.card -u _id -d solr_doc_manager > mongo-connector.out 2>&1
方法二:以服務啟動
service mongo-connector start
Solr刪除全部索引
http://192.168.11.52:8983/solr/card/update/?stream.body=%3Cdelete%3E%3Cquery%3E*:*%3C/query%3E%3C/delete%3E&stream.contentType=text/xml;charset=utf-8&commit=true
參考:
http://blog.mongodb.org/post/29127828146/introducing-mongo-connector
https://github.com/mongodb-labs/mongo-connector/wiki/Installation
https://github.com/mongodb-labs/mongo-connector/wiki/Usage-with-Solr
https://loutilities.wordpress.com/2012/11/26/complementing-mongodb-with-real-time-solr-search/
本文出自 “SQL Server Deep Dives” 部落格,請務必保留此出處http://ultrasql.blog.51cto.com/9591438/1696083
Mongo-connector整合MongoDB到Solr實現增量索引