Hadoop之Hbase详解

来源:互联网 发布:linux启动项 编辑:程序博客网 时间:2024/05/21 15:41
Hbase(Hadoop Database)是一种高可靠性,高性能,面向列,可伸缩的分布式存储系统。

行键:每行都有唯一的行键,行键没有数据类型,它内部被认为是一个字节数组。
列簇:数据在行中被组织成列簇,每行有相同的列簇,但是在行之间,相同的列簇   不需要有相同的列修饰符。在引擎中,HBase将列簇存储在它自己           的数据文件中,所以,它们需要事先被定义,此外,改变列簇并不容易。
列修饰符:列簇定义真实的列,被称之为列修饰符,你可以认为列修饰符就是列本身。
版本:每列都可以有一个可配置的版本数量,你可以通过列修饰符的制定版本获取数据。

Hbase原理

1. hbase的存储文件为HFile,每个HFile对应一个Family,结构为key-value
2. 表数据的存储形式为region,region中存储连续的row-key
3. 当region大于一定值后,从中间进行拆分成两个子region
4. 每一台region server包含多个region
5. memstore用于数据缓存的内存区
6. WAL为数据操作日志
7. memstore定期将数据依据WAL写入到HFile

8.               master          slave
hdfs        namenode     datanode
mr          JobTracker     TaskTracker
hbase     Master           RegionServer

9. 服务端出错,会将正确的值插入到库中;客户端出错,都不会提交,因此在catch里进行调用table.flushCommits

Hbase的安装模式

本地模式:

参数文件配置参数参考值 hbase-env.sh   JAVA_HOME /usr/java/jdk/ hbase-site.xml hbase.rootdir file:///usr/local/cloud/hbase/data

伪分布式模式:   

 参数文件 配置参数 参考值 .bash_profile HBASE_HOME /usr/local/cloud/hbase hbase-env.sh JAVA_HOME  /usr/java/jdk/  HBASE_MANAGES_ZK true hbase-site.xml hbase.rootdir hdfs://192.168.56.81:9000/hbase  hbase.cluster.distributed true  hbase.zookeeper.quorum 192.168.56.31  dfs.replication 1 regionservers  localhost

全分布模式

  参数文件 配置参数  参考值  .bash_profile  HBASE_HOME /usr/local/cloud/hbase hbase-env.sh  JAVA_HOME /usr/java/jdk/  HBASE_MANAGES_ZK true  hbase-site.xml hbase.rootdir hdfs://192.168.56.31:9000/hbase   hbase.cluster.distributed true   hbase.zookeeper.quorum 192.168.56.31  dfs.replication 2  hbase.master.maxclockskew 180000 regionservers  192.168.56.33
 192.168.56.4


常用配置


hbase.client.write.buffer
20971520
本地缓存大小(字节),当达到该大小量时,进行提交操作

hbase.regionserver.lease.period
180000
设置每一次scan的超时时间

常用命令

创建table

create 'testtable','cf1','cf2'
# 为列族cf1和cf2指定保存的版本数量
create 'testtable',{NAME=>'cf1',VERSIONS=>3},{NAME=>'cf2',VERSIONS=>3}

插入数据

put 'testtable','r1','cf1:c1','v1'
put 'testtable','r1','cf1:c2','v2'
put 'testtable','r1','cf2:c3','v3'
put 'testtable','r1','cf2:c4','v4'

开启插入数据本地缓存  false开启 true关闭

setAutoFlush(false)
isAutoflush()
flushCommits()

设置本地缓存大小(单位字节)

setWriteBufferSize()
getWriteBufferSize()

判断数据是否存在,只返回布尔值

boolean exists(Get get)

 getRowOrBefore
 当rowkey存在时,直接输出
 当rowkey不存在时,输出前一个
Result res = table.getRowOrBefore("r3".getBytes(), "cf1".getBytes());

查询数据

scan 'testtable'
# 查看三个版本以内的数据
scan 'testtable',{VERSIONS=>3}
get 'testtable','r1'

删除数据
delete 'testtable','r1','cf2:c4'

 删除表
disable 'testtable'
drop 'testtable'

设置返回的行数

scan.setCaching(num)

设置返回行的列数

scan.setBatch(num)

0 0
原创粉丝点击