[关闭]
@hadoopMan 2017-03-04T14:29:55.000000Z 字数 16461 阅读 1453

Hbase进阶

hbase


想学习spark,hadoop,kafka等大数据框架,请加群459898801,满了之后请加2群224209501。后续文章会陆续公开

1,HBase 功能架构

1,hbase是hadoop的数据库

hbase是Hadoop 数据库,因为它具有存储数据和检索数据的功能。而且数据存储是基于HDFS,主要原因依赖hdfs存储数据量大,数据安全性高,而且硬件平台要求低,只需要商用PCServer就可以等特性。与RDBMS 相比hbase可以存储海量数据,而且检索速度可以达到准实时,最迟是秒级别。
打架hbase集群至少需要三个框架Hbase,zookeeper,HDFS。三个环节任意一个环节出问题将导致hbase集群不可用。
hbase是列式存储数据库,即nosql数据库,列数据可以十多版本的。
Cell:{rowkey + cf + column + version(timestamp)} : value
table,分为多个region,region按照rowKey进行管理,[startRowKey,stopRowKey),四个key分为5个Region。不在范围内的便于插入region头和尾部。
region.png-1.7kB
在默认的情况下,创建一个表时,会给一个表创建一个Region

2,hbase架构

1,hbase结构图

hbase架构图.png-133.6kB
hbase客户端存储和检索数据直接是通过zookeeper来实现的。依据rowkey在zookeeper上找到对应的region,然后根据region通过zookeeper找到对应的regionserver,这个过程并没有经过Hmaster。最后找到regionserver去检索数据。

2,HBase 写数据

client 会先写入 hlog 文件(WAL:Write Head Log) 再写入memStore(Memroy)达到一定阈值的时候flush到StoreFile。这样可以保证数据完整性。

3,hbase数据存储

hbase中所有数据文件都存储在hadoopHDFS文件系统上,主要包括两种文件类型:
1,HFile:hbase中kevalue数据的存储格式,HFile是hadoop的二进制格式文件,实际上StoreFile就是对HFile做了轻量级的包装,进行数据存储。
2,HLogFile:hbase中WAL(Write Ahead Log)的存储格式,物理上是Hadoop的SequenceFile。

4,HRegion Server

1,HRegionServer内部管理了一系列HRegion对象,每个HRegion对应了tables中的一个region,HRegion中由多个HStroe组成。每个HStore对应于Table中的一个column family的存储,可以看出每个columnfamily其实就是一个集中的存储单元,因此最好将具备共同IO特性的column放在一个columnfamily中,这样最高效。
2,HStore存储是Hbase存储的核心,由两部分组成,一部分是MemStore,一部分是StoreFile。MemStore是Sorted Memory Buffer,用户写入的数据首先会放入Memstore,当MemsTore满了以后会flush成一个storeFile(底层是现实HFile)。

5,MemStore&storeFile

1,用户写入数据流程
用户写入数据流程.png-143.1kB
2,Client写入数据首先写入到MemStore,一直到MemStore
满,就会flush成一个StoreFile,直至增长到一定阈值,就会触发Compact合并操作,多个StoreFile合并成一个StoreFile,同时进行版本合并和数据删除,当StoreFilesCompact后,逐步形成越来越大的StoreFile,单个StoreFile大小超过一定阈值之后,触发Split操作,把当前Regio Split成两个Region,父region会下线,新的split出的两个孩子region会被HMaste分配到相应的HRegionServer上,使得原先1个region的压力得以分流到2个region上。
3,HBase只是增加数据,有所得更新和删除操作,都是在Compact阶段做的,所以用户写操作只需要进入到内存即可立即返回,从而保证IO高性能。

6,HLog文件结构

