solr-hbase二级索引及查询解决方案(一)

发布时间:2018-02-28 21:41,

浏览次数:636

, 标签:

solr

hbase

最近要搞一个查询功能,是把hbase中的数据方便的查询出来.之前根据rowkey的查询方式,尽管有针对性设计过rowkey,有前缀查询,后缀查询,以及正则查询,但是实际上不够用.

参考了网络上的设计,建立二级索引是比较好的思路.于是就以solr存储hbase里面的列索引,实现了这个功能.

需要的组件有:

1.hbase

2.solr

3.key-value store indexer

4.CDH

5.zookeeper

6.hadoop

key-value store indexer

是一个基于hbase的replication特性而实现的能够动态的将hbase的二级索引同步给solr的组件,并且可以批量导入索引,增量同步索引,同步时延比较小,几乎近实时.

需要的组件看起来有些多,由于我们本来是用CDH管理组件,所以这里也是在CDH中搭建环境的.当然,单独安装组件也可以,不过容易出错,本人之前单独安装配置了solr,却感觉接下来无从下手,喜欢动手的可以一试.

在CDH中安装好以上环境.具体安装配置,方式,CDH有介绍.

7.cdh安装solr集群

8.安装key-value store indexer 集群

这里的集群,hadoop,hbase用了4台机器,其它的都用了3台机器,机器数量不一致,但是zookeeper,solr机器数量最好一致,因为zookeeper集群数量在2n+1时最为稳定.

SOLR-HBASE-INDEXER安装

1.cdh安装solr集群

solr的java heap内存配置改成1G.

2.安装key-value store indexer 集群

3.Hbase表需要开启REPLICATION复制功能

create 'table',{NAME => 'info', REPLICATION_SCOPE => 1}

其中1表示开启replication功能,0表示不开启,默认为0

4.对于已经创建的表可以使用如下命令

disable 'table' alter 'table',{NAME => 'info', REPLICATION_SCOPE => 1} enable

'table'

5.生成实体配置文件, /testhbase/cdhsolr/testIndex是自定义路径,可以自己设置

solrctl instancedir --generate /testhbase/cdhsolr/testIndex

6.编辑生成好的scheme.xml文件

把hbase表中需要索引的列添加到scheme.xml

filed节点,其中的name属性值要与Morphline.conf文件中的outputField属性值对应

"false" required="true"/>

stored="true" multiValued="false" required="true"/>

修改solrconfig.xml 文件中autoCommit. 这里还可以调整同步间隔,比如把60000改成120000.

${solr.autoCommit.maxTime:60000}

true

7.创建collection实例并配置文件上传到zookeeper,命令

solrctl instancedir --create testIndex /testhbase/cdhsolr/testIndex

8.上传到zookeeper之后,其他节点就可以从zookeeper下载配置文件。接下来创建collection,命令:可指定分片数和副本数量

solrctl collection --create testIndex -s 3 -r 3 -m 50

9.在Hbase-solr的安装目录(cdh目录下面)下,创建Lily HBase Indexer配置文件morphline-hbase-mapper.xml

vi /testhbase/cdhsolr/testIndex/conf/hbase-indexer/morphline-hbase-mapper.xml

morphline-hbase-mapper.xml文件内容:

<?xml version="1.0" encoding="UTF-8"?>

"com.ngdata.hbaseindexer.morphline.MorphlineResultToSolrMapper">

"morphlineFile" value="morphlines.conf">

="testIndexMap">

其中morphlineId 的value是对应Key-Value Store Indexer 中配置文件Morphlines.conf

中morphlines 属性id值

Morphlines.conf 文件配置,下文有说明.

mkdir /testhbase/cdhsolr/testIndex/conf/hbase-indexer cp

/testhbase/cdhsolr/hbase-indexer/morphline-hbase-mapper.xml

/testhbase/cdhsolr/testIndex/conf/hbase-indexer/morphline-hbase-mapper.xml

10.修改Morphlines 文件, 具体操作:进入Key-Value Store

