网络环境

  1. 专线:用户需要把hbase集群的VPC相关网络信息配置到专线里面,可直通hbase环境

  2. 公有云虚拟机VPC环境:选择和hbase通VPC

  3. 其他:需要开hbase公网

  4. 注意:默认导入hbase数据,依赖的hbase-common、hbase-client、hbase-server、hbase-protocol使用社区的包即可。如果是公网需要使用云hbase发布的相关包


方案一:hive关联hbase表方式

  1. 适用场景:数据量不大4T以下(因为需要走hbase的api导入数据)

  2. 从hbase页面获取zk连接地址,并用下述方式启动hive客户端

hive  --hiveconf hbase.zookeeper.quorum=xxxx
  1. hbase表不存在的情况

  • 创建hive表hive_hbase_table映射hbase表base_table,会自动创建hbase表hbase_table,且会随着hive表删除而删除。这里需要指定hive的schema到hbase schema的映射关系。关于类型可参考Hive/HBaseIntegration

CREATE TABLE hive_hbase_table(key int, value string) STORED BY 'org.apache.hadoop.hive.hbase.HBaseStorageHandler'WITH SERDEPROPERTIES ("hbase.columns.mapping" = ":key,cf1:val") TBLPROPERTIES ("hbase.table.name" = "hbase_table", "hbase.mapred.output.outputtable" = "hbase_table");
  • 创建一张原始的hive表,准备一些数据

create table hive_data (mykey int,myval string);insert into hive_data values(1,"www.ymq.io");
  • 把hive原表hive_data中数据,通过hive表hive_hbase_table导入到hbase的表hbase_table中

insert into table hive_hbase_table select * from hive_data;
  • 查看hbase表hbase_table中是否有数据

  1. hbase表存在的情况

  • 创建hive的外表关联hbase表,注意hive schema到hbase schema的映射关系。删除外表不会删除对应hbase表

CREATE EXTERNAL TABLE hive_hbase_external_table(key int, value string) STORED BY 'org.apache.hadoop.hive.hbase.HBaseStorageHandler'WITH SERDEPROPERTIES ("hbase.columns.mapping" = ":key,cf1:val") TBLPROPERTIES ("hbase.table.name" = "hbase_table", "hbase.mapred.output.outputtable" = "hbase_table");
  • 其他导入数据相关同2


方案二:hive表生成hfile,通过bulkload导入到hbase

  1. 适用场景:数据量大(4T以上)

  2. 把hive数据转换为hfile

  • 启动hive并添加相关hbase的jar包

add jar /usr/lib/hive-current/lib/hive-hbase-handler-2.3.3.jar;add jar /usr/lib/hive-current/lib/hbase-common-1.1.1.jar;add jar /usr/lib/hive-current/lib/hbase-client-1.1.1.jar;add jar /usr/lib/hive-current/lib/hbase-protocol-1.1.1.jar;add jar /usr/lib/hive-current/lib/hbase-server-1.1.1.jar;
  • 创建一个outputformat为HiveHFileOutputFormat的hive表

    其中/tmp/hbase_table_hfile/cf_0是hfile保存到hdfs的路径,cf_0是hbase family的名字

create table hbase_hfile_table(key int, cf_0_c0 string) stored asINPUTFORMAT 'org.apache.hadoop.mapred.TextInputFormat'OUTPUTFORMAT 'org.apache.hadoop.hive.hbase.HiveHFileOutputFormat'TBLPROPERTIES ('hfile.family.path' = '/tmp/hbase_table_hfile/cf_0');
  • 把原始数据表的数据通过hbase_hfile_table表保存为hfile

insert into table hbase_hfile_table select * from hive_data;
  • 查看对应hdfs路径是否生成了hfile

  1. 通过bulkload将数据导入到hbase表中

  • 使用阿里云hbase客户端创建具有上面对应family的hbase表

hbase(main):012:0> create 'hbase_hfile_load_table','cf_0'
  • 下载云hbase客户端,配置hbase-site.xml,并将hdfs-site.xml、core-site.xml拷贝到hbase/conf目录

 wget http://public-hbase.oss-cn-hangzhou.aliyuncs.com/installpackage/alihbase-1.1.4-bin.tar.gz . vi conf/hbase-site.xml <property>         <name>hbase.zookeeper.quorum</name>         <value>xxx</value> </property>
  • 执行bulkload导入到hbase表中

bin/hbase org.apache.hadoop.hbase.mapreduce.LoadIncrementalHFiles hdfs://maste:port/tmp/hbase_table_hfile/  hbase_hfile_load_table
  • 在hbase表hbase_hfile_load_table查看数据是否导入


©著作权归作者所有:来自51CTO博客作者mb5fdb0a6739180的原创作品,如需转载,请注明出处,否则将追究法律责任

更多相关文章

  1. 回顾·基于Impala平台打造交互查询系统
  2. Druid原理及产险实践
  3. promethues的一些概念
  4. Apache Hadoop 3.x 最新状态以及升级指南
  5. 60TB 数据量的作业从 Hive 迁移到 Spark 在 Facebook 的实践
  6. 真正的机器学习平台根本不存在?
  7. HBase基础 | 图数据库HGraphDB介绍
  8. Apache iceberg:Netflix 数据仓库的基石
  9. MySQL数据库测试数据导入脚本与基础查询操作

随机推荐

  1. Android全局主题样式控制,语言设置、主题
  2. 启动android默认浏览器
  3. android 9.0 设置 应用应用信息 隐藏 app
  4. Android隐式启动Activity可能存在的坑
  5. 设置ListView分割线
  6. Android 7.1 触摸事件代码跟踪
  7. android各版本对应的SDK level(包括androi
  8. [Android 特效] Android 通过流播放声音(
  9. Android写Logcat文件保存到SD卡
  10. android用Popup弹出窗(PopupWindow的使用