且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何访问E-MapReduce中HBase集群

更新时间:2022-02-27 17:44:46

一、创建HBase集群

E-MapReduce在EMR-1.2.0版本开始支持HBase(1.1.1)了,创建集群时注意点如下:

1)选择付费类型

创建集群的基本信息页面可选择付费类型,包括包年包月和按量付费两种,一般HBase集群都是长期存在的,所以选择包年包月价格更实惠
如何访问E-MapReduce中HBase集群

2)选择软件版本配置

产品版本选择EMR-1.2.0及以上版本,集群类型选择HBASE,目前EMR支持的HBase版本号为1.1.1。
如何访问E-MapReduce中HBase集群

3)集群网络配置

可以选择将HBase集群创建在经典网络环境或者专有网络环境(VPC)经典网络和专有网络不通

所以:

  • 如果在EMR中已有经典网络环境的Hadoop集群或者ECS需要访问HBase,那么需要选择经典网络
  • 其它场景***推荐选择VPC,如用户自有IDC需要访问EMR的HBase

如何访问E-MapReduce中HBase集群

如何访问E-MapReduce中HBase集群

4)集群节点配置

HBase集群至少3个节点,推荐配置4核16GB/SSD云盘
如何访问E-MapReduce中HBase集群

如上根据自己的需求,即可一键完成HBase集群的部署安装,接下来就可以对HBase集群进行读写。

二、访问EMR的HBase集群

网络

访问HBase集群的前提是网络能通,而且能够访问HBase集群的相关端口

端口号 进程
2181 Zookeeper
16000 HMaster
16020 HRegionServer

下面列举一下常见的网络场景(不包括登陆HBase集群访问HBase):

日常办公环境测试访问HBase

    日常办公环境不能访问HBase集群中的HRegionServer机器(只有ECS的内网IP),所以只能通过Thrift访问HBase,并且master节点需要公网IP以及安全组开放9090端口

途径 备注
经典网络HBase Thrift master节点有公网IP并开放9090端口
专有网络HBase Thrift master节点有公网IP并开放9090端口

公司自有IDC环境访问HBase

公司自有IDC访问EMR的HBase只能将HBase集群创建在VPC中,然后利用阿里云的高速通道-自行专线接入访问VPC实现IDC和VPC的HBase网络互通。

途径 备注
经典网络HBase 无法访问
专有网络HBase 高速通道

阿里云经典网络环境中的ECS机器访问HBase

    阿里云的经典网络环境和VPC网络不通,所以HBase只能创建在经典网络中才能实现网络互通。

途径 备注
经典网络HBase 同一个安全组或开放安全组端口号 2181/16000/16020
专有网络HBase 无法访问

阿里云VPC环境访问HBase

HBase集群必须创建在VPC中。

  • 处于同一个VPC中:访问机器和HBase集群在同一个安全组,或者HBase集群开放端口给访问的机器
  • 处于不同VPC中:通过高速通道打通两个VPC网络,然后开放HBase端口
途径 备注
经典网络HBase 无法访问
专有网络HBase 直接访问/高速通道

访问HBase的几种方式

2.1节介绍了要访问HBase的前提,即网络要能通,接下来介绍访问HBase的几种方式

HBase Shell

步骤:

a.登陆master节点

b.进入HBase shell,然后进行HBase操作(建表/读写等)

>sudo su hdfs
>hbase shell

HBase-Client

工程中引用maven依赖

    <dependencies>
        <dependency>
            <groupId>org.apache.hbase</groupId>
            <artifactId>hbase-client</artifactId>
            <version>1.1.1</version>
        </dependency>
    </dependencies>

HBase-spring-template

在Spring框架下访问HBase,具体详见Spring with HBase,另外github上面有相关示例可参考。

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xmlns:context="http://www.springframework.org/schema/context"
    xmlns:hdp="http://www.springframework.org/schema/hadoop"
    xmlns:p="http://www.springframework.org/schema/p"
    xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
    http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd
    http://www.springframework.org/schema/hadoop http://www.springframework.org/schema/hadoop/spring-hadoop.xsd">

    <context:property-placeholder location="hbase.properties"/>

    <context:component-scan base-package="org.springframework.samples.hadoop.hbase"/>

    <hdp:configuration id="hadoopConfiguration">
        <!--注释掉-->
      <!--fs.defaultFS=hdfs://localhost:8020-->
    </hdp:configuration>
    
    <hdp:hbase-configuration configuration-ref="hadoopConfiguration" zk-quorum="${hbase.zk.host}" zk-port="${hbase.zk.port}"/>
    
    <bean id="hbaseTemplate" class="org.springframework.data.hadoop.hbase.HbaseTemplate">
        <property name="configuration" ref="hbaseConfiguration"/>
    </bean>

</beans>

Thrift

a.登陆master节点启动thrift2服务(目前没有默认启动thrift2服务)

sudo su hdfs
hbase-daemon.sh start thrift2

b.生成Java语言的HBase-thrift client

  • 本地安装thrift客户端
linux:
    >cd /etc/yum.repos.d/
    >wget -c http://download.opensuse.org/repositories/home:/jblunck:/messaging/CentOS_CentOS-6/home:jblunck:messaging.repo
    >yum install thrift
    
mac:
    >brew install thrift
>thrift -strict --gen java:hashcode ./hbase-thrift/src/main/resources/org/apache/hadoop/hbase/thrift2/hbase.thrift

c.利用HBase-thrift client编写代码,实现本地访问HBase,详见HBase-1.1.1源码包中的hbase-examples/src/main/java/org/apache/hadoop/hbase/thrift2/DemoClient.java示例。

Hive

a.登陆Hive集群节点
b.进入Hive shell,示例详见Hive HBase Integration

>hive
>set hbase.zookeeper.quorum=10.46.74.14,10.25.5.96,10.25.5.118;
>create table hbasetable(key int, value string)
 stored by 'org.apache.hadoop.hive.hbase.HBaseStorageHandler'
 with serdeproperties ("hbase.columns.mapping" = ":key,cf1:val")
 tblproperties ("hbase.table.name" = "xyz");

Spark

参照spark-hbase-connector

Hadoop

参照HBase MapReduce Examples