1,WAL意为Write ahead log,类似Mysql中的binlog,用来做灾难恢复。Hlog记录数据的所有变更,一旦数据修改,就可以从log中进行数据恢复。每个HRegionServer维护一个HLog而不是一个Hregion一个。这样不同region(来自不同tables)的日志就会混在一起,这样做的目的是不断追加单个文件相对于同时写多个文件而言,可以减少按值寻址次数,因此可以提高对table的写性能,带来的麻烦事,如果一台HRegionServer下线,为恢复其上的region,需要将HRegionServer上的log进行拆分,然后分发到其他hregionServer上进行数据恢复。

3,深入hbase架构

hbase架构图

1,client

1,整个hbase集群访问入口;
2,使用HBase RPC机制与HMaster和HRegionServer进行通信;
3,与HMaster进行通信管理类操作
4,与HRegionServer进行数据读写操作
5,包含访问HBase的接口,并维护cache来加快对HRegion的访问。

2,zookeeper

1,保证任何时候,集群中只有一个HMaster
2,存储所有HRegion的寻址入口;
3,实时监控HRegionServer的上线和下线信息,并实时通知给HMaster;
4,存储HBase的schema和table元数据;
5,zookeeper Quorum存储-ROOT-表地址、HMaster地址

3,HMaster

1,HMaster没有单点问题,HBase中可以启动多个HMaster,通过zookeeper的Master Election机制保证总有一个Master在运行主要负责Table和Region的管理工作。
2,管理用户对table的增删改查操作;
3,管理HRegionServer的负载均衡,调整Region分布;
4,RegionSplit后,负责新Region的分布;
5,在HRegionServer停机后,负责将失效HRegionServer上Region迁移工作。

4,HRegionServer

1,维护HRegion,处理对这些HRegion的IO请求,向HDFS文件系统中读写数据;
2,负责切分在运行过程中变得过大的HRegion
3,Client访问HBase上数据的过程并不需要master参与(寻址访问zookeeper和HRegionServer,数据读写访问HRegionServer),HMaster仅仅维护者table和Region的元数据信息,负载很低。

5,HBase & zookeeper

1,HBase依赖zookeeper;
2,默认情况下,HBase管理zookeeper实例,比如,启动或者停止zookeeper;
3,HMaster与RegionServers启动时会向zookeeper注册;
4,zookeeper的引入使得HMaster不再是单点故障。

4,hbase的eclipse编程环境搭建

首先在pom.xml文件中添加如下内容

  1. <properties>
  2. <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
  3. <hbase.version>0.98.6-hadoop2</hbase.version>
  4. </properties>
  5. <dependency>
  6. <groupId>org.apache.hbase</groupId>
  7. <artifactId>hbase-server</artifactId>
  8. <version>${hbase.version}</version>
  9. </dependency>
  10. <dependency>
  11. <groupId>org.apache.hbase</groupId>
  12. <artifactId>hbase-client</artifactId>
  13. <version>${hbase.version}</version>
  14. </dependency>

然后再resource目录下添加
hbase-site.xml文件

5,JAVA API的使用

