進入hbase shell console
$HBASE_HOME/bin/hbase shell
如果有kerberos認證,需要事先使用相應的keytab進行一下認證(使用kinit命令),認證成功之後再使用hbase shell進入可以使用whoami命令可檢視當前使用者
hbase(main)> whoami
表的管理
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}
分兩步:首先disable,然後drop
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"
許可權管理
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}
# 語法:delete <table>, <rowkey>, <family:column> , <timestamp>,必須指定列名
hbase(main)> delete "t1","rowkey001","f1:col1"
hbase(main)> deleteall "t1","rowkey001"
# 語法: truncate <table>
# 其具體過程是:disable table -> drop table -> create table
hbase(main)> truncate "t1"
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)開啟/關閉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"
配置管理及節點重啟
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 console
$HBASE_HOME/bin/hbase shell
如果有kerberos認證,需要事先使用相應的keytab進行一下認證(使用kinit命令),認證成功之後再使用hbase shell進入可以使用whoami命令可檢視當前使用者
hbase(main)> whoami
表的管理
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}
分兩步:首先disable,然後drop
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"
許可權管理
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}
# 語法:delete <table>, <rowkey>, <family:column> , <timestamp>,必須指定列名
hbase(main)> delete "t1","rowkey001","f1:col1"
hbase(main)> deleteall "t1","rowkey001"
# 語法: truncate <table>
# 其具體過程是:disable table -> drop table -> create table
hbase(main)> truncate "t1"
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)開啟/關閉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"
配置管理及節點重啟
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