HBase学习笔记(1)

1.rdbms和hbase的比较:(结构,功能)
  关系型数据库                                          HBase
  数据库以表的形式存在                                                数据以region的形式存在
  支持FAT,NTFS,EXT文件系统                                         支持hdfs文件系统
  使用commit log存储日志                                            使用WAL(write-ahead logs)存储日志
  参考系统是坐标系统                                                    参考系统是Zookeeper
  使用主键(PK)                                                                使用行键row key
  支持分区                                                                        支持分片
  使用行,列,单元格                                                    使用行,列,列族,单元格 cell 
                                                        
  向上扩展                                                                        横向或向外扩展
  sql查询                                                                            使用api和mapreduce来访问hbase数据
  面向行,即每一行都是一个连续单元                      面向列,即每一列都是在某一页上的一个连续的单元
  数据总量依赖于服务器配置                                        数据总量依赖于机器数量及其配置
  支持ACID(atomicity,consistency,isolation,durability)  不支持ACID
  适合结构化数据                                                                                适合结构化和非结构化数据
  一般都是中心化的                                                                            一般都是分布式的

2.内存数据缓冲池,使用LRU算法
  leastest
  recently
  used
3.实时大数据访问
  HBase采用log-structured merge-tree作为内部数据存储架构,这种架构会周期性地将
  小文件合并成大文件以减少磁盘访问同时减少NameNode压力。
4.Hbase优点
  方便高效的压缩数据
  支持快速数据检索
  管理和配置简单,支持横向扩展,所以非常容易扩展
  聚合查询性能非常高
  可高效地进行分区,提供自动分区机制把大的region切分成小的subregion
5.hbase缺点
  对JOIN以及多表合并数据的查询性能不好
  更新过程中有大量的写入和删除操作,需要频繁合并和分裂,降低存储效率
  对关系模型支持不好,分区和索引模式设计比较困难。
6.HMaster
  监控RegionServer
  处理RegionServer故障转移
  处理元数据的变更
  处理region的分配或移除
  在空闲时间进行数据的负载均衡
  通过Zookeeper发布自己的位置给客户端
7.RegionServer
  负责存储HBase的实际数据
  处理分配给它的Region
  刷新缓存到HDFS
  维护HLog
  执行压缩
  负责处理Region分片
8.启动hbase(首先启动Hadoop,zookeeper)
  bin/start-hbase.sh
9.进入hbase客户端命令操作界面
  bin/hbase shell
10.help查看帮助命令
HBase Shell, version 0.98.6-cdh5.3.6, rUnknown, Tue Jul 28 15:17:11 PDT 2015
Type 'help "COMMAND"', (e.g. 'help "get"' -- the quotes are necessary) for help on a specific command.
Commands are grouped. Type 'help "COMMAND_GROUP"', (e.g. 'help "general"') for help on a command group.

COMMAND GROUPS:
  Group name: general
  Commands: status, table_help, version, whoami

  Group name: ddl
  Commands: alter, alter_async, alter_status, create, describe, disable, disable_all, drop, drop_all, enable, enable_all, exists, get_table, is_disabled, is_enabled, list, show_filters

  Group name: namespace
  Commands: alter_namespace, create_namespace, describe_namespace, drop_namespace, list_namespace, list_namespace_tables

  Group name: dml
  Commands: append, count, delete, deleteall, get, get_counter, incr, put, scan, truncate, truncate_preserve

  Group name: tools
  Commands: assign, balance_switch, balancer, catalogjanitor_enabled, catalogjanitor_run, catalogjanitor_switch, close_region, compact, flush, hlog_roll, major_compact, merge_region, move, split, trace, unassign, zk_dump

  Group name: replication
  Commands: add_peer, disable_peer, enable_peer, list_peers, list_replicated_tables, remove_peer, set_peer_tableCFs, show_peer_tableCFs

  Group name: snapshots
  Commands: clone_snapshot, delete_snapshot, list_snapshots, rename_snapshot, restore_snapshot, snapshot

  Group name: quotas
  Commands: list_quotas, set_quota

  Group name: security
  Commands: grant, revoke, user_permission

  Group name: visibility labels
  Commands: add_labels, clear_auths, get_auths, set_auths, set_visibility

SHELL USAGE:
Quote all names in HBase Shell such as table and column names.  Commas delimit
command parameters.  Type <RETURN> after entering a command to run it.
Dictionaries of configuration used in the creation and alteration of tables are
Ruby Hashes. They look like this:

  {'key1' => 'value1', 'key2' => 'value2', ...}

and are opened and closed with curley-braces.  Key/values are delimited by the
'=>' character combination.  Usually keys are predefined constants such as
NAME, VERSIONS, COMPRESSION, etc.  Constants do not need to be quoted.  Type
'Object.constants' to see a (messy) list of all constants in the environment.

If you are using binary keys or values and need to enter them in the shell, use
double-quote'd hexadecimal representation. For example:

  hbase> get 't1', "key\x03\x3f\xcd"
  hbase> get 't1', "key\003\023\011"
  hbase> put 't1', "test\xef\xff", 'f1:', "\x01\x33\x40"

The HBase shell is the (J)Ruby IRB with the above HBase-specific commands added.
For more on the HBase Shell, see http://hbase.apache.org/docs/current/book.html11.创建一张表,插入数据
  create 'student','info'
  put 'student','1001','info:name','Jim'
       表名   ,rowKey, 列族名:列名,值
  put 'student','1001','info:sex','female'
  put 'student','1001','info:age','18'
  list查看表是否存在
  scan 'student' 查看整表数据
  scan 'student',{STARTROW => '1001',STOPROW => '1003'} 查看[1001,1002]
  get 'student','1001' 查看某一行数据
  get 'student','1001','info:name'  查看某一行单元格数据(列)
  ctrl + backspace 退格删除
  
12.查看表结构
  describe 'student'
13.更新数据,删除数据
  put 'student','1001','info:name','Jim2' 更新数据
  deleteall 'student','1003'
  delete 'student','1003','info:name'
  disable 'student' 禁用表 
  enable 'student'
  is_enabled ‘表名’
  is_disabled ‘表名’
  drop 'student' 删除表(首先禁用)
   
14.HBase读数据流程
  HRegionServer保存着meta表以及表数据,要访问表数据,首先Client先去访问zookeeper,
  从zookeeper里面获取meta表所在的位置信息,即找到这个meta表在哪个HRegionServer上保存着。
  接着Client通过刚才获取到的HRegionServer的IP来访问Meta表所在的HRegionServer,从而读取到Meta,
  进而获取到Meta表中存放的元数据。
  Client通过元数据中存储的信息,访问对应的HRegionServer,然后扫描所在HRegionServer的Memstore和Storefile来查询数据。
  最后HRegionServer把查询到的数据响应给Client。
15.HBase写数据流程
  Client也是先访问zookeeper,找到Meta表,并获取Meta表元数据。
  确定当前将要写入的数据所对应的HRegion和HRegionServer服务器。
  Client向该HRegionServer服务器发起写入数据请求,然后HRegionServer收到请求并响应。
  Client先把数据写入到HLog,以防止数据丢失。
  然后将数据写入到Memstore。
  如果HLog和Memstore均写入成功,则这条数据写入成功。
  如果Memstore达到阈值,会把Memstore中的数据flush到Storefile中。
  当Storefile越来越多,会触发Compact合并操作,把过多的Storefile合并成一个大的Storefile。
  当Storefile越来越大,Region也会越来越大,达到阈值后,会触发Split操作,将Region一分为二。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值