1,hbase表的java api基本使用

  1. package hbase.learn.com;
  2. import org.apache.hadoop.conf.Configuration;
  3. import org.apache.hadoop.hbase.Cell;
  4. import org.apache.hadoop.hbase.CellUtil;
  5. import org.apache.hadoop.hbase.HBaseConfiguration;
  6. import org.apache.hadoop.hbase.client.Delete;
  7. import org.apache.hadoop.hbase.client.Get;
  8. import org.apache.hadoop.hbase.client.HTable;
  9. import org.apache.hadoop.hbase.client.Put;
  10. import org.apache.hadoop.hbase.client.Result;
  11. import org.apache.hadoop.hbase.client.ResultScanner;
  12. import org.apache.hadoop.hbase.client.Scan;
  13. import org.apache.hadoop.hbase.util.Bytes;
  14. import org.apache.hadoop.io.IOUtils;
  15. public class hbaseJAVAAPI {
  16. public static HTable getHTableByTableName(String tableName) //
  17. throws Exception {
  18. // Get instance of Configuration
  19. Configuration configuration = HBaseConfiguration.create();
  20. // Get table instance
  21. HTable table = new HTable(configuration, tableName);
  22. System.out.println(table);
  23. return table;
  24. }
  25. /*
  26. * Get Data From Table By Rowkey
  27. */
  28. public void getData()throws Exception {
  29. String tableName = "user";
  30. // Get table instance
  31. HTable table = getHTableByTableName(tableName);
  32. // Create Get with rowkey
  33. Get get = new Get(Bytes.toBytes("1001")) ;
  34. //=======================================
  35. get.addColumn(//
  36. Bytes.toBytes("info"),//
  37. Bytes.toBytes("age")//
  38. );
  39. //=======================================
  40. // Get Data
  41. Result result = table.get(get) ;
  42. // System.out.println(result);
  43. /**
  44. * Key:
  45. * rowkey + cf + c + version
  46. *
  47. * Value :
  48. * value
  49. */
  50. for(Cell cell : result.rawCells()){
  51. System.out.println(Bytes.toString(CellUtil.cloneRow(cell)));
  52. System.out.println(//
  53. Bytes.toString(CellUtil.cloneFamily(cell))
  54. + ":" //
  55. + Bytes.toString(CellUtil.cloneQualifier(cell)) //
  56. + " -> " //
  57. + Bytes.toString(CellUtil.cloneValue(cell)) //
  58. + " " //
  59. + cell.getTimestamp()
  60. );
  61. System.out.println("--------------------------------");
  62. }
  63. // close
  64. table.close();
  65. }
  66. /**
  67. * Put Data into Table
  68. * @throws Exception
  69. *
  70. * Map<String,Object>
  71. *
  72. */
  73. public void putData() throws Exception {
  74. String tableName = "user";
  75. // Get table instance
  76. HTable table = getHTableByTableName(tableName);
  77. // create put instance
  78. Put put = new Put(Bytes.toBytes("1001")) ;
  79. // Add a column with value
  80. put.add(//
  81. Bytes.toBytes("info"), //
  82. Bytes.toBytes("sex"), //
  83. Bytes.toBytes("male") //
  84. ) ;
  85. put.add(//
  86. Bytes.toBytes("info"), //
  87. Bytes.toBytes("tel"), //
  88. Bytes.toBytes("010-876523423") //
  89. ) ;
  90. put.add(//
  91. Bytes.toBytes("info"), //
  92. Bytes.toBytes("address"), //
  93. Bytes.toBytes("beijing") //
  94. ) ;
  95. /*
  96. Map<String,Object> kvs = new HashMap<String,Object>() ;
  97. for(String key : kvs.keySet()){
  98. put.add(//
  99. HBaseTableConstant.HBASE_TABLE_USER_CF, //
  100. Bytes.toBytes(key), //
  101. Bytes.toBytes(kvs.get(key)) //
  102. ) ;
  103. }
  104. */
  105. // put data into table
  106. table.put(put);
  107. // close
  108. table.close();
  109. }
  110. public void deleteData() throws Exception {
  111. String tableName = "user";
  112. // Get table instance
  113. HTable table = getHTableByTableName(tableName);
  114. Delete delete = new Delete (Bytes.toBytes("1001")) ;
  115. delete.deleteFamily(Bytes.toBytes("info")) ;
  116. // delete.deleteColumn(//
  117. // Bytes.toBytes("info"), //
  118. // Bytes.toBytes("sex") //
  119. // ) ;
  120. // delete.deleteColumns(family, qualifier) ;
  121. // delete data
  122. table.delete(delete);
  123. // close
  124. table.close();
  125. }
  126. public void scanData()throws Exception {
  127. String tableName = "user";
  128. // Get table instance
  129. HTable table = null;
  130. ResultScanner resultScanner = null ;
  131. try{
  132. table = getHTableByTableName(tableName);
  133. Scan scan = new Scan() ;
  134. //===========================================================
  135. //Range
  136. // scan.setStartRow(startRow);
  137. // scan.setStopRow(stopRow) ;
  138. //Scan
  139. // Scan scan2 = new Scan(startRow,stopRow) ;
  140. //add Column
  141. // scan.addColumn(family, qualifier) ;
  142. // scan.addFamily(family) ;
  143. //Filter
  144. // Filter filter = new PrefixFilter(prefix) ;
  145. // scan.setFilter(filter) ;
  146. // page
  147. // PageFilter
  148. //Cache
  149. // scan.setCacheBlocks(cacheBlocks);
  150. // scan.setCaching(caching);
  151. //===========================================================
  152. resultScanner = table.getScanner(scan) ;
  153. // iterator
  154. for(Result result : resultScanner){
  155. for(Cell cell : result.rawCells()){
  156. System.out.println(Bytes.toString(CellUtil.cloneRow(cell)));
  157. System.out.println(//
  158. Bytes.toString(CellUtil.cloneFamily(cell))
  159. + ":" //
  160. + Bytes.toString(CellUtil.cloneQualifier(cell)) //
  161. + " -> " //
  162. + Bytes.toString(CellUtil.cloneValue(cell)) //
  163. + " " //
  164. + cell.getTimestamp()
  165. );
  166. }
  167. System.out.println("##################################");
  168. }
  169. }catch(Exception e ){
  170. e.printStackTrace();
  171. }finally {
  172. IOUtils.closeStream(resultScanner);
  173. IOUtils.closeStream(table);
  174. }
  175. }
  176. public static void main(String[] args) throws Exception {
  177. hbaseJAVAAPI hbase=new hbaseJAVAAPI();
  178. System.out.println("==================get table name===================");
  179. hbase.getHTableByTableName("user");
  180. System.out.println("==================put data===================");
  181. hbase.putData();
  182. System.out.println("==================get data===================");
  183. hbase.getData();
  184. System.out.println("==================scan data===================");
  185. hbase.scanData();
  186. System.out.println("==================delete data===================");
  187. hbase.deleteData();
  188. System.out.println("==================scan data===================");
  189. hbase.scanData();
  190. }
  191. }