Indexer面板->配置->查看和编辑->属性-Morphline文件,

inputColumn:Hbase的CLOUMN

outputField:Solr的Schema.XML配置的fields

morphlines : [ { id :testIndexMap importCommands : ["org.kitesdk.**",

"com.ngdata.**"] commands : [ { extractHBaseCells { mappings : [ { inputColumn

: "info:COL1" outputField : "COL1" type : string source : value }, {

inputColumn : "info:COL2" outputField : "COL2" type : string source : value } ]

} } { logDebug { format : "output record: {}", args : ["@{}"] } } ] } ]

11.注册Lily HBase Indexer configuration 和 Lily Hbase Indexer Service

hbase-indexer add-indexer \ --name testIndex \ --indexer-conf

/testhbase/cdhsolr/testIndex/conf/hbase-indexer/morphline-hbase-mapper.xml \ -

-connection-param solr.zk=c2:2181,c3:2181,c4:2181/solr \ --connection-param

solr.collection=testIndex \ --zookeeper c2:2181,c3:2181,c4:2181

12.验证索引器是否成功创建

hbase-indexer list-indexers

如果出现下图所示,则表示索引创建成功.

13.测试put数据查看结果

当写入数据后,稍过几秒我们可以在相对于的solr中查询到该插入的数据,表明配置已经成功

put 'solr_test_table','r1','info:COL1','123456'

14.使用IK分词器(这里我下了一个solr5以上版本适用的IK jar包)

在/home/parcels/CDH/lib/solr/webapps/solr/WEB-INF创建classes目录

把IKAnalyzer.cfg.xml 和 stopword.dic添加到classes目录

把IKAnalyzer2012FF_u1.jar添加到/opt/cloudera/parcels/CDH/lib/solr/webapps/solr/WEB-INF/lib目录

在Schema.xml中添加

"org.wltea.analyzer.lucene.IKAnalyzer"/>

isMaxWordLength="true" class="org.wltea.analyzer.lucene.IKAnalyzer"/>

fieldType>

配置好后,更新ZK配置文件,重启solr服务

15.扩展命令

Scheme.xml新增索引字段

执行以下命令更新配置:

solrctl instancedir --update testIndex /testhbase/cdhsolr/testIndex solrctl

collection--reload testIndex hbase-indexer update-indexer -n testIndex

添加多个索引器

当你需要创建多个索引时,可以按下面说明操作。

一个solr

索引对应一个collection,一个collection对一个morphline-hbase-mapper.xml和Morphlines.conf。当需要配置多个索引时,在Morphlines.conf的morphlines节点添加对应索引模块,以id区分,如下面代码模块:

morphlines : [

{

id :testIndexMap

importCommands : [“org.kitesdk.“, “com.ngdata.“]

commands : [

{

extractHBaseCells {

mappings : [

{

inputColumn : “info:COL1”

outputField : “COL1”

type : string

source : value

},

{

inputColumn : “info:COL2”

outputField : “COL2”

type : string

source : value

}

]

}

}

{ logDebug { format : “output record: {}”, args : [“@{}”] } }

]

},

{

id :testIndexMap2

importCommands : [“org.kitesdk.“, “com.ngdata.“]

commands : [

{

extractHBaseCells {

mappings : [

{

inputColumn : “info2:COL1”

outputField : “COL1”

type : string

source : value

},

{

inputColumn : “info2:COL2”

outputField : “COL2”

type : string

source : value

}

]

}

}

{ logDebug { format : “output record: {}”, args : [“@{}”] } }

]

}

]

16.Hbase表数据到SOLR集群迁移

在CDH5.3.2中Hbase-indexer提供了MapReduce来批量构建索引的方式,该MapReduce封装在如下jar包中,只需用命令行执行:

/home/parcels/CDH-5.3.2-1.cdh5.3.2.p0.10/lib/hbase-solr/tools/hbase-indexer-mr-1.5-cdh5.3.2-job.jar

