一、非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
{PHOENIX_HOME}/phoenix-
{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。