在阿里云EMR下构建云HBase二级索引

一、非HA EMR构建二级索引
云HBase借助Phoenix实现二级索引功能,对于Phoenix二级索引的详细介绍可参考https://yq.aliyun.com/articles/536850?spm=a2c4e.11153940.blogrightarea544746.26.673e7308MxY7Lc
当Phoenix表数据量较大时,可以选择异步构建索引方式,利用MR快速同步索引数据,同时降低HBase服务端负载。
由于云HBase没有MR,需要借助外部计算引擎(自建Hadoop集群或者阿里云EMR),详细操作步骤可参考阿里云瑾谦大神的博客:https://yq.aliyun.com/articles/544746?spm=a2c4e.11153940.blogcont574090.11.28895835Lse5dN

这篇文章主要介绍在非HA的EMR环境下执行bulkload向phoenix表中批量入库,构建二级索引稍有不同,但大体上类类似,只不过将bulkload命令替换成二级索引构建命令:

yarn –config C O N F D I R j a r {PHOENIX_HOME}/phoenix- v e r s i o n c l i e n t . j a r o r g . a p a c h e . p h o e n i x . m a p r e d u c e . i n d e x . I n d e x T o o l d a t a t a b l e T A B L E N A M E i n d e x t a b l e I N D E X N A M E o u t p u t p a t h h d f s : / / h b a s e c l u s t e r / p a t h / {CONF_DIR}是需要创建的用户配置目录,用户需要把配置有云HBase zookeeper信息的hbase-site.xml和云HBase的hdfs-site.xml配置文件放在该目录下。
hbase-site.xml配置:



hbase.zookeeper.quorum
zk1,zk2,zk3


–data-table 是phoenix数据表的表名
–index-table是phoenix中已经创建好的索引表名
–output-path是云HBase集群hdfs的目录,要指定hdfs的nameservice,二级索引的数据本质还是利用BulkLoad生成,HFile文件存放在改目录下,然后再move到索引表中。

二、HA EMR构建二级索引
如果构建二级索引时EMR集群开启了HA,在使用上述步骤过程中,可能会遇到下面的问题:
image
这个问题原因是由于开启HA的EMR集群HDFS的nameservice名跟云HBase的HDFS的nameservice名相同导致的。
解决这个问题需要把云HBase集群HDFS的nameservice改掉,并在EMR集群中把指定hdfs-site.xml配置修改为改动后的云HBase的nameservice名。
注意:修改nameservice需要重启hdfs,有丢数据的风险,请联系工作人员进行操作。
修改步骤如下:
1、 修改nameservice配置项
HDFS修改nameservice名时涉及配置项有:
core-site.xml


fs.defaultFS
hdfs://emr-cluster

hdfs-site.xml


dfs.client.failover.proxy.provider.emr-cluster
org.apache.hadoop.hdfs.server.namenode.ha.ConfiguredFailoverProxyProvider


dfs.nameservices
emr-cluster


dfs.ha.namenodes.emr-cluster
nn1,nn2


dfs.namenode.http-address.emr-cluster.nn1
emr-header-1.cluster-74778:50070


dfs.namenode.http-address.emr-cluster.nn2
emr-header-2.cluster-74778:50070


dfs.namenode.rpc-address.emr-cluster.nn1
emr-header-1.cluster-74778:8020


dfs.namenode.rpc-address.emr-cluster.nn2
emr-header-2.cluster-74778:8020

修改后同步core-site.xml和hdfs-site.xml同步到集群各个节点
滚动重启HDFS

1)重启其中一台namenode:
su hadoop -l -c ‘/usr/lib/hadoop-current/sbin/hadoop-daemon.sh stop namenode’
su hadoop -l -c ‘/usr/lib/hadoop-current/sbin/hadoop-daemon.sh start namenode’

2)依次重启datanode节点:
su hadoop -l -c ‘/usr/lib/hadoop-current/sbin/hadoop-daemon.sh stop datanode’
su hadoop -l -c ‘/usr/lib/hadoop-current/sbin/hadoop-daemon.sh start datanode’

3)重启另外的namenode节点
注意:重启hdfs过程中要注意观察日志,操作不慎会有丢数据风险。
namenode重启成功后,可以按照第一部分操作构建索引了,注意–output-path配置是改动后的云hbase hdfs的nameservice。

猜你喜欢

转载自blog.csdn.net/gydtep/article/details/82585441