1 Hive整合HBase的配置
1.1 导入jar包
导入hbase安装目录lib目录如下jar包到hive安装目录lib文件夹下(我这里没有导入是因为hive本身版本比较高它的lib目录下有1.1.1版本的,我觉得版本高于我安装的hbase集群,而且还比较接近就直接用默认的这些jar包了,如果读者按照这种方式失败的话严格用和hbase版本一致的jar包再试试)
1.2 修改Hive的配置文件
修改hive-site.xml文件
步骤1:将上述jar包添加到hive-site.xml文件hive.aux.jars.path属性中
<property>
<name>hive.aux.jars.path</name>
<value>file:///opt/bigdata/hive/lib/hbase-client-1.1.1.jar,file:///opt/bigdata/hive/lib/hbase-common-1.1.1.jar,
file:///opt/bigdata/hive/lib/hbase-common-1.1.1-tests.jar,file:///opt/bigdata/hive/lib/hbase-protocol-1.1.1.jar,
file:///opt/bigdata/hive/lib/hbase-server-1.1.1.jar,file:///opt/bigdata/hive/lib/htrace-core-3.1.0-incubating.jar,
file:///opt/bigdata/hive/lib/hive-hbase-handler-2.3.4.jar,file:///opt/bigdata/hive/lib/zookeeper-3.4.6.jar</value>
<description>The location of the plugin jars that contain implementations of user defined functions and serdes.</description>
</property>
步骤2: 修改hive.zookeeper.quorum属性
<property>
<name>hive.zookeeper.quorum</name>
<value>master,slave1,slave2</value>
<description>
List of ZooKeeper servers to talk to. This is needed for:
1. Read/write locks - when hive.lock.manager is set to
org.apache.hadoop.hive.ql.lockmgr.zookeeper.ZooKeeperHiveLockManager,
2. When HiveServer2 supports service discovery via Zookeeper.
3. For delegation token storage if zookeeper store is used, if
hive.cluster.delegation.token.store.zookeeper.connectString is not set
4. LLAP daemon registry service
</description>
</property>
步骤3: 新建一个hbase.zookeeper.quorum属性(此属性hive-site.xml之前不存在)。
<property>
<name>hbase.zookeeper.quorum</name>
<value>master,slave1,slave2</value>
<description/>
</property>
修改hive-env.sh文件
添加环境变量
2 测试
2.1 启动
启动顺序Hadoop->Zookeeper->HBase->MySQL->Hive
这里我仅仅展示配置好hive如何启动
步骤1: 定位到hive安装目录bin目录下,启动hive服务
步骤2: 进入shell
如上图所示,执行一个简单的命令验证shell启动的准确无误,接下来我们就可以使用配置好的系统了。
2.2 创建内部表
适用于数据从hive导入hbase这种情况
步骤1: 准备测试数据,创建测试文件course.csv(目录/opt/bigdata/data/course.csv)
步骤2: 将数据导入HDFS中
在hdfs中创建/hive-hbase/course目录
将course.csv文件上传至/hive-hbase/course目录下
步骤3: 创建Hive数据库
进入Hive Shell客户端创建库course
显示一下刚才创建的course库
步骤4: 创建Hive表
create external table if not exists course.testcourse(cname string,score int)
row format delimited fields terminated by '\t' stored as textfile location '/hive-hbase/course';
步骤5: 查看hive表中的数据
步骤6: 创建Hive内部表
create table course.hbase_testcourse(key string,cname string,score int) stored by 'org.apache.hadoop.hive.hbase.HBaseStorageHandler' with serdeproperties("hbase.columns.mapping"="cf:cname,cf:score") tblproperties("hbase.table.name"="hbase_testcourse");
步骤7: 查看Hive中所创建的表
步骤8: 向hbase中插入数据
步骤9: 查看hbase中是否存入数据
至此通过这种方式就大功告成了!
2.2 创建外部表
适用于该表在HBase中已经存在,但在Hive中并没有相关信息。此时可以通过创建外部表的方式,为HBase现有表提供SQL查询条件。而内部表适用于Hive和HBase都没有相关表的情况。
步骤1: 进入HBase Shell客户端执行建表命令create ‘hbase_test’,{ NAME =>‘cf’}
步骤2: 执行如下命令插入数据
put ‘hbase_test’,‘hadoop’,‘cf:score’, ‘95’
put ‘hbase_test’,‘storm’,‘cf:score’, ‘96’
put ‘hbase_test’,‘spark’,‘cf:score’, ‘97’
步骤3: 查看hbase_test表中的数据
步骤4: 进入Hive Shell客户端,创建外部表course.hbase_test, 建表命令如下所示
create external table course.hbase_test(cname string,score int) STORED BY 'org.apache.hadoop.hive.hbase.HBaseStorageHandler'WITH SERDEPROPERTIES("hbase.columns.mapping" =":key,cf:score") TBLPROPERTIES("hbase.table.name" ="hbase_test", "hbase.mapred.output.outputtable" = "hbase_test");
步骤5: Hive查看数据
完结!