HBase shell 命令。
生活随笔
收集整理的這篇文章主要介紹了
HBase shell 命令。
小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.
HBase shell 命令。
?
$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 |
1)查看有哪些表
| hbase(main)> list |
2)創(chuàng)建表
| # 語(yǔ)法:create <table>, {NAME => <family>, VERSIONS => <VERSIONS>} # 例如:創(chuàng)建表t1,有兩個(gè)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)
| # 語(yǔ)法:describe <table> # 例如:查看表t1的結(jié)構(gòu) hbase(main)> describe 't1' |
5)修改表結(jié)構(gòu)
修改表結(jié)構(gòu)必須先disable
| # 語(yǔ)法: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' |
1)分配權(quán)限
| # 語(yǔ)法 : grant <user> <permissions> <table> <column family> <column qualifier> 參數(shù)后面用逗號(hào)分隔 # 權(quán)限用五個(gè)字母表示: "RWXCA". # READ('R'), WRITE('W'), EXEC('X'), CREATE('C'), ADMIN('A') # 例如,給用戶‘test'分配對(duì)表t1有讀寫的權(quán)限, hbase(main)> grant 'test','RW','t1' |
2)查看權(quán)限
| # 語(yǔ)法:user_permission <table> # 例如,查看表t1的權(quán)限列表 hbase(main)> user_permission 't1' |
3)收回權(quán)限
| # 與分配權(quán)限類似,語(yǔ)法:revoke <user> <table> <column family> <column qualifier> # 例如,收回test用戶在表t1上的權(quán)限 hbase(main)> revoke 'test','t1' |
1)添加數(shù)據(jù)
| # 語(yǔ)法: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)查詢某行記錄
| # 語(yǔ)法: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)掃描表
| # 語(yǔ)法:scan <table>, {COLUMNS => [ <family:column>,.... ], LIMIT => num} # 另外,還可以添加STARTROW、TIMERANGE和FITLER等高級(jí)功能 # 例如:掃描表t1的前5條數(shù)據(jù) hbase(main)> scan 't1',{LIMIT=>5} |
c)查詢表中的數(shù)據(jù)行數(shù)
| # 語(yǔ)法:count <table>, {INTERVAL => intervalNum, CACHE => cacheNum} # INTERVAL設(shè)置多少行顯示一次及對(duì)應(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 )刪除行中的某個(gè)列值
| # 語(yǔ)法:delete <table>, <rowkey>,? <family:column> , <timestamp>,必須指定列名 # 例如:刪除表t1,rowkey001中的f1:col1的數(shù)據(jù) hbase(main)> delete 't1','rowkey001','f1:col1' |
注:將刪除改行f1:col1列所有版本的數(shù)據(jù)
b )刪除行
| # 語(yǔ)法:deleteall <table>, <rowkey>,? <family:column> , <timestamp>,可以不指定列名,刪除整行數(shù)據(jù) # 例如:刪除表t1,rowk001的數(shù)據(jù) hbase(main)> deleteall 't1','rowkey001' |
c)刪除表中的所有數(shù)據(jù)
| # 語(yǔ)法: truncate <table> # 其具體過程是:disable table -> drop table -> create table # 例如:刪除表t1的所有數(shù)據(jù) hbase(main)> truncate 't1' |
1)移動(dòng)region
| # 語(yǔ)法: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
| # 語(yǔ)法:balance_switch true|false hbase(main)> balance_switch |
3)手動(dòng)split
| # 語(yǔ)法:split 'regionName', 'splitKey' |
4)手動(dòng)觸發(fā)major compaction
| #語(yǔ)法: #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' |
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" #啟動(dòng): 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 |
?
轉(zhuǎn)載于:https://www.cnblogs.com/yjd_hycf_space/p/6930737.html
總結(jié)
以上是生活随笔為你收集整理的HBase shell 命令。的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 历史上魏忠贤是好人还是坏人(专家评价魏忠
- 下一篇: 关于collectionview布局的坑