一、進入hbase shell consolenode
$HBASE_HOME/bin/hbase shell #若是有kerberos認證,須要事先使用相應的keytab進行一下認證(使用kinit命令),認證成功以後再使用hbase shell進入可使用whoami命令可查看當前用戶。
hbase(main)> whoami
二、表的管理linux
1)查看有哪些表
hbase(main)> list 2)建立表 # 語法:create <table>, {NAME => <family>, VERSIONS => <VERSIONS>} # 例如:建立表t1,有兩個family name:f1,f2,且版本數均爲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)查看錶的結構 # 語法:describe <table> # 例如:查看錶t1的結構
hbase(main)> describe 't1' 5)修改表結構 修改表結構必須先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'
三、權限管理shell
1)分配權限 # 語法 : grant <user> <permissions> <table> <column family> <column qualifier> 參數後面用逗號分隔 # 權限用五個字母表示: "RWXCA". # READ('R'), WRITE('W'), EXEC('X'), CREATE('C'), ADMIN('A') # 例如,給用戶‘test'分配對錶t1有讀寫的權限,
hbase(main)> grant 'test','RW','t1' 2)查看權限 # 語法:user_permission <table> # 例如,查看錶t1的權限列表
hbase(main)> user_permission 't1' 3)收回權限 # 與分配權限相似,語法:revoke <user> <table> <column family> <column qualifier> # 例如,收回test用戶在表t1上的權限
hbase(main)> revoke 'test','t1'
四、表數據的增刪改查緩存
1)添加數據 # 語法:put <table>,<rowkey>,<family:column>,<value>,<timestamp> # 例如:給表t1的添加一行記錄:rowkey是rowkey001,family name:f1,column name:col1,value:value01,timestamp:系統默認
hbase(main)> put 't1','rowkey001','f1:col1','value01' #用法比較單一。
2)查詢數據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條數據
hbase(main)> scan 't1',{LIMIT=>5} c)查詢表中的數據行數 # 語法:count <table>, {INTERVAL => intervalNum, CACHE => cacheNum} # INTERVAL設置多少行顯示一次及對應的rowkey,默認1000;CACHE每次去取的緩存區大小,默認是10,調整該參數可提升查詢速度 # 例如,查詢表t1中的行數,每100條顯示一次,緩存區爲500
hbase(main)> count 't1', {INTERVAL => 100, CACHE => 500} 3)刪除數據a)刪除行中的某個列值 # 語法:delete <table>, <rowkey>, <family:column> , <timestamp>,必須指定列名 # 例如:刪除表t1,rowkey001中的f1:col1的數據
hbase(main)> delete 't1','rowkey001','f1:col1' 注:將刪除改行f1:col1列全部版本的數據 b)刪除行 # 語法:deleteall <table>, <rowkey>, <family:column> , <timestamp>,能夠不指定列名,刪除整行數據 # 例如:刪除表t1,rowk001的數據
hbase(main)> deleteall 't1','rowkey001' c)刪除表中的全部數據 # 語法: truncate <table> # 其具體過程是:disable table -> drop table -> create table # 例如:刪除表t1的全部數據
hbase(main)> truncate 't1'
五、Region管理ssh
1)移動region # 語法:move 'encodeRegionName', 'ServerName' # encodeRegionName指的regioName後面的編碼,ServerName指的是master-status的Region Servers列表 # 示例
hbase(main)>move '4343995a58be8e5bbc739af1e91cd72d', 'db-41.xxx.xxx.org,60020,1390274516739' 2)開啓/關閉region # 語法:balance_switch true|false
hbase(main)> balance_switch 3)手動split # 語法:split 'regionName', 'splitKey'
4)手動觸發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'
六、配置管理及節點重啓oop
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 # 關閉:
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
七、坑坑坑,Hbase shell退格鍵很差使。編碼
用Xshell登錄linux主機後,在hbase shell下死活不能使用backspace和delete刪除誤輸的指令,只得不停退出,重登,仔細輸。。又錯了,再退出,再登,仔細輸。。。又錯了。。。又錯了。。。。。又錯了。。。。。。。悲劇。。。。。spa
摸索了一下,在File->Properties->Terminal->Keyboard下,把DELETE/BACKSPACE key sequence選爲ASCII 127(Ctrl+?)。這樣在hbase shell下,DELETE/BACKSPACE終於聽使喚了。debug