1.進(jìn)入hbase shell console
$HBASE_HOME/bin/hbase shell
如果有kerberos認(rèn)證,需要事先使用相應(yīng)的keytab進(jìn)行一下認(rèn)證(使用kinit命令)蜕琴,認(rèn)證成功之后再使用hbase shell進(jìn)入可以使用whoami
命令可查看當(dāng)前用戶
hbase(main) > whoami```
**2表的管理**
>1)查看有哪些表hbase(main)> list
>2)創(chuàng)建表
*語法*:
```create <table>, {NAME => <family>, VERSIONS => <VERSIONS>}```
例如:創(chuàng)建表t1,有兩個family name:f1,f2颁股,且版本數(shù)均為2
hbase(main)> create 't1',
{NAME =>'f1', VERSIONS => 2},
{NAME =>'f2' , VERSIONS => 2}
> 3)刪除表
分兩步:首先disable,然后drop
例如:刪除表t1
hbase(main)> disable 't1'
hbase(main)> drop 't1'
4)查看表的結(jié)構(gòu)
*語法*:``describe <table>``
例如:查看表t1的結(jié)構(gòu)
hbase(main)> describe 't1'
5)修改表結(jié)構(gòu)修改表結(jié)構(gòu)必須先disable
*語法*:``alter 't1', {NAME => 'f1'}, {NAME => 'f2', METHOD => 'delete'}``
例如:修改表test1的cf的TTL為180天
hbase(main)> disable 'test1'
hbase(main)> alter 'test1'
,{NAME=>'body' ,TTL=>'15552000'}
,{NAME=>'meta', TTL=>'15552000'}
hbase(main)>enable 'test1'
**3.權(quán)限管理**
>1)分配權(quán)限# 語法 : grant <user> <permissions> <table> <column family> <column qualifier> 參數(shù)后面用逗號分隔
**權(quán)限**用五個字母表示: "RWXCA".
```READ('R'), WRITE('W'), EXEC('X'), CREATE('C'), ADMIN('A')```
例如狗准,給用戶‘test'分配對表t1有讀寫的權(quán)限,
```hbase(main)> grant 'test' , 'RW' , 't1' ```
2)查看權(quán)限
*語法*:``user_permission <table>``
例如茵肃,查看表t1的權(quán)限列表
```hbase(main)> user_permission 't1'```
3)收回權(quán)限
與分配權(quán)限類似,
*語法*:```revoke <user> <table> <column family> <column qualifier>```
例如腔长,收回test用戶在表t1上的權(quán)限
hbase(main)> revoke 'test' , 't1'```
4.表數(shù)據(jù)的增刪改查
1)添加數(shù)據(jù)
語法:put <table>,<rowkey>,<family:column>,<value>,<timestamp>
例如:給表t1的添加一行記錄:rowkey是rowkey001,family name:f1验残,column name:col1捞附,value:value01,timestamp:系統(tǒng)默認(rèn)
hbase(main)> put 't1' ,
'rowkey001' ,
'f1:col1', 'value01'
用法比較單一您没。
2)查詢數(shù)據(jù)
a)查詢某行記錄
語法:get <table>,<rowkey>,[<family:column>,....]
例如:查詢表t1鸟召,rowkey001中的f1下的col1的值
hbase(main)> get 't1',
'rowkey001' , 'f1:col1'
或者:
hbase(main)> get 't1' , 'rowkey001' ,
{COLUMN=>'f1:col1'}
查詢表t1,rowke002中的f1下的所有列值
hbase(main)> get 't1','rowkey001'
b)掃描表
語法:scan <table>, {COLUMNS => [ <family:column>,.... ], LIMIT => num}
另外氨鹏,還可以添加STARTROW欧募、TIMERANGE和FITLER等高級功能
例如:掃描表t1的前5條數(shù)據(jù)
hbase(main)> scan 't1' , {LIMIT=>5}
c)查詢表中的數(shù)據(jù)行數(shù)
語法:count <table>, {INTERVAL => intervalNum, CACHE => cacheNum}
INTERVAL設(shè)置多少行顯示一次及對應(yīng)的rowkey,默認(rèn)1000仆抵;CACHE每次去取的緩存區(qū)大小跟继,默認(rèn)是10,調(diào)整該參數(shù)可提高查詢速度.
例如镣丑,查詢表t1中的行數(shù)舔糖,每100條顯示一次,緩存區(qū)為500
hbase(main)> count 't1',
{INTERVAL => 100, CACHE => 500}
3)刪除數(shù)據(jù)
a )刪除行中的某個列值
語法:delete <table>, <rowkey>, <family:column> , <timestamp>
,必須指定列名
例如:刪除表t1莺匠,rowkey001中的f1:col1的數(shù)據(jù)
hbase(main)> delete 't1' ,
'rowkey001' ,'f1:col1'
注:將刪除改行f1:col1列所有版本的數(shù)據(jù)
b )刪除行
語法:deleteall <table>, <rowkey>, <family:column> , <timestamp>
金吗,可以不指定列名,刪除整行數(shù)據(jù)
例如:刪除表t1趣竣,rowk001的數(shù)據(jù)
hbase(main)> deleteall 't1','rowkey001'
c)刪除表中的所有數(shù)據(jù)
語法: truncate <table>
其具體過程是:disable table -> drop table -> create table
例如:刪除表t1的所有數(shù)據(jù)
hbase(main)> truncate 't1'
5.Region管理
1)移動region
語法:move 'encodeRegionName', 'ServerName'
encodeRegionName
指的regioName
后面的編碼摇庙,ServerName
指的是master-status
的Region Servers
列表
示例
hbase(main)>move
'4343995a58be8e5bbc739af1e91cd72d' ,
'db-41.xxx.xxx.org,60020,1390274516739'
2)開啟/關(guān)閉region
語法:balance_switch true|false
hbase(main)> balance_switch
3)手動split
語法:split 'regionName', 'splitKey'
4)手動觸發(fā)major compaction
語法:Compact all regions in a table:
hbase> major_compact 't1'
Compact an entire region:
hbase> major_compact 'r1'
Compact a single column family within a region:
hbase> major_compact 'r1', 'c1'
Compact a single column family within a table:
hbase> major_compact 't1', 'c1'
6.配置管理及節(jié)點(diǎn)重啟
1)修改hdfs配置hdfs配置位置:
/etc/hadoop/conf
同步hdfs配置
cat /home/hadoop/slaves | xargs -i -t scp /etc/hadoop/conf/hdfs-site.xml hadoop@{}: /etc/hadoop/conf/hdfs-site.xml
關(guān)閉:
cat /home/hadoop/slaves | xargs -i -t ssh hadoop@{} "sudo /home/hadoop/cdh4/hadoop-2.0.0-cdh4.2.1/sbin/hadoop-daemon.sh --config /etc/hadoop/conf stop datanode"
啟動:
cat /home/hadoop/slaves | xargs -i -t ssh hadoop@{} "sudo /home/hadoop/cdh4/hadoop-2.0.0-cdh4.2.1/sbin/hadoop-daemon.sh --config /etc/hadoop/conf start datanode"
2)修改hbase配置hbase配置位置:
同步hbase配置
cat /home/hadoop/hbase/conf/regionservers | xargs -i -t scp /home/hadoop/hbase/conf/hbase-site.xml hadoop@{}:/home/hadoop/hbase/conf/hbase-site.xml
graceful重啟
cd ~/hbase bin/graceful_stop.sh --restart --reload --debug inspurXXX.xxx.xxx.org