`

hbase bulkloader实例入门

阅读更多

一、使用mr生成对应hbase table的hfile

maper中写入库逻辑,reduce是用hbase自带的,outputformat用的是hfileoutputformat

 

 

                        Configuration conf = new Configuration();
                        Job jobAfter = new Job(conf2);
                        jobAfter.setJarByClass(Test.class);
                        jobAfter.setMapperClass(LogicMapper.class);//在mapper中写业务逻辑
                        jobAfter.setMapOutputKeyClass(ImmutableBytesWritable.class);//只能是ImmutableBytesWritable类
                        jobAfter.setMapOutputValueClass(Put.class);//只能是put或keyvalue类型
                        FileOutputFormat.setOutputPath(jobAfter, new Path("/user/hadoop/bulkload/data"));
                        jobAfter.setOutputFormatClass(HFileOutputFormat.class);
                        HTable table=new HTable(conf,conf.get("tableName"));
                        HFileOutputFormat.configureIncrementalLoad(jobAfter, table);//根据map输出key和value设置reduce class;根据htable的region数,设置reduce数
                        jobAfter.waitForCompletion(true);

 

 

 

 

二、

将hfile导入到hbase中 

hadoop jar hbase-VERSION.jar completebulkload hdfs://localhost:8020/user/hadoop/bulkload/data testtable

 

bulkload实例二

当hbase集群和hadoop(跑MR的)集群不在一起时,就需要知道zk ip和port了

第一步

生成hfile的时候,需要hbase-site位置,里边有zk的ip和port

 

第二步

 

 

hadoop jar /home/q/hadoop/hbase-0.98.0-hadoop2/lib/hbase-server-0.98.0-hadoop2.jar  completebulkload  -Dhbase.zookeeper.quorum=192.168.xx.xx -Dhbase.zookeeper.property.clientPort=2181 hdfs://192.168.xxx.xxx:8020/user/hadoop/wfdata/testoutput xxx_table
 

 

 

192.168.xx.xx这是zk的ip 2181是zk的port

 

192.168.xxx.xxx这是hdfs上hfile的位置

 

 

 

分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics