栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 前沿技术 > 大数据 > 大数据系统

Hbase 基本操作练习

Hbase 基本操作练习

基本配置环境展示


这里是工作室电脑 linux 系统伪分布式单机 hbase 配置的环境展示,全分布式安装 hbase 暂时还有些问题尚未解决,日后配置完成会发布相应配置记录。

参考配置教程

注意hbase 与 hadoop版本。

实验目的
  1. 理解Hbase在Hadoop体系结构中的角色;
  2. 熟练使用Hbase操作常用的Shell命令;
实验内容:hbase一些基本操作练习

编程实现以下功能,并利用Hbase提供的Shell命令完成任务:

创建一个名为test1的表,列族名为 f1,列族版本号为5(保留5个最近历史版本),允许读取数据时进行缓存,其余参数均采用默认值。

hbase(main):001:0> create 'test1',{NAME=>'f1', VERSIONS=>5, BLOCKCACHE => true} 
Created table test1
Took 1.4086 seconds                                                            
=> Hbase::Table - test1

修改表的结构

hbase(main):002:0> alter 'test1', {NAME=>'basic',IN_MEMORY=> true}
Updating all regions with the new schema...
1/1 regions updated.
Done.
Took 2.1550 seconds 

描述表的结构

hbase(main):003:0> describe 'test1'
Table test1 is ENABLED                                                             
test1                                                                              
COLUMN FAMILIES DEscriptION                                                        
{NAME => 'basic', BLOOMFILTER => 'ROW', IN_MEMORY => 'true', VERSIONS => '1', KEEP_
DELETED_CELLS => 'FALSE', DATA_BLOCK_ENCODING => 'NONE', COMPRESSION => 'NONE', TTL
 => 'FOREVER', MIN_VERSIONS => '0', BLOCKCACHE => 'true', BLOCKSIZE => '65536', REP
LICATION_SCOPE => '0'}                                                             

{NAME => 'f1', BLOOMFILTER => 'ROW', IN_MEMORY => 'false', VERSIONS => '5', KEEP_DE
LETED_CELLS => 'FALSE', DATA_BLOCK_ENCODING => 'NONE', COMPRESSION => 'NONE', TTL =
> 'FOREVER', MIN_VERSIONS => '0', BLOCKCACHE => 'true', BLOCKSIZE => '65536', REPLI
CATION_SCOPE => '0'}                                                               

2 row(s)
Quota is disabled
Took 0.0202 seconds

确认 test1 表是否存在

hbase(main):004:0> exists 'test1'
Table test1 does exist                                                             
Took 0.0116 seconds                                                                
=> true

显示所有表名列表,查看当前所有列表

hbase(main):005:0> list
TABLE                                                                              
test1                                                                              
1 row(s)
Took 0.0089 seconds                                                                
=> ["test1"]

禁用表 test1

hbase(main):006:0> disable 'test1'
Took 0.3409 seconds 

确认 test1 表是否被禁用

hbase(main):007:0> is_disabled 'test1'
true                                                                               
Took 0.0055 seconds                                                                
=> 1

查看表 test1 的状态并解禁表 test1

hbase(main):008:0> scan 'test1'
ROW                   COLUMN+CELL                                        
org.apache.hadoop.hbase.TableNotEnabledException: test1 is disabled.
        at org.apache.hadoop.hbase.client.ConnectionImplementation.relocateRegion(ConnectionImplementation.java:770)
        at org.apache.hadoop.hbase.client.RpcRetryingCallerWithReadReplicas.getRegionLocations(RpcRetryingCallerWithReadReplicas.java:330)
        at org.apache.hadoop.hbase.client.ScannerCallable.prepare(ScannerCallable.java:139)
        at org.apache.hadoop.hbase.client.ScannerCallableWithReplicas$RetryingRPC.prepare(ScannerCallableWithReplicas.java:408)
        at org.apache.hadoop.hbase.client.RpcRetryingCallerImpl.callWithRetries(RpcRetryingCallerImpl.java:105)
        at org.apache.hadoop.hbase.client.ResultBoundedCompletionService$QueueingFuture.run(ResultBoundedCompletionService.java:80)
        at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
        at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
        at java.lang.Thread.run(Thread.java:748)

ERROR: Table test1 is disabled!

For usage try 'help "scan"'

Took 0.4912 seconds                                                      
# 这里才是解禁操作(忽略上面的报错
hbase(main):009:0> enable 'test1'
Took 0.6368 seconds              
#再次查看                                        
hbase(main):010:0> scan 'test1'
ROW                 COLUMN+CELL                                          
0 row(s)
Took 0.0178 seconds 

删除表 test1

# 要先禁用再删除
hbase(main):011:0> drop 'test1'

ERROR: Table test1 is enabled. Disable it first.

For usage try 'help "drop"'

Took 0.0138 seconds                                                      
hbase(main):012:0> disable 'test1'
Took 0.3230 seconds                                                      
hbase(main):013:0> drop 'test1'
Took 0.1339 seconds

新建一个 test1 表,禁用删除并重建一个表

hbase(main):015:0> create 'test1',{NAME=>'f1', VERSIONS=>5, BLOCKCACHE => true}
Created table test1
Took 1.1222 seconds                                                      
=> Hbase::Table - test1                                              
hbase(main):016:0> truncate 'test1'
Truncating 'test1' table (it may take a while):
Disabling table...
Truncating table...
Took 2.4535 seconds            
一些问题的解答 为什么不要求 hbase 的 Master 一定是 Namenode?

为了保证Hbase集群的高可靠性,Hbase支持多Backup Master 设置。

可通过多个hbase的Master使得hbase集群一台机器上有活动的master节点,则该master节点为master,所以其他节点开始等待,直到此节点上的hmaster挂掉。其他节点会变成新的Master节点。

这样就可以说明为什么不要求 hbase 的 Master 一定是 Namenode,但一般将hbase的Master配置在Namenode上。

转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/311256.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号