hadoop集群中的HBase使用

这篇博客展示了Zookeeper的启动与状态检查,以及HBase的命名空间管理、表创建、删除、数据插入和查询操作,包括扫描、获取、删除记录等。还涉及到了HDFS上HBase的数据目录结构。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

[admin@Cluster-01 ~]$ zkServer.sh status
ZooKeeper JMX enabled by default
Using config: /home/admin/zookeeper/zookeeper-3.4.9/bin/../conf/zoo.cfg
Error contacting service. It is probably not running.
[admin@Cluster-01 ~]$ zkServer.sh start
ZooKeeper JMX enabled by default
Using config: /home/admin/zookeeper/zookeeper-3.4.9/bin/../conf/zoo.cfg
Starting zookeeper ... STARTED

[admin@Cluster-01 ~]$ start-all.sh

[admin@Cluster-01 ~]$ jps
1264 QuorumPeerMain
1716 DFSZKFailoverController
1815 ResourceManager
2232 HMaster
1418 NameNode
2429 Jps

[admin@Cluster-03 ~]$ jps
1238 QuorumPeerMain
1690 HRegionServer
1802 Jps
1310 DataNode
1502 NodeManager
1375 JournalNode
[admin@Cluster-01 ~]$ hbase shell

hbase(main):001:0> create_namespace 'testDB'
0 row(s) in 0.6260 seconds

hbase(main):002:0> list_namespace
NAMESPACE                                                                             
default                                                                               
hbase                                                                                 
testDB                                                                                
3 row(s) in 0.0690 seconds

hbase(main):003:0> drop_namespace 'testDB'
0 row(s) in 0.1670 seconds

hbase(main):004:0> list_namespace
NAMESPACE                                                                             
default                                                                               
hbase                                                                                 
2 row(s) in 0.0410 seconds

hbase(main):005:0> create_namespace 'testDB'
0 row(s) in 0.3420 seconds

hbase(main):006:0> quit
[admin@Cluster-01 ~]$ hadoop fs -ls hbase/
Found 8 items
drwxr-xr-x   - admin supergroup          0 2020-05-20 08:35 hbase/.tmp
drwxr-xr-x   - admin supergroup          0 2020-05-20 08:35 hbase/MasterProcWALs
drwxr-xr-x   - admin supergroup          0 2020-05-20 08:35 hbase/WALs
drwxr-xr-x   - admin supergroup          0 2020-05-20 08:35 hbase/corrupt
drwxr-xr-x   - admin supergroup          0 2020-05-20 08:44 hbase/data
-rw-r--r--   3 admin supergroup         42 2020-05-12 19:12 hbase/hbase.id
-rw-r--r--   3 admin supergroup          7 2020-05-12 19:12 hbase/hbase.version
drwxr-xr-x   - admin supergroup          0 2020-05-20 08:35 hbase/oldWALs
[admin@Cluster-01 ~]$ hadoop fs -ls hbase/data
Found 3 items
drwxr-xr-x   - admin supergroup          0 2020-05-12 19:13 hbase/data/default
drwxr-xr-x   - admin supergroup          0 2020-05-20 08:35 hbase/data/hbase
drwxr-xr-x   - admin supergroup          0 2020-05-20 08:44 hbase/data/testDB
[admin@Cluster-01 ~]$ hadoop fs -ls hbase/data/hbase
Found 2 items
drwxr-xr-x   - admin supergroup          0 2020-05-12 19:12 hbase/data/hbase/meta
drwxr-xr-x   - admin supergroup          0 2020-05-20 08:35 hbase/data/hbase/namespace
[admin@Cluster-01 ~]$ hadoop fs -ls hbase/data/hbase/meta
Found 3 items
drwxr-xr-x   - admin supergroup          0 2020-05-12 19:12 hbase/data/hbase/meta/.tabledesc
drwxr-xr-x   - admin supergroup          0 2020-05-12 19:12 hbase/data/hbase/meta/.tmp
drwxr-xr-x   - admin supergroup          0 2020-05-20 08:43 hbase/data/hbase/meta/1588230740
[admin@Cluster-01 ~]$ hadoop fs -ls hbase/data/hbase/namespace
Found 3 items
drwxr-xr-x   - admin supergroup          0 2020-05-20 08:35 hbase/data/hbase/namespace/.tabledesc
drwxr-xr-x   - admin supergroup          0 2020-05-20 08:35 hbase/data/hbase/namespace/.tmp
drwxr-xr-x   - admin supergroup          0 2020-05-20 08:40 hbase/data/hbase/namespace/340493c70af9881c3d77a8bd596b79bc
[admin@Cluster-01 ~]$ hadoop fs -ls hbase/data/testDB

hbase(main):001:0> create 'scores', 'grade', 'course'
0 row(s) in 3.0460 seconds

=> Hbase::Table - scores
hbase(main):002:0> list
TABLE                                                                                 
scores                                                                                
tab1                                                                                  
2 row(s) in 0.0540 seconds

=> ["scores", "tab1"]

hbase(main):003:0> describe 'scores'
Table scores is ENABLED                                                               
scores                                                                                
COLUMN FAMILIES DESCRIPTION                                                           
{NAME => 'course', BLOOMFILTER => 'ROW', VERSIONS => '1', IN_MEMORY => 'false', KEEP_D
ELETED_CELLS => 'FALSE', DATA_BLOCK_ENCODING => 'NONE', TTL => 'FOREVER', COMPRESSION 
=> 'NONE', MIN_VERSIONS => '0', BLOCKCACHE => 'true', BLOCKSIZE => '65536', REPLICATIO
N_SCOPE => '0'}                                                                       
{NAME => 'grade', BLOOMFILTER => 'ROW', VERSIONS => '1', IN_MEMORY => 'false', KEEP_DE
LETED_CELLS => 'FALSE', DATA_BLOCK_ENCODING => 'NONE', TTL => 'FOREVER', COMPRESSION =
> 'NONE', MIN_VERSIONS => '0', BLOCKCACHE => 'true', BLOCKSIZE => '65536', REPLICATION
_SCOPE => '0'}                                                                        
2 row(s) in 0.1730 seconds