如果对一个已经存在数据的hbase表做了索引,会发现只记录了后面插入的数据,已经存在的数据没有索引。那么就要将之前的数据的索引同步上。

运行同步命令需要在有morphlines.conf文件的目录进行。在hbase的master节点上,执行命令:

find / | grep morphlines.conf$

进入最新的那个process目录/run/cloudera-scm-agent/process/345-ks_indexer-HBASE_INDEXER,本人是在solrcloud

的leader core所在节点上操作,当然最好找最新的process. ks_indexer-HBASE_INDEXER 前面的数字最大,表示最新.

(如果想不进入目录执行,则在命令中加上 –morphline-file

/run/cloudera-scm-agent/process/345-ks_indexer-HBASE_INDEXER/morphlines.conf,来指定目录所在位置

)

在进入的目录中,将morphlines.conf文件拷到该目录.

执行命令:

hadoop --config /etc/hadoop/conf \ jar /home/parcels/CDH-5.12.0-1.cdh5.12.0.p0

.29/lib/hbase-solr/tools/hbase-indexer-mr-1.5-cdh5.12.0-job.jar \ --conf

/etc/hbase/conf/hbase-site.xml \ --hbase-indexer-file

/testhbase/cdhsolr/testIndex/conf/hbase-indexer/morphline-hbase-mapper.xml \ --

zk-host c2:2181,c3:2181,c4:2181/solr \ --collection testIndex \ --reducers 0 \

--go-live

等待完成,这样,hbase中的数据的二级索引就批量导进solr中.

17.卸载索引

solr删除索引,一般只能一条一条的删,当然可以写程序批量删除.

如果是删除建立的testIndex索引,删除步骤:

hbase-indexer delete-indexer -n testIndex solrctl collection --delete testIndex

solrctl collection--list solrctl instancedir --delete testIndex solrctl

instancedir--list

删除hadoop上core目录:

