阿里云-云小站(无限量代金券发放中)
【腾讯云】云服务器、云数据库、COS、CDN、短信等热卖云产品特惠抢购

Mongo-connector集成MongoDB到Solr实现增量索引

141次阅读
没有评论

共计 4104 个字符,预计需要花费 11 分钟才能阅读完成。

配置 MongoDB 复制集

部署一个用于测试和开发的复制集

部署复制集

1. 为每个节点建立必要的数据文件夹:

1 mkdir -p /srv/mongodb/rs0-0 /srv/mongodb/rs0-1 /srv/mongodb/rs0-2

2. 通过下述命令来启动 mongod 实例:

第一个节点:

mongod –port 27017 –dbpath /srv/mongodb/rs0-0 –replSet rs0 –smallfiles –oplogSize 128 –logappend –logpath /srv/mongodb/rs0-0/mongod.log &

第二个节点:

mongod –port 27018 –dbpath /srv/mongodb/rs0-1 –replSet rs0 –smallfiles –oplogSize 128 –logappend –logpath /srv/mongodb/rs0-1/mongod.log &

第三个节点:

mongod –port 27019 –dbpath /srv/mongodb/rs0-2 –replSet rs0 –smallfiles –oplogSize 128 –logappend –logpath /srv/mongodb/rs0-2/mongod.log &

3. 我们可以通过下列命令来连接到第一个实例:

mongo –port 27017

4. 在 mongo 中使用 rs.initiate() 来初始化复制集。我们可以通过下列方式来设定复制集配置对象:

rsconf = {
          _id: “rs0”,   
          members: [
                      {
                      _id: 0,   
                      host: “<hostname>:27017”   
                      }   
                    ]   
        }

5. 将 <hostname> 替换为我们的主机名

rs.initiate(rsconf)

6. 查看复制集配置

rs.conf()

7. 使用 mongo 连接到 primary,并用过 rs.add() 命令来添加第二个和第三个 mongod 实例到复制集中。将 <hostname> 替换为我们的主机名。

rs.add(“<hostname>:27018”) 
rs.add(“<hostname>:27019”)

8. 通过 rs.status() 命令来检查复制集的状态。

安装 Solr5.3

参考:《在 CentOS 下安装 Solr5.3》http://www.linuxidc.com/Linux/2015-09/123206.htm

安装 Python2.7

参考:《在 CentOS 下安装 Python2.7》http://www.linuxidc.com/Linux/2015-04/116593.htm

安装 pip

参考:《在 CentOS 下安装 pip》http://www.linuxidc.com/Linux/2015-09/123321.htm

安装 mongo-connector 

方法一:使用 pip 安装

1 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.zip
cd 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 visible
but does not ensure that data is synced to disk. This is
faster 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

更多 MongoDB 相关内容可以看看以下的有用链接

MongoDB 3.0 正式版发布下载  http://www.linuxidc.com/Linux/2015-03/114414.htm

CentOS 编译安装 MongoDB http://www.linuxidc.com/Linux/2012-02/53834.htm

CentOS 编译安装 MongoDB 与 mongoDB 的 php 扩展 http://www.linuxidc.com/Linux/2012-02/53833.htm

CentOS 6 使用 yum 安装 MongoDB 及服务器端配置 http://www.linuxidc.com/Linux/2012-08/68196.htm

Ubuntu 13.04 下安装 MongoDB2.4.3 http://www.linuxidc.com/Linux/2013-05/84227.htm

MongoDB 入门必读(概念与实战并重) http://www.linuxidc.com/Linux/2013-07/87105.htm

Ubunu 14.04 下 MongoDB 的安装指南 http://www.linuxidc.com/Linux/2014-08/105364.htm

《MongoDB 权威指南》(MongoDB: The Definitive Guide)英文文字版[PDF] http://www.linuxidc.com/Linux/2012-07/66735.htm

Nagios 监控 MongoDB 分片集群服务实战 http://www.linuxidc.com/Linux/2014-10/107826.htm

基于 CentOS 6.5 操作系统搭建 MongoDB 服务 http://www.linuxidc.com/Linux/2014-11/108900.htm

MongoDB 的详细介绍:请点这里
MongoDB 的下载地址:请点这里

本文永久更新链接地址:http://www.linuxidc.com/Linux/2015-09/123322.htm

正文完
星哥说事-微信公众号
post-qrcode
 0
星锅
版权声明:本站原创文章,由 星锅 于2022-01-21发表,共计4104字。
转载说明:除特殊说明外本站文章皆由CC-4.0协议发布,转载请注明出处。
【腾讯云】推广者专属福利,新客户无门槛领取总价值高达2860元代金券,每种代金券限量500张,先到先得。
阿里云-最新活动爆款每日限量供应
评论(没有评论)
验证码
【腾讯云】云服务器、云数据库、COS、CDN、短信等云产品特惠热卖中