hbase(main):004:0> create 'testDB:scores','grade','course'
0 row(s) in 1.4000 seconds

=> Hbase::Table - testDB:scores

hbase(main):005:0> put 'scores','Tom','grade:','5'
0 row(s) in 0.4010 seconds

hbase(main):006:0> put 'scores','Tom','course:math','97'
0 row(s) in 0.0710 seconds

hbase(main):007:0> put 'scores','Tom','course:art','87'
0 row(s) in 0.0170 seconds

hbase(main):008:0> put 'scores','Jim','grade','4'
0 row(s) in 0.0140 seconds

hbase(main):009:0> put 'scores','Jim','course:math','89'
0 row(s) in 0.0140 seconds

hbase(main):010:0> put 'scores','Jim','course:art','80'
0 row(s) in 0.0200 seconds

hbase(main):011:0> put 'scores','Jim','course:','90'
0 row(s) in 0.0210 seconds

hbase(main):012:0> put 'scores','Jim','course:','91'
0 row(s) in 0.0130 seconds

hbase(main):013:0> get 'scores','Jim'
COLUMN                 CELL                                                           
 course:               timestamp=1589937452012, value=91                              
 course:art            timestamp=1589937404824, value=80                              
 course:math           timestamp=1589937388665, value=89                              
 grade:                timestamp=1589937343885, value=4                               
4 row(s) in 0.0540 seconds

hbase(main):014:0> get 'scores','Jim','grade'
COLUMN                 CELL                                                           
 grade:                timestamp=1589937343885, value=4                               
1 row(s) in 0.0230 seconds

hbase(main):015:0> get 'scores','Tom'
COLUMN                 CELL                                                           
 course:art            timestamp=1589937321508, value=87                              
 course:math           timestamp=1589937288387, value=97                              
 grade:                timestamp=1589937235939, value=5                               
3 row(s) in 0.0160 seconds
hbase(main):017:0> get 'scores','Jim','course'
COLUMN                 CELL                                                           
 course:               timestamp=1589937452012, value=91                              
 course:art            timestamp=1589937404824, value=80                              
 course:math           timestamp=1589937388665, value=89                              
3 row(s) in 0.0240 seconds

hbase(main):018:0> scan 'scores'
ROW                    COLUMN+CELL                                                    
 Jim                   column=course:, timestamp=1589937452012, value=91              
 Jim                   column=course:art, timestamp=1589937404824, value=80           
 Jim                   column=course:math, timestamp=1589937388665, value=89          
 Jim                   column=grade:, timestamp=1589937343885, value=4                
 Tom                   column=course:art, timestamp=1589937321508, value=87           
 Tom                   column=course:math, timestamp=1589937288387, value=97          
 Tom                   column=grade:, timestamp=1589937235939, value=5                
2 row(s) in 0.0920 seconds

hbase(main):019:0> count 'scores'
2 row(s) in 0.0430 seconds

=> 2

hbase(main):020:0> get 'scores','Jim'
COLUMN                 CELL                                                           
 course:               timestamp=1589937452012, value=91                              
 course:art            timestamp=1589937404824, value=80                              
 course:math           timestamp=1589937388665, value=89                              
 grade:                timestamp=1589937343885, value=4                               
4 row(s) in 0.0240 seconds
hbase(main):021:0> delete 'scores','Jim','course:art'
0 row(s) in 0.0500 seconds

hbase(main):022:0> get 'scores','Jim'
COLUMN                    CELL                                                                   
 course:                  timestamp=1589937452012, value=91                                      
 course:math              timestamp=1589937388665, value=89                                      
 grade:                   timestamp=1589937343885, value=4                                       
3 row(s) in 0.0170 seconds

hbase(main):023:0> deleteall 'scores','Jim'
0 row(s) in 0.0260 seconds

hbase(main):024:0> get 'scores','Jim'
COLUMN                    CELL                                                                   
0 row(s) in 0.0120 seconds

hbase(main):025:0> truncate 'scores'
Truncating 'scores' table (it may take a while):
 - Disabling table...
 - Truncating table...
0 row(s) in 5.3100 seconds

hbase(main):029:0> disable 'scores'
0 row(s) in 2.2660 seconds

hbase(main):030:0> drop 'scores'
0 row(s) in 1.2830 seconds

hbase(main):031:0> scan 'scores'
ROW                       COLUMN+CELL                                                            

ERROR: Unknown table scores!


hbase(main):032:0> list
TABLE                                                                                            
tab1                                                                                             
testDB:scores                                                                                    
2 row(s) in 0.0150 seconds

=> ["tab1", "testDB:scores"]
hbase(main):033:0> disable 'testDB:scores'
0 row(s) in 2.2790 seconds

hbase(main):034:0> drop 'testDB:scores'
0 row(s) in 1.2670 seconds

hbase(main):035:0> list
TABLE                                                                                            
tab1                                                                                             
1 row(s) in 0.0180 seconds

=> ["tab1"]
hbase(main):036:0> scan 'testDB:scores'
ROW                       COLUMN+CELL                                                            

ERROR: Unknown table testDB:scores!


hbase(main):057:0> quit


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值