2,输出结果如下

  1. ==================get table name===================
  2. ==================put data===================
  3. user;hconnection-0x3be33bad
  4. ==================get data===================
  5. user;hconnection-0x3be33bad
  6. 1001
  7. info:age -> 18 1451913054898
  8. --------------------------------
  9. ==================scan data===================
  10. user;hconnection-0x3be33bad
  11. 10001
  12. info:address -> beijing 1451914706880
  13. 10001
  14. info:sex -> male 1451914706880
  15. 10001
  16. info:tel -> 010-876523423 1451914706880
  17. ##################################
  18. 1001
  19. info:address -> beijing 1451915182523
  20. 1001
  21. info:age -> 18 1451913054898
  22. 1001
  23. info:name -> lisi 1451913049037
  24. 1001
  25. info:sex -> male 1451915182523
  26. 1001
  27. info:tel -> 010-876523423 1451915182523
  28. ##################################
  29. ==================delete data===================
  30. user;hconnection-0x3be33bad
  31. ==================scan data===================
  32. user;hconnection-0x3be33bad
  33. 10001
  34. info:address -> beijing 1451914706880
  35. 10001
  36. info:sex -> male 1451914706880
  37. 10001
  38. info:tel -> 010-876523423 1451914706880
  39. ##################################

6,hbase和mapreduce

