CDH-HBASE二级索引

本文详细介绍如何将HBase与Solr集成以实现高效的数据索引和搜索功能。包括配置HBase复制、设置Solr collection、创建LilyHBaseIndexer配置及morphline文件等步骤。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

1.   使用LILY HBASE NRT 索引服务

1.1.    确保整个集群范围的HBase复制启用


 

1.2.    用shell设置column-family的复制功能

a)        对于已存在的表,每个需要建立索引的列簇都需要设置REPLICATION_SCOPE,命令如下:


b)        新建表,用如下命令:

1.3.    创建slor对应的collection

c)         生成实体配置文件

d)        编辑/home/bigdata/xuhailiu/solr/web-collection/conf/schema.xml文件。

         为方便调试,取出了文件中自带的一些字段。

注:其中id字段和_version_两个字段必须保留,id作为habserowkey_version_用于版本的区分。

e)         创建 collection 实例并配置文件上传到 zookeeper

$ solrctl instancedir --create web-collection /home/bigdata/xuhailiu/solr/web-collection

                   验证操作是否成功:

                   登录到zookeeper安装的主机,执行客户端脚本登录:

$ /opt/cloudera/parcels/CDH/bin/zookeeper-client

                   登录成功后执行命令:

ls /solr/configs/web-collection

                   显示结果:

f)         创建collection:

solrctl collection --create web-collection -s 1 -r 2

此时可在solr界面上看到创建的collection

 

1.4.    创建 Lily HBase Indexer 配置

morphline-hbase-mapper.xml

<?xml version="1.0"?>
<indexer table="web_log"
mapper="com.ngdata.hbaseindexer.morphline.MorphlineResultToSolrMapper">
<!-- The relative or absolute path on the local file system to the morphline
configuration file. -->
<!-- Use relative path "morphlines.conf" for morphlines managed by Cloudera Manager
-->
<param name="morphlineFile" value="/home/bigdata/xuhailiu/solr/conf/morphlines.conf"/>
<!-- The optional morphlineId identifies a morphline if there are multiple morphlines
in morphlines.conf -->
<param name="morphlineId" value="morphline1"/>
</indexer>

Ø  Table对应需要映射的hbase表名

Ø  Mapper固定值com.ngdata.hbaseindexer.morphline.MorphlineResultToSolrMapper

Ø  morphlineFile对应的valuemorphlines.conf存放位置

Ø  morphlineId morphlines.conf文件中morphlines属性 id

 

1.5.    创建morphlines.conf文件

morphlines : [
{
id : morphline1
importCommands : ["org.kitesdk.morphline.**", "com.ngdata.**"]
commands : [
{
extractHBaseCells {
mappings : [
{
inputColumn : "cf:host"
outputField : "host"
type : string
source : value
}
{
inputColumn : "cf:level"
outputField : "level"
type : string
source : value

}

{
inputColumn : "cf:url"
outputField : "url"
type : string
source : value

}


]
}
}
#for avro use with type : "byte[]" in extractHBaseCells mapping above
#{ readAvroContainer {} }
#{
# extractAvroPaths {
# paths : {
# data : /user_name
# }
# }
#}
{ logTrace { format : "output record: {}", args : ["@{}"] } }
]
}
]

 

Ø  inputColumn对应hbase中的列簇和列

Ø  outputField对应schema.xml文件中Field

 

1.6.    上传morphlines.conf文件到Key-ValueStore Indexer的每台主机上

       ps:此处通过Key-Value Store Indexer界面的操作方式,有待研究。)

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

hbase-indexer add-indexer \
--name web_index \
--indexer-conf /home/bigdata/xuhailiu/solr/web-collection/morphline-hbase-mapper.xml \
--connection-param solr.zk=dcdev02:2181,dcdev03:2181,dcdev01:2181/solr \
--connection-param solr.collection=web-collection \
--zookeeper dcdev02:2181,dcdev03:2181,dcdev01:2181

验证操作是否成功:

         登录到zookeeper安装的主机,执行命令:

hbase-indexer list-indexers -dump

显示:

1.8.    向Hbase表中插入数据

$ hbase shell
hbase shell> put 'web_log','rowkey1','cf:host','127.0.0.1'

                  solr界面查询结果:



评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值