export HADOOP_USER_NAME=solr hdfs dfs -rm -r /solr/*

清空回收站:

hdfs dfs -expunge

删除索引物理目录:

rm -rf /testhbase/cdhsolr/testIndex

以上操作是必须项.

有必要的时候,还要清理zookeeper上和solr有关(/solr),和indexer有关(/ngdata),和hbase有关(/hbase)

清理/var/lib/solr中创建的core目录下面的与indexer配置相关的文件

重启solr-server服务,重启Lily hbase indexer服务.

18.报错解决思路.

执行17步骤的流程,能解决大部分错误.除此之外,可以删除/tmp中跟solr有关文件,/home/yarn/userCache中跟solr有关文件,

solr分片所在目录中的文件,总之,尽量先清除solr的残余缓存,core文件,再重启solr,Lily hbase indexer等服务.

参考资料:

http://blog.csdn.net/u010936936/article/details/78064148

http://blog.csdn.net/zgjdzwhy/article/details/68059751

http://www.niuchaoqun.com/14543825447680.html

http://www.zhangrenhua.com/2017/02/10/Hbase%E4%BD%BF%E7%94%A8Solr%E4%BA%8C%E7%BA%A7%E7%B4%A2%E5%BC%95(Lily%20Hbase%20Index)/

等.

(非常感谢以上作者提供的细致解答)

java分词器和索引器_solr-hbase二级索引及查询解决方案(一)相关推荐

  1. 使用solr构建hbase二级索引

    使用solr构建hbase二级索引 @(HBASE)[hbase, solr] 使用solr构建hbase二级索引 一概述 一业务场景描述 二技术方案 1技术方案一 2技术方案二 3关于索引的建议 二 ...

  2. 基于Solr的Hbase二级索引

    关于Hbase二级索引 HBase 是一个列存数据库,每行数据只有一个主键RowKey,无法依据指定列的数据进行检索.查询时需要通过RowKey进行检索,然后查看指定列的数据是什么,效率低下.在实际应 ...

  3. (转)HBase二级索引与Join

    二级索引与索引Join是Online业务系统要求存储引擎提供的基本特性.RDBMS支持得比较好,NOSQL阵营也在摸索着符合自身特点的最佳解决方案. 这篇文章会以HBase做为对象来探讨如何基于Hba ...

  4. hbase组合rowkey_「从零单排HBase 11」HBase二级索引解决方案

    HBase一个令人惋惜的地方,就是不支持二级索引.因此,社区有了很多补充方案来填补HBase的二级索引能力的缺陷. 今天,我们就来看看有哪些二级索引方案,通过对比各个方案的优缺点,并结合我们的具体场景 ...

  5. CDH 6 安装 Hbase 二级索引 Solr + Key-Value Store Indexer

    目录 一.集群安装Solr +  Key-Value Store Indexer 二.创建Hbase二级索引 1.更改表结构,允许复制 2.创建相应的SolrCloud集合 3.创建 collecti ...

  6. Phoenix+Hbase二级索引

    使用的软件版本,注意软件版本很重要,很重要 apache-phoenix-5.0.0-HBase-2.0-bin.tar.gz hadoop-2.9.2.tar.gz hbase-2.0.5-bin. ...

  7. 基于ES的HBase二级索引方案

    HBase不支持多条件查询,不提供二级索引,难以满足用户对检索功能多样性和高效率两方面的需求.由索引模块的需求分析可知,本文解决通过,提出数据与索引的分离,利用HBase数据库的存储模式灵活多变,容纳 ...

  8. 华为HBase 二级索引调研

    1.Overall Solution 解决思想: 一个user table对应一个index table index的创建与更新全部在RS端的cp-processor里实现 核心思想:一个actual ...

  9. 阿里云EMR异步构建云HBase二级索引

    一.非HA EMR构建二级索引 云HBase借助Phoenix实现二级索引功能,对于Phoenix二级索引的详细介绍可参考https://yq.aliyun.com/articles/536850?s ...

  10. Hbase 二级索引 Solr int字段排序问题 can not sort on multivalued field

    Hbase Solr 同步二级索引后,进行int字段排序时报错 报错如下 {"responseHeader":{"zkConnected":true," ...

最新文章

  1. 连表/子查询/计算的sql
  2. iframe 按比例缩放_不按常理出牌!5个Excel灵异事件,能让你崩溃
  3. 编写高质量代码改善C#程序的157个建议——建议157:从写第一个界面开始,就进行自动化测试...
  4. 读锁调度导致高延迟的 case 一例
  5. 肖鹏:微博数据库那些事儿(图灵访谈)
  6. 并行流 线程池_使用自定义线程池处理并行数据库流
  7. 谷歌guava_Google Guava BiMaps
  8. 【Python】os库的使用
  9. 【opencv学习】【图像的阈值处理】
  10. 【学堂在线数据挖掘:理论方法笔记】第二天(3.18)
  11. Eclipse问题提示
  12. iOS硬解码H264视频流
  13. 浅析:通过自定义DSL实现一个序列号生成器
  14. win7怎样设置计算机休眠时间,win7休眠时间怎么设置
  15. Vue中常用的开发小技巧-让开发更便捷快速-总结
  16. timedatectl的详细用法
  17. 华强北再也没法生产散装 iPhone 了
  18. java线程读写互相影响_求助。多线程读取文件相互影响
  19. 微信公众号客服功能如何开通?
  20. php右小角弹出框,js右下角弹出提示框示例代码

热门文章

  1. Tensorflow2.0图像预处理
  2. MTK9255/Mstar投影仪使用screencap截屏图片无内容的问题处理
  3. 数据库约束的一些用法总结(constraint)
  4. ajax一般格式,ajax标准格式
  5. 通信原理笔记—码间串扰与波形传输无失真的条件(奈奎斯特第一准则)
  6. 英语计算机答题卡模板,英语答题卡模板.doc
  7. HashMap的长度为什么是2的N次方
  8. 波特率,比特率,数据传输速率,Shannon,Nyquist
  9. 区块链汽车租赁系统设计
  10. 自动驾驶感知——激光雷达基本概念|激光雷达点云|激光雷达的标定