1,代码实现

  1. package hbase.learn.com;
  2. import java.io.IOException;
  3. import org.apache.hadoop.conf.Configuration;
  4. import org.apache.hadoop.conf.Configured;
  5. import org.apache.hadoop.hbase.Cell;
  6. import org.apache.hadoop.hbase.CellUtil;
  7. import org.apache.hadoop.hbase.HBaseConfiguration;
  8. import org.apache.hadoop.hbase.client.Put;
  9. import org.apache.hadoop.hbase.client.Result;
  10. import org.apache.hadoop.hbase.client.Scan;
  11. import org.apache.hadoop.hbase.io.ImmutableBytesWritable;
  12. import org.apache.hadoop.hbase.mapreduce.TableMapReduceUtil;
  13. import org.apache.hadoop.hbase.mapreduce.TableMapper;
  14. import org.apache.hadoop.hbase.mapreduce.TableReducer;
  15. import org.apache.hadoop.hbase.util.Bytes;
  16. import org.apache.hadoop.io.Text;
  17. import org.apache.hadoop.mapreduce.Job;
  18. import org.apache.hadoop.util.Tool;
  19. import org.apache.hadoop.util.ToolRunner;
  20. public class User2BasicMapReduce extends Configured implements Tool {
  21. // step 1 : Mapper
  22. /**
  23. * Mapper<ImmutableBytesWritable, Result, KEYOUT, VALUEOUT>
  24. */
  25. public static class ReadUserMapper extends //
  26. TableMapper<Text, Put> {
  27. private Text mapOutputKey = new Text();
  28. @Override
  29. protected void map(ImmutableBytesWritable key, Result value, Context context)
  30. throws IOException, InterruptedException {
  31. // get rowkey
  32. String rowkey = Bytes.toString(key.get());
  33. // set map output key
  34. mapOutputKey.set(rowkey);
  35. // ==============================================================
  36. // create Put
  37. Put put = new Put(key.get());
  38. // iterator
  39. for (Cell cell : value.rawCells()) {
  40. // add family : info
  41. if ("info".equals(Bytes.toString(CellUtil.cloneFamily(cell)))) {
  42. // add column : name
  43. if ("name".equals(Bytes.toString(CellUtil.cloneQualifier(cell)))) {
  44. put.add(cell);
  45. }
  46. // add column : age
  47. else if ("age".equals(Bytes.toString(CellUtil.cloneQualifier(cell)))) {
  48. put.add(cell);
  49. }
  50. }
  51. }
  52. // context write
  53. context.write(mapOutputKey, put);
  54. }
  55. }
  56. // step 2: Reducer
  57. /**
  58. * Reducer<KEYIN, VALUEIN, KEYOUT, Mutation>
  59. */
  60. public static class WriteBasicReducer extends //
  61. TableReducer<Text, Put, ImmutableBytesWritable> {
  62. @Override
  63. protected void reduce(Text key, Iterable<Put> values, Context context)
  64. throws IOException, InterruptedException {
  65. for(Put put : values){
  66. context.write(null, put);
  67. }
  68. }
  69. }
  70. // step 3: Driver
  71. public int run(String[] args) throws Exception {
  72. // 1) configuration
  73. Configuration conf = this.getConf();
  74. // 2) create job
  75. Job job = Job.getInstance(conf, //
  76. this.getClass().getSimpleName());
  77. job.setJarByClass(User2BasicMapReduce.class); // class that contains
  78. // mapper and reducer
  79. // 3) set job
  80. Scan scan = new Scan();
  81. scan.setCaching(500); // 1 is the default in Scan, which will be bad for
  82. // MapReduce jobs
  83. scan.setCacheBlocks(false); // don't set to true for MR jobs
  84. // set other scan attrs
  85. TableMapReduceUtil.initTableMapperJob(//
  86. "user", // input table
  87. scan, // Scan instance to control CF and attribute selection
  88. ReadUserMapper.class, // mapper class
  89. Text.class, // mapper output key
  90. Put.class, // mapper output value
  91. job //
  92. );
  93. TableMapReduceUtil.initTableReducerJob(//
  94. "basic", // output table
  95. WriteBasicReducer.class, // reducer class
  96. job //
  97. );
  98. job.setNumReduceTasks(1); // at least one, adjust as required
  99. boolean b = job.waitForCompletion(true);
  100. if (!b) {
  101. throw new IOException("error with job!");
  102. }
  103. return b ? 0 : 1;
  104. }
  105. public static void main(String[] args) throws Exception {
  106. // get configuration
  107. Configuration configuration = HBaseConfiguration.create();
  108. // run job
  109. int status = ToolRunner.run(//
  110. configuration, //
  111. new User2BasicMapReduce(), //
  112. args //
  113. );
  114. // exit program
  115. System.exit(status);
  116. }
  117. }

