HBase亿级数据秒级查询实践

一、Cloudera Manager安装如下插件

image.png

二;HBase部分

1;HBase需要开启复制功能


image.png

2;建表
新建表,需要开启复本功能:
create "person_data",{NAME => "info", REPLICATION_SCOPE => 1}
如果表已存在:
disable ‘表名’
alter ‘表名’,{NAME => ‘列族名’, REPLICATION_SCOPE => 1}
enable ‘表名’

三;SolrCloud部分
1;创建solrCloud
solrctl --zk xuehai-dn:2181,xuehai-nn:2181,xuehai-cm:2181/solr instancedir --generate /opt/hbaseSolrConf

2;修改配置文件/opt/hbaseSolrConf/conf/schemal.xml
name:属性的名称,这里有个特殊的属性“version”是必须添加的。
type:字段的数据结构类型,所用到的类型需要在fieldType中设置。
indexed:是否创建索引。
stored:是否存储原始数据。如果不需要返回该字段而只需要通过该字段索引,则可设置为false。
required:添加文档时,该字段必须存在,类似mysql的not null。

3;初始化collection
solrctl --zk xuehai-dn:2181,xuehai-nn:2181,xuehai-cm:2181/solr instancedir --create personDataCollection /opt/hbaseSolrConf/conf

4;新建collection
solrctl --zk xuehai-dn:2181,xuehai-nn:2181,xuehai-cm:2181/solr collection --create personDataCollection -s 3 -r 2 -m 8

-s表示设置分片Shard数为3,建议设置为SolrCloud集群的机器数
-r表示设置的Replica数为1,创建的副本数为1,建议设置为2及其以上
-m默认值是1,表示最大shards数目,应大于Shard*Replica
-c是指定zk上solr/configs节点下使用的配置文件名称
-a是允许添加副本

5;查看是否创建成功

solrctl --zk xuehai-dn:2181,xuehai-nn:2181,xuehai-cm:2181/solr collection --list

四;HBase Index部分

1;在CMweb端,修改Morphline配置文件(修改完后,需要重启生效,若需要针对多个列族或多个表创建索引,则可以增加morphlines,每个morphlines之间以逗号进行分隔。)

image.png

2;2;修改morphline-hbase-mapper-personData.xml,并上传至/opt/hbaseSolrConf
(file://C:\Users\root\AppData\Local\Temp\enhtmlclip\morphline-hbase-mapper-personData.xml)

3;添加Index
hbase-indexer add-indexer
--name personDataIndex
--indexer-conf /opt/hbaseSolrConf/morphline-hbase-mapper-personData.xml
--connection-param solr.zk=xuehai-dn:2181,xuehai-nn:2181,xuehai-cm:2181/solr
--connection-param solr.collection=personDataCollection
--zookeeper xuehai-dn:2181,xuehai-nn:2181,xuehai-cm:2181

4;查看Index
hbase-indexer list-indexers --zookeeper xuehai-dn:2181,xuehai-nn:2181,xuehai-cm:2181

image.png

同步历史数据:

hadoop --config /etc/hadoop/conf.cloudera.yarn \
jar /opt/cloudera/parcels/CDH/lib/hbase-solr/tools/hbase-indexer-mr-*-job.jar \
-D 'mapred.child.java.opts=-Xmx1024m' \
--conf /etc/hbase/conf/hbase-site.xml \
--log4j /opt/cloudera/parcels/CDH/share/doc/search*/examples/solr-nrt/log4j.properties \
--hbase-indexer-file /opt/hbaseSolrConf/morphline-hbase-mapper-personData.xml \
--morphline-file /opt/hbaseSolrConf/morphlines.conf \(备注:将上面的Morphline配置文件复制一份即可)
--verbose \
--go-live \
--zk xuehai-dn:2181,xuehai-nn:2181,xuehai-cm:2181/solr \
--collection personDataCollection

删除索引:

1;删除Index
hbase-indexer delete-indexer --name personDataIndex --zookeeper xuehai-dn:2181,xuehai-nn:2181,xuehai-cm:2181

2;删除collection所有的doc
solrctl collection --deletedocs personDataCollection

3;删除collection
solrctl collection --delete personDataCollection

4;删除instancedir
solrctl instancedir --delete personDataCollection

上述指令会将Collection进行删除,并将zookeeper中包含该Collection信息的collection和config进行清空。
如果需要彻底删除某个Collection,需按顺序执行以上四条指令,并将/opt/hbaseSolrConf清空,即删除掉schema.xml

参考:
https://blog.csdn.net/qq_34842671/article/details/86496983

https://blog.csdn.net/liwenbluesky/article/details/89049517

©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容