Hbase-之hbase shell使用(预分区…)
1 hbase shell入门
- 最简单的入门进入交互式界面
cd /hbase-2.4.2
./bin/hbase shell
常用的hbase shell练习可以参考 hbase shell 练习
# 查看hbase shell指南
help
# 创建table test
create 'test','cf'
# 列出table,判断是否存在list
list 'test'
# 描述表的信息
describe 'test'
# put数据进table
put 'test','rowkey1','cf:id','1'
put 'test','rowkey2','cf:name','bob'
#scan扫描表
scan 'test'
# get一行数据
get 'test','rowkey1'
#禁用/启用table
disable 'test'
enable 'test'
# drop table
drop 'test'
# 退出交互式hbase shell
quit
stopping hbase....................
# 使用hbase shell的计数命令count,每次抓取1000行
count 'test' ,CACHE => 1000
2 使用hbase shell的非交互式模式
hbase的非交互式模式与hive的hive -e/-f
一样
./bin/hbase shell -n or --non-interactive
2.1 将系统shell脚本结合hbase shell使用
#实际上 describe 'test'可以换成其它任何hbase shell命令
echo "describe 'test'" | hbase shell -n
3 动态配置JVM选项启动hbase shell
HBASE_SHELL_OPTS="-verbose:gc -XX:+PrintGCApplicationStoppedTime -XX:+PrintGCDateStamps \
-XX:+PrintGCDetails -Xloggc:$HBASE_HOME/logs/gc-hbase.log" ./bin/hbase shell
4 重写默认配置启动hbase shell
$ ./bin/hbase shell -Dhbase.zookeeper.quorum=ZK0.remote.cluster.example.org,ZK1.remote.cluster.example.org,ZK2.remote.cluster.example.org -Draining=false
...
hbase(main):001:0> @shell.hbase.configuration.get("hbase.zookeeper.quorum")
=> "ZK0.remote.cluster.example.org,ZK1.remote.cluster.example.org,ZK2.remote.cluster.example.org"
hbase(main):002:0> @shell.hbase.configuration.get("raining")
=> "false"
5 通过hbase shell进行region split
5.1 pre-split方式1
#table t1,创建了一个列簇,同时被分成4个region
# <10 \ 10~20 \ 20~30 \ >30
create 't1','cf',SPLITS => ['10','20','30']
5.2 pre-split方式2
vim split.txt
10
20
30
# 每行算作一个region分隔符,左闭右开
hbase>create 't14','f',SPLITS_FILE=>'splits.txt'
5.3 按照Hbase的自带的分区策略进行预分区
# create table with four regions based on random bytes keys
hbase>create 't2','f1', { NUMREGIONS => 4 , SPLITALGO => 'UniformSplit' }
# create table with five regions based on hex keys
hbase>create 't3','f1', { NUMREGIONS => 5, SPLITALGO => 'HexStringSplit' }