2,导出jar包并运行

  1. export HBASE_HOME=/opt/modules/hbase-0.98.6-hadoop2
  2. export HADOOP_HOME=/opt/modules/hadoop-2.5.0
  3. HADOOP_CLASSPATH=`${HBASE_HOME}/bin/hbase classpath` $HADOOP_HOME/bin/yarn jar /opt/tools/User2BasicMapReduce.jar

执行成功后
导出成功后.png-19.9kB

3,出现的错误及解决方法

经追查源码查到在Put时,虽然实例化了正确的Put,但是Put中没有KeyValue值,表现出来的状况就是在Put的familyMap中没有任何的值,根本原因还是数据有问题,但从此问题中可以看到,如果一个Put中没有任何的value那么是不会被放入HBase中的。当然这可能也和HBase存储数据的方式有关,在RDBMS中我们可以存储类似“id01,null,null”的数据,但在HBase中,值为空的数据是不会被存储的。put使用的时候,假如为空就会报如下错误。
因为数据中不存在age列。

  1. ^C16/01/04 23:38:19 INFO mapreduce.Job: Task Id : attempt_1451912421695_0002_r_000000_2, Status : FAILED
  2. Error: java.lang.IllegalArgumentException: No columns to insert
  3. at org.apache.hadoop.hbase.client.HTable.validatePut(HTable.java:1304)
  4. at org.apache.hadoop.hbase.client.HTable.doPut(HTable.java:941)
  5. at org.apache.hadoop.hbase.client.HTable.put(HTable.java:908)
  6. at org.apache.hadoop.hbase.mapreduce.TableOutputFormat$TableRecordWriter.write(TableOutputFormat.java:126)
  7. at org.apache.hadoop.hbase.mapreduce.TableOutputFormat$TableRecordWriter.write(TableOutputFormat.java:87)
  8. at org.apache.hadoop.mapred.ReduceTask$NewTrackingRecordWriter.write(ReduceTask.java:558)
  9. at org.apache.hadoop.mapreduce.task.TaskInputOutputContextImpl.write(TaskInputOutputContextImpl.java:89)
  10. at org.apache.hadoop.mapreduce.lib.reduce.WrappedReducer$Context.write(WrappedReducer.java:105)
  11. at hbase.learn.com.User2BasicMapReduce$WriteBasicReducer.reduce(User2BasicMapReduce.java:77)
  12. at hbase.learn.com.User2BasicMapReduce$WriteBasicReducer.reduce(User2BasicMapReduce.java:1)
  13. at org.apache.hadoop.mapreduce.Reducer.run(Reducer.java:171)
  14. at org.apache.hadoop.mapred.ReduceTask.runNewReducer(ReduceTask.java:627)
  15. at org.apache.hadoop.mapred.ReduceTask.run(ReduceTask.java:389)
  16. at org.apache.hadoop.mapred.YarnChild$2.run(YarnChild.java:168)
  17. at java.security.AccessController.doPrivileged(Native Method)
  18. at javax.security.auth.Subject.doAs(Subject.java:415)
  19. at org.apache.hadoop.security.UserGroupInformation.doAs(UserGroupInformation.java:1614)
  20. at org.apache.hadoop.mapred.YarnChild.main(YarnChild.java:163)

7,importtsv导入数据

1,创建表student

  1. create 'student','info'

2,创建目录并上传数据

  1. /opt/modules/hadoop-2.5.0/bin/hdfs dfs -put /opt/datas/importtsv.tsv /user/hadoop/hbase/importtsv/input

