简介
HBase 是一个面向列式存储的分布式数据库,其设计思想来源于 Google 的 BigTable 论文。
HBase 底层存储基于 HDFS 实现,集群的管理基于 ZooKeeper 实现。
HBase 良好的分布式架构设计为海量数据的快速存储、随机访问提供了可能,基于数据副本机制和分区机制可以轻松实现在线扩容、缩容和数据容灾,是大数据领域中 Key-Value 数据结构存储最常用的数据库方案
特点
Hbase 的扩展性主要体现在两个方面,一个是基于运算能力(RegionServer) 的扩展,通过增加 RegionSever 节点的数量,提升 Hbase 上层的处理能力;另一个是基于存储能力的扩展(HDFS),通过增加 DataNode 节点数量对存储层的进行扩容,提升 HBase 的数据存储能力。
HBase 作为一个开源的分布式 Key-Value 数据库,其主要作用是面向 PB 级别数据的实时入库和快速随机访问。这主要源于上述易扩展的特点,使得 HBase 通过扩展来存储海量的数据。
Hbase 是根据列族来存储数据的。列族下面可以有非常多的列。列式存储的最大好处就是,其数据在表中是按照某列存储的,这样在查询只需要少数几个字段时,能大大减少读取的数据量。
WAL 机制保证了数据写入时不会因集群异常而导致写入数据丢失,Replication 机制保证了在集群出现严重的问题时,数据不会发生丢失或损坏。而且 Hbase 底层使用 HDFS,HDFS 本身也有备份。
在 HBase 的列族中,可以指定任意多的列,为空的列不占用存储空间,表可以设计得非常稀疏。
HBase 可以将数据存储在本地文件系统,也可以存储在 HDFS 文件系统。在生产环境中,HBase 一般运行在HDFS 上,以 HDFS 作为基础的存储设施。HBase 通过 HBase Client 提供的 Java API 来访问 HBase 数据库,以完成数据的写入和读取。HBase 集群主由HMaster、Region Server 和 ZooKeeper 组成。
架构
HBase 系统遵循 Master/Salve 架构,由三种不同类型的组件组成:
client
- 提供了访问hbase的接口
- 提供cache缓存提高访问hbase的效率 , 比如region的信息
Zookeeper
- 保证任何时候,集群中只有一个 Master;
- 存储所有 Region 的寻址入口;
- 实时监控 Region Server 的状态,将 Region Server 的上线和下线信息实时通知给 Master;
- 存储 HBase 的 Schema,包括有哪些 Table,每个 Table 有哪些 Column Family 等信息。
Master
- 为 Region Server 分配 Region;
- 负责 Region Server 的负载均衡 ;
- 发现失效的 Region Server 并重新分配其上的 Region;
- GFS 上的垃圾文件回收;
- 处理 Schema 的更新请求
Region Server
- Region Server 负责维护 Master 分配给它的 Region ,并处理发送到 Region 上的 IO 请求;
- Region Server 负责切分在运行过程中变得过大的 Region
安装
因为hbase需要依赖zookeeper和hdfs,所以在安装hbase集群之前需要确保zookeeper和hdfs的环境正常
- # 1.在conf目录下找到hbase-env.sh
- cd /opt/apps/hbase-2.2.5/conf
- vi hbase-env.sh
- # 修改的地方:
- # 1.1 配置java的环境变量,注意需要将前面的注释打开
- export JAVA_HOME=/opt/apps/jdk1.8
- #1.2 hbase中内嵌了一个zookeeper,默认使用的是内置的zoopkeeper,将等号后面的true改成false
- export HBASE_MANAGES_ZK=false
- # 2.在 conf目录下找到hbase-site.xml
- vi hbase-site.xml
- # 在最下面输入下面的配置文件
- <configuration>
- <property>
- <name>hbase.rootdir</name>
- <value>hdfs://linux01:8020/hbase</value>
- </property>
- <property>
- <name>hbase.cluster.distributed</name>
- <value>true</value>
- </property>
- <property>
- <name>hbase.unsafe.stream.capability.enforce</name>
- <value>false</value>
- </property>
- <property>
- <name>hbase.zookeeper.quorum</name>
- <value>linux01:2181,linux02:2181,linux03:2181</value>
- </property>
- </configuration>
- # 3.regionservers 配置 启动集群中的Regionserver机器
- vi regionservers
- # 输入自己的三台机器域名
- linux01
- linux02
- linux03
复制代码- for i in 2 3
- do
- scp -r hbase-2.2.5/ linux0$i:$PWD
- done
复制代码 单节点启动:- bin/hbase-daemon.sh start master
- bin/hbase-daemon.sh start regionserver
- # 提示:如果regionserver无法启动,请先检查下集群之间的节点时间是否同步
复制代码 一键启动:- # 1.jps查看
- [root@linux01 conf]# jps
- 4305 Jps
- 2386 QuorumPeerMain
- 2051 DataNode
- 3747 HMaster # 查看HMaster有无进程
- 1898 NameNode
- 3934 HRegionServer # 查看HRegionServer有无进程
- # 2.通过"linux01:16010"的方式来访问HBase管理页面,进得去代表启动成功
复制代码 数据模型
namespace:hbase中没有数据库的概念 , 是使用namespace来达到数据库分类别管理表的作用
table:表,一个表包含多行数据
Row Key (行键):一行数据包含一个唯一标识rowkey、多个column以及对应的值。在HBase中,一张表中所有row都按照rowkey的字典序由小到大排序。
Column Family(列族):在建表的时候指定,不能够随意的删减,一个列族下面可以有多个列(类似于给列进行分组,相同属性的列是一个组,给这个组取个名字叫列族)
Column Qualifier (列):列族下面的列,一个列必然是属于某一个列族的行
Cell:单元格,由(rowkey、column family、qualifier、type、timestamp,value)组成的结构,其中type表示Put/Delete操作类型,timestamp代表这个cell的版本。KV结构存储,其中rowkey、column family、qualifier、type以及timestamp是K,value字段对应KV结构的V。
Timestamp(时间戳):时间戳,每个cell在写入HBase的时候都会默认分配一个时间戳作为该cell的版本,用户也可以在写入的时候自带时间戳。HBase支持多版本特性,即同一rowkey、column下可以有多个value存在,这些value使用timestamp作为版本号,版本越大,表示数据越新。
shell客户端
- # 如果配置了环境变量:在任意地方敲 hbase shell
- # 如果没有配置环境变量,需要在bin目录下./hbase shell
- hbase shell
- # 出现如下 代表成功进入了hbase的shell客户端
- hbase(main):001:0>
复制代码 通用命令
status: 查看HBase的状态,例如,服务器的数量。- hbase(main):001:0> status
- 1 active master, 0 backup masters, 3 servers, 0 dead, 0.6667 average load
- Took 0.3609 seconds
复制代码 version: 提供正在使用HBase版本。- hbase(main):002:0> version
- 2.2.5, rf76a601273e834267b55c0cda12474590283fd4c, 2020年 05月 21日 星期四 18:34:40 CST
- Took 0.0004 seconds
复制代码 table_help: 表引用命令提供帮助。- 关于表的一些命令参考
- 如:
- To read the data out, you can scan the table:
- hbase> t.scan
- which will read all the rows in table 't'.
复制代码 whoami: 提供有关用户的信息。- hbase(main):004:0> whoami
- root (auth:SIMPLE)
- groups: root
- Took 0.0098 seconds
复制代码 命名空间相关命令
list_namespace:列出所有的命名空间- hbase(main):005:0> list_namespace
- NAMESPACE
- default
- hbase
- 2 row(s)
- Took 0.0403 seconds
复制代码 create_namespace:创建一个命名空间- hbase(main):002:0> create_namespace doit
- NameError: undefined local variable or method 'doit' for main:Object
- # 名称需要加上引号
- hbase(main):003:0> create_namespace 'doit'
- Took 0.2648 seconds
复制代码 describe_namespace:描述一个命名空间- hbase(main):004:0> describe_namespace 'doit'
- DESCRIPTION
- {NAME => 'doit'}
- Quota is disabled
- Took 0.0710 seconds
复制代码 drop_namespace:删除一个命名空间- # 注意 :只能删除空的命名空间,如果里面有表是删除不了的
- hbase(main):005:0> drop_namespace 'doit'
- Took 0.2461 seconds
- # 命名空间不为空的话
- hbase(main):035:0> drop_namespace 'doit'
- ERROR: org.apache.hadoop.hbase.constraint.ConstraintException: Only empty namespaces can be removed. Namespace doit has 1 tables
- at org.apache.hadoop.hbase.master.procedure.DeleteNamespaceProcedure.prepareDelete(DeleteNamespaceProcedure.java:217)
- at org.apache.hadoop.hbase.master.procedure.DeleteNamespaceProcedure.executeFromState(DeleteNamespaceProcedure.java:78)
- at org.apache.hadoop.hbase.master.procedure.DeleteNamespaceProcedure.executeFromState(DeleteNamespaceProcedure.java:45)
- at org.apache.hadoop.hbase.procedure2.StateMachineProcedure.execute(StateMachineProcedure.java:194)
- at org.apache.hadoop.hbase.procedure2.Procedure.doExecute(Procedure.java:962)
- at org.apache.hadoop.hbase.procedure2.ProcedureExecutor.execProcedure(ProcedureExecutor.java:1662)
- at org.apache.hadoop.hbase.procedure2.ProcedureExecutor.executeProcedure(ProcedureExecutor.java:1409)
- at org.apache.hadoop.hbase.procedure2.ProcedureExecutor.access$1100(ProcedureExecutor.java:78)
- at org.apache.hadoop.hbase.procedure2.ProcedureExecutor$WorkerThread.run(ProcedureExecutor.java:1979)
- For usage try 'help "drop_namespace"'
- Took 0.1448 seconds
复制代码 alter_namespace:修改namespace其中属性- hbase(main):038:0> alter_namespace 'doit',{METHOD => 'set', 'PROPERTY_NAME' => 'PROPERTY_VALUE'}
- Took 0.2491 seconds
复制代码 list_namespace_tables:列出一个命名空间下所有的表- hbase(main):037:0> list_namespace_tables 'doit'
- TABLE
- user
- 1 row(s)
- Took 0.0372 seconds
- => ["user"]
复制代码 DDL相关命令
list:列举出默认名称空间下所有的表- hbase(main):001:0> list
- TABLE
- doit:user
- 1 row(s)
- Took 0.3187 seconds
- => ["doit:user"]
复制代码 create:建表- create ‘xx:t1’,{NAME=>‘f1’,VERSION=>5}
- # 创建表t1并指明命名空间xx
- # {NAME} f1指的是列族
- # VERSION 表示版本数
- # 多个列族f1、f2、f3
- create ‘t2’,{NAME=>‘f1’},{NAME=>‘f2’},{NAME=>‘f3’}
- hbase(main):003:0> create 'doit:student' 'f1','f2','f3'
- Created table doit:studentf1
- Took 1.2999 seconds
- => Hbase::Table - doit:studentf1
- # 创建表得时候预分region
- hbase(main):106:0> create 'doit:test','f1', SPLITS => ['rowkey_010','rowkey_020','rowkey_030','rowkey_040']
- Created table doit:test
- Took 1.3133 seconds
- => Hbase::Table - doit:test
复制代码 drop:删除表- hbase(main):006:0> drop 'doit:studentf1'
- ERROR: Table doit:studentf1 is enabled. Disable it first.
- For usage try 'help "drop"'
- Took 0.0242 seconds
- # 注意:删除表之前需要禁用表
- hbase(main):007:0> disable 'doit:studentf1'
- Took 0.7809 seconds
- hbase(main):008:0> drop 'doit:studentf1'
- Took 0.2365 seconds
复制代码 drop_all:丢弃在命令中给出匹配“regex”的表- hbase(main):023:0> disable_all 'doit:student.*'
- doit:student1
- doit:student2
- doit:student3
- doit:studentf1
- Disable the above 4 tables (y/n)?
- y
- 4 tables successfully disabled
- Took 4.3497 seconds
- hbase(main):024:0> drop_all 'doit:student.*'
- doit:student1
- doit:student2
- doit:student3
- doit:studentf1
- Drop the above 4 tables (y/n)?
- y
- 4 tables successfully dropped
- Took 2.4258 seconds
复制代码 disable:禁用表- # 删除表之前必须先禁用表
- hbase(main):007:0> disable 'doit:studentf1'
- Took 0.7809 seconds
复制代码 disable_all:禁用在命令中给出匹配“regex”的表- hbase(main):023:0> disable_all 'doit:student.*'
- doit:student1
- doit:student2
- doit:student3
- doit:studentf1
- Disable the above 4 tables (y/n)?
- y
- 4 tables successfully disabled
- Took 4.3497 seconds
复制代码 enable:启用表- hbase(main):007:0> enable 'doit:student'
- Took 0.7809 seconds
复制代码 enable_all:启用在命令中给出匹配“regex”的表- hbase(main):032:0> enable_all 'doit:student.*'
- doit:student
- doit:student1
- doit:student2
- doit:student3
- doit:student4
- Enable the above 5 tables (y/n)?
- y
- 5 tables successfully enabled
- Took 5.0114 seconds
复制代码 is_enabled:判断该表是否是启用的表- hbase(main):034:0> is_enabled 'doit:student'
- true
- Took 0.0065 seconds
- => true
复制代码 is_disabled:判断该表是否是禁用的表- hbase(main):035:0> is_disabled 'doit:student'
- false
- Took 0.0046 seconds
- => 1
复制代码 describe:描述这张表- hbase(main):038:0> describe 'doit:student'
- Table doit:student is ENABLED
- doit:student
- COLUMN FAMILIES DESCRIPTION
- {NAME => 'f1', VERSIONS => '1', EVICT_BLOCKS_ON_CLOSE => 'false', NEW_VERSION_BEHAVIOR => 'false', KEEP_DELETED_CELLS => 'FALSE', CACHE_DATA_ON_WRITE => 'false', DATA_BLO
- CK_ENCODING => 'NONE', TTL => 'FOREVER', MIN_VERSIONS => '0', REPLICATION_SCOPE => '0', BLOOMFILTER => 'ROW', CACHE_INDEX_ON_WRITE => 'false', IN_MEMORY => 'false', CACHE
- _BLOOMS_ON_WRITE => 'false', PREFETCH_BLOCKS_ON_OPEN => 'false', COMPRESSION => 'NONE', BLOCKCACHE => 'true', BLOCKSIZE => '65536'}
- {NAME => 'f2', VERSIONS => '1', EVICT_BLOCKS_ON_CLOSE => 'false', NEW_VERSION_BEHAVIOR => 'false', KEEP_DELETED_CELLS => 'FALSE', CACHE_DATA_ON_WRITE => 'false', DATA_BLO
- CK_ENCODING => 'NONE', TTL => 'FOREVER', MIN_VERSIONS => '0', REPLICATION_SCOPE => '0', BLOOMFILTER => 'ROW', CACHE_INDEX_ON_WRITE => 'false', IN_MEMORY => 'false', CACHE
- _BLOOMS_ON_WRITE => 'false', PREFETCH_BLOCKS_ON_OPEN => 'false', COMPRESSION => 'NONE', BLOCKCACHE => 'true', BLOCKSIZE => '65536'}
- {NAME => 'f3', VERSIONS => '1', EVICT_BLOCKS_ON_CLOSE => 'false', NEW_VERSION_BEHAVIOR => 'false', KEEP_DELETED_CELLS => 'FALSE', CACHE_DATA_ON_WRITE => 'false', DATA_BLO
- CK_ENCODING => 'NONE', TTL => 'FOREVER', MIN_VERSIONS => '0', REPLICATION_SCOPE => '0', BLOOMFILTER => 'ROW', CACHE_INDEX_ON_WRITE => 'false', IN_MEMORY => 'false', CACHE
- _BLOOMS_ON_WRITE => 'false', PREFETCH_BLOCKS_ON_OPEN => 'false', COMPRESSION => 'NONE', BLOCKCACHE => 'true', BLOCKSIZE => '65536'}
- 3 row(s)
- QUOTAS
- 0 row(s)
- Took 0.0349 seconds
- # VERSIONS => '1', -- 版本数量
- # EVICT_BLOCKS_ON_CLOSE => 'false',
- # NEW_VERSION_BEHAVIOR => 'false',
- # KEEP_DELETED_CELLS => 'FALSE', 保留删除的单元格
- # CACHE_DATA_ON_WRITE => 'false',
- # DATA_BLOCK_ENCODING => 'NONE',
- # TTL => 'FOREVER', -- 过期时间
- # MIN_VERSIONS => '0', -- 最小版本数
- # REPLICATION_SCOPE => '0',
- # BLOOMFILTER => 'ROW', --布隆过滤器
- # CACHE_INDEX_ON_WRITE => 'false',
- # IN_MEMORY => 'false', -- 内存中
- # CACHE_BLOOMS_ON_WRITE => 'false', --布隆过滤器
- # PREFETCH_BLOCKS_ON_OPEN => 'false',
- # COMPRESSION => 'NONE', -- 压缩格式
- # BLOCKCACHE => 'true', -- 块缓存
- # BLOCKSIZE => '65536' -- 块大小
复制代码 alter:修改表里面的属性- hbase(main):040:0> alter 'doit:student', NAME => 'cf1', VERSIONS => 5, TTL => 10
- Updating all regions with the new schema...
- 1/1 regions updated.
- Done.
- Took 2.1406 seconds
复制代码 alter_async:直接操作不等待,和上面的alter功能一样- hbase(main):059:0> alter_async 'doit:student', NAME => 'cf1', VERSIONS => 5, TTL => 10
- Took 1.0268 seconds
复制代码 alter_status:获取alter命令的执行状态- hbase(main):060:0> alter_status 'doit:student'
- 1/1 regions updated.
- Done.
- Took 1.0078 seconds
复制代码 list_regions:列出一个表中所有的region- Examples:
- hbase> list_regions 'table_name'
- hbase> list_regions 'table_name', 'server_name'
- hbase> list_regions 'table_name', {SERVER_NAME => 'server_name', LOCALITY_THRESHOLD => 0.8}
- hbase> list_regions 'table_name', {SERVER_NAME => 'server_name', LOCALITY_THRESHOLD => 0.8}, ['SERVER_NAME']
- hbase> list_regions 'table_name', {}, ['SERVER_NAME', 'start_key']
- hbase> list_regions 'table_name', '', ['SERVER_NAME', 'start_key']
- hbase(main):045:0> list_regions 'doit:student'
- SERVER_NAME | REGION_NAME | START_KEY | END_KEY | SIZE | REQ | LOCALITY |
- --------------------------- | ------------------------------------------------------------- | ---------- | ---------- | ----- | ----- | ---------- |
- linux02,16020,1683636566738 | doit:student,,1683642944714.39f7c8772bc476c4d38c663e879d50da. | | | 0 | 0 | 0.0 |
- 1 rows
- Took 0.0145 seconds
复制代码 locate_region:通过表名和row名方式获取region- hbase(main):062:0> locate_region 'doit:student', 'key0'
- HOST REGION
- linux02:16020 {ENCODED => 39f7c8772bc476c4d38c663e879d50da, NAME => 'doit:student,,1683642944714.39f7c8772bc476c4d38c663e879d50da.', STARTKEY => '', ENDK
- EY => ''}
- 1 row(s)
- Took 0.0027 seconds
复制代码 show_filters:显示hbase的所有的过滤器- hbase(main):058:0> show_filters
- DependentColumnFilter
- KeyOnlyFilter
- ColumnCountGetFilter
- SingleColumnValueFilter
- PrefixFilter
- SingleColumnValueExcludeFilter
- FirstKeyOnlyFilter
- ColumnRangeFilter
- ColumnValueFilter
- TimestampsFilter
- FamilyFilter
- QualifierFilter
- ColumnPrefixFilter
- RowFilter
- MultipleColumnPrefixFilter
- InclusiveStopFilter
- PageFilter
- ValueFilter
- ColumnPaginationFilter
- Took 0.0035 seconds
复制代码 DML相关命令
put插入/更新数据【某一行的某一列】(如果不存在,就插入,如果存在就更新)- hbase(main):007:0> put 'doit:user_info' ,'rowkey_001','f1:name','zss'
- Took 0.0096 seconds
- hbase(main):008:0> put 'doit:user_info' ,'rowkey_001','f1:age','1'
- Took 0.0039 seconds
- hbase(main):009:0> put 'doit:user_info' ,'rowkey_001','f1:gender','male'
- Took 0.0039 seconds
- hbase(main):010:0> put 'doit:user_info' ,'rowkey_001','f2:phone_num','98889'
- Took 0.0040 seconds
- hbase(main):011:0> put 'doit:user_info' ,'rowkey_001','f2:gender','98889'
- # 注意:put中需要指定哪个命名空间的那个表,然后rowkey是什么,哪个列族下面的哪个列名,然后值是什么
- # 一个个的插入,不能一下子插入多个列名的值
复制代码 get:获取一个列族中列这个cell- hbase(main):015:0> get 'doit:user_info' ,'rowkey_001','f2:gender'
- COLUMN CELL
- f2:gender timestamp=1683646645379, value=123
- 1 row(s)
- Took 0.0242 seconds
- hbase(main):016:0> get 'doit:user_info' ,'rowkey_001'
- COLUMN CELL
- f1:age timestamp=1683646450598, value=1
- f1:gender timestamp=1683646458847, value=male
- f1:name timestamp=1683646443469, value=zss
- f2:gender timestamp=1683646645379, value=123
- f2:phone_num timestamp=1683646472508, value=98889
- 1 row(s)
- Took 0.0129 seconds
- # 如果遇到中文乱码的问题怎么办呢?在最后加上{'FORMATTER'=>'toString'}参数即可
- hbase(main):137:0> get 'doit:student','rowkey_001',{'FORMATTER'=>'toString'}
- COLUMN CELL
- f1:name timestamp=1683864047691, value=张三
- 1 row(s)
- Took 0.0057 seconds
- # 注意:get是hbase中查询数据最快的方式,但是只能每次返回一个rowkey的数据
复制代码 scan:扫描表中的所有数据- hbase(main):012:0> scan 'doit:user_info'
- ROW COLUMN+CELL
- rowkey_001 column=f1:age, timestamp=1683646450598, value=1
- rowkey_001 column=f1:gender, timestamp=1683646458847, value=male
- rowkey_001 column=f1:name, timestamp=1683646443469, value=zss
- rowkey_001 column=f2:gender, timestamp=1683646483495, value=98889
- rowkey_001 column=f2:phone_num, timestamp=1683646472508, value=98889
- 1 row(s)
- Took 0.1944 seconds
- scan 'tbname',{Filter(过滤器)}
- scan 'itcast:t2'
- #rowkey前缀过滤器
- scan 'itcast:t2', {ROWPREFIXFILTER => '2021'}
- scan 'itcast:t2', {ROWPREFIXFILTER => '202101'}
- #rowkey范围过滤器
- #STARTROW:从某个rowkey开始,包含,闭区间
- #STOPROW:到某个rowkey结束,不包含,开区间
- scan 'itcast:t2',{STARTROW=>'20210101_000'}
- scan 'itcast:t2',{STARTROW=>'20210201_001'}
- scan 'itcast:t2',{STARTROW=>'20210101_000',STOPROW=>'20210201_001'}
- scan 'itcast:t2',{STARTROW=>'20210201_001',STOPROW=>'20210301_007'}
- # 在Hbase数据检索,==尽量走索引查询:按照Rowkey条件查询==
- # 尽量避免走全表扫描
- # 索引查询:有一本新华字典,这本字典可以根据拼音检索,找一个字,先找目录,找字
- # 全表扫描:有一本新华字典,这本字典没有检索目录,找一个字,一页一页找
- # ==Hbase所有Rowkey的查询都是前缀匹配==
- # 如果遇到中文乱码的问题在最后加上{'FORMATTER'=>'toString'}参数即可
- hbase(main):130:0> scan 'doit:student',{'FORMATTER'=>'toString'}
- ROW COLUMN+CELL
- rowkey_001 column=f1:name, timestamp=1683863389259, value=张三
- 1 row(s)
- Took 0.0063 seconds
复制代码 incr:一般用于自动计数的,不用记住上一次的值,直接做自增- # 注意:因为shell往米面设置的value的值是String类型的
- hbase(main):005:0> incr 'doit:student','rowkey002', 'f1:age'
- COUNTER VALUE = 1
- Took 0.1877 seconds
- hbase(main):006:0> incr 'doit:student','rowkey002', 'f1:age'
- COUNTER VALUE = 2
- Took 0.0127 seconds
- hbase(main):007:0> incr 'doit:student','rowkey002', 'f1:age'
- COUNTER VALUE = 3
- Took 0.0079 seconds
- hbase(main):011:0> incr 'doit:student','rowkey002', 'f1:age'
- COUNTER VALUE = 4
- Took 0.0087 seconds
复制代码 count:统计一个表里面有多少行数据- hbase(main):031:0> count 'doit:user_info'
- 1 row(s)
- Took 0.0514 seconds
- => 1
复制代码 delete删除某一行中列对应的值- # 删除某一行中列对应的值
- hbase(main):041:0> delete 'doit:student' ,'rowkey_001','f1:id'
- Took 0.0152 seconds
复制代码 deleteall:删除一行数据- # 根据rowkey删除一行数据
- hbase(main):042:0> deleteall 'doit:student','rowkey_001'
- Took 0.0065 seconds
复制代码 append:追加,假如该列不存在添加新列,存在将值追加到最后- # 再原有值得基础上追加值
- hbase(main):098:0> append 'doit:student','rowkey_001','f1:name','hheda'
- CURRENT VALUE = zsshheda
- Took 0.0070 seconds
- hbase(main):100:0> get 'doit:student','rowkey_001','f1:name'
- COLUMN CELL
- f1:name timestamp=1683861530789, value=zsshheda
- 1 row(s)
- Took 0.0057 seconds
- #注意:如果原来没有这个列,会自动添加一个列,然后将值set进去
- hbase(main):101:0> append 'doit:student','rowkey_001','f1:name1','hheda'
- CURRENT VALUE = hheda
- Took 0.0063 seconds
- hbase(main):102:0> get 'doit:student','rowkey_001','f1:name1'
- COLUMN CELL
- f1:name1 timestamp=1683861631392, value=hheda
- 1 row(s)
- Took 0.0063 seconds
复制代码 truncate:清空表里面所有的数据- # 执行流程
- # 先disable表
- # 然后再drop表
- # 最后重新create表
- hbase(main):044:0> truncate 'doit:student'
- Truncating 'doit:student' table (it may take a while):
- Disabling table...
- Truncating table...
- Took 2.5457 seconds
复制代码 truncate_preserve:清空表但保留分区- hbase(main):008:0> truncate_preserve 'doit:test'
- Truncating 'doit:test' table (it may take a while):
- Disabling table...
- Truncating table...
- Took 4.1352 seconds
- hbase(main):009:0> list_regions 'doit:test'
- SERVER_NAME | REGION_NAME | START_KEY | END_KEY | SIZE | REQ | LOCALITY |
- --------------------------- | -------------------------------------------------------------------- | ---------- | ---------- | ----- | ----- | ---------- |
- linux03,16020,1684200651855 | doit:test,,1684205468848.920ae3e043ad95890c4f5693cb663bc5. | | rowkey_010 | 0 | 0 | 0.0 |
- linux01,16020,1684205091382 | doit:test,rowkey_010,1684205468848.f8a21615be51f42c562a2338b1efa409. | rowkey_010 | rowkey_020 | 0 | 0 | 0.0 |
- linux02,16020,1684200651886 | doit:test,rowkey_020,1684205468848.25d62e8cc2fdaecec87234b8d28f0827. | rowkey_020 | rowkey_030 | 0 | 0 | 0.0 |
- linux03,16020,1684200651855 | doit:test,rowkey_030,1684205468848.2b0468e6643b95159fa6e210fa093e66. | rowkey_030 | rowkey_040 | 0 | 0 | 0.0 |
- linux01,16020,1684205091382 | doit:test,rowkey_040,1684205468848.fb12c09c7c73cfeff0bf79b5dda076cb. | rowkey_040 | | 0 | 0 | 0.0 |
- 5 rows
- Took 0.1019 seconds
复制代码 get_counter:获取计数器- hbase(main):017:0> incr 'doit:student','rowkey_001','f1:name2'
- COUNTER VALUE = 1
- Took 0.0345 seconds
- hbase(main):018:0> incr 'doit:student','rowkey_001','f1:name2'
- COUNTER VALUE = 2
- Took 0.0066 seconds
- hbase(main):019:0> incr 'doit:student','rowkey_001','f1:name2'
- COUNTER VALUE = 3
- Took 0.0059 seconds
- hbase(main):020:0> incr 'doit:student','rowkey_001','f1:name2'
- COUNTER VALUE = 4
- Took 0.0061 seconds
- hbase(main):021:0> incr 'doit:student','rowkey_001','f1:name2'
- COUNTER VALUE = 5
- Took 0.0064 seconds
- hbase(main):022:0> incr 'doit:student','rowkey_001','f1:name2'
- COUNTER VALUE = 6
- Took 0.0062 seconds
- hbase(main):023:0> incr 'doit:student','rowkey_001','f1:name2'
- COUNTER VALUE = 7
- Took 0.0066 seconds
- hbase(main):024:0> incr 'doit:student','rowkey_001','f1:name2'
- COUNTER VALUE = 8
- Took 0.0059 seconds
- hbase(main):025:0> incr 'doit:student','rowkey_001','f1:name2'
- COUNTER VALUE = 9
- Took 0.0063 seconds
- hbase(main):026:0> incr 'doit:student','rowkey_001','f1:name2'
- COUNTER VALUE = 10
- Took 0.0061 seconds
- hbase(main):027:0> get_counter 'doit:student','rowkey_001','f1:name2'
- COUNTER VALUE = 10
- Took 0.0040 seconds
复制代码 get_splits:用于获取表所对应的region数个数- hbase(main):148:0> get_splits 'doit:test'
- Total number of splits = 5
- rowkey_010
- rowkey_020
- rowkey_030
- rowkey_040
- Took 0.0120 seconds
- => ["rowkey_010", "rowkey_020", "rowkey_030", "rowkey_040"]
复制代码 免责声明:如果侵犯了您的权益,请联系站长,我们会及时删除侵权内容,谢谢合作! |