3,创建importtsv.sh脚本

  1. #!/bin/sh
  2. export HBASE_HOME=/opt/modules/hbase-0.98.6-hadoop2
  3. export HADOOP_HOME=/opt/modules/hadoop-2.5.0
  4. HADOOP_CLASSPATH=`${HBASE_HOME}/bin/hbase classpath` \
  5. $HADOOP_HOME/bin/yarn jar \
  6. $HBASE_HOME/lib/hbase-server-0.98.6-hadoop2.jar \
  7. importtsv \
  8. -Dimporttsv.columns=HBASE_ROW_KEY,\
  9. info:name,info:age,info:sex,info:address,info:phone \
  10. student \
  11. hdfs://miaodonghua1.host:8020/user/hadoop/hbase/importtsv/input

4,执行脚本

  1. ./importtsv.sh

执行成功后
命令执行成功.png-52.1kB
数据上传成功.png-45.1kB

8,completebulkload导入数据

1,创建hfile-importtsv.sh脚本

输入如下内容

  1. #/bin/sh
  2. export HBASE_HOME=/opt/modules/hbase-0.98.6-hadoop2
  3. export HADOOP_HOME=/opt/modules/hadoop-2.5.0
  4. HADOOP_CLASSPATH=`${HBASE_HOME}/bin/hbase classpath` \
  5. $HADOOP_HOME/bin/yarn jar \
  6. $HBASE_HOME/lib/hbase-server-0.98.6-hadoop2.jar \
  7. importtsv \
  8. -Dimporttsv.columns=HBASE_ROW_KEY,\
  9. info:name,info:age,info:sex,info:address,info:phone \
  10. -Dimporttsv.bulk.output=hdfs://miaodonghua1.host:8020/user/hadoop/hbase/importtsv/hfileoutput \
  11. student \
  12. hdfs://miaodonghua1.host:8020/user/hadoop/hbase/importtsv/input

2,执行脚本生成HFile文件

  1. ./hfile-importtsv.sh

执行成功后
HFile成功生成.png-55.3kB

3,HFile数据导入到hbase

  1. HADOOP_CLASSPATH=`${HBASE_HOME}/bin/hbase classpath` $HADOOP_HOME/bin/yarn jar \ $HBASE_HOME/lib/hbase-server-0.98.6-hadoop2.jar \ completebulkload \ /user/hadoop/hbase/importtsv/hfileoutput/ student

HFile数据导入成功.png-50.7kB

9,指定导入数据分割方式

1,创建csv-hfile-importtsv.sh

  1. #/bin/sh
  2. export HBASE_HOME=/opt/modules/hbase-0.98.6-hadoop2
  3. export HADOOP_HOME=/opt/modules/hadoop-2.5.0
  4. HADOOP_CLASSPATH=`${HBASE_HOME}/bin/hbase classpath` \
  5. $HADOOP_HOME/bin/yarn jar \
  6. $HBASE_HOME/lib/hbase-server-0.98.6-hadoop2.jar \
  7. importtsv \
  8. -Dimporttsv.columns=HBASE_ROW_KEY,\
  9. info:name,info:age,info:sex,info:address,info:phone \
  10. -Dimporttsv.bulk.output=hdfs://miaodonghua1.host:8020/user/hadoop/hbase/importtsv/csvhfileoutput \
  11. -Dimporttsv.separator=, \
  12. student \
  13. hdfs://miaodonghua1.host:8020/user/hadoop/hbase/importtsv/input

2,执行脚本

  1. ./csv-hfile-importtsv.sh

hfile数据生成成功
CSVHFile生成.png-49.7kB

3,导入数据到hbase

  1. HADOOP_CLASSPATH=`${HBASE_HOME}/bin/hbase classpath` $HADOOP_HOME/bin/yarn jar \ $HBASE_HOME/lib/hbase-server-0.98.6-hadoop2.jar \
  2. completebulkload \
  3. /user/hadoop/hbase/importtsv/csvhfileoutput/ student

数据导入成功
csv数据加载成功.png-47kB

添加新批注
在作者公开此批注前,只有你和作者可见。
回复批注