Hbase的访问方式
1、Native Java API:最常规和高效的访问方式;
2、HBase Shell:HBase的命令行工具,最简单的接口,适合HBase管理使用;
3、Thrift Gateway:利用Thrift序列化技术,支持C++,PHP,Python等多种语言,适合其他异构系统在线访问HBase表数据;
4、REST Gateway:支持REST 风格的Http API访问HBase, 解除了语言限制;
5、MapReduce:直接使用MapReduce作业处理Hbase数据;
6、使用Pig/hive处理Hbase数据。
Hbase shell基本用法
hbase shell 的help对语法的介绍很全,搞明白help上的实例,对hbase shell的操作就很熟练了。
hbase shell 的操作分为 10类,本文只介绍前4类,分别是:
Group name | commands |
---|---|
general | status, table_help, version, whoami |
ddl | alter, alter_async, alter_status, create, describe, disable, disable_all, drop, drop_all, enable, enable_all, exists, get_table, is_disabled, is_enabled, list, show_filters |
namespace | alter_namespace, create_namespace, describe_namespace, drop_namespace, list_namespace, list_namespace_tables |
dml | append, count, delete, deleteall, get, get_counter, incr, put, scan, truncate, truncate_preserve |
tools | assign, balance_switch, balancer, catalogjanitor_enabled, catalogjanitor_run, catalogjanitor_switch, close_region, compact, compact_rs, flush, major_compact, merge_region, move, split, trace, unassign, wal_roll, zk_dump |
replication | add_peer, append_peer_tableCFs, disable_peer, disable_table_replication, enable_peer, enable_table_replication, list_peers, list_replicated_tables, remove_peer, remove_peer_tableCFs, set_peer_tableCFs, show_peer_tableCFs |
snapshots | clone_snapshot, delete_all_snapshot, delete_snapshot, list_snapshots, restore_snapshot, snapshot |
configuration | update_all_config, update_config |
security | grant, revoke, user_permission |
visibility labels | add_labels, clear_auths, get_auths, list_labels, set_auths, set_visibility |
Hbase shell 命令具体介绍
general
status
作用:查询当前服务器状态。
实例:
hbase(main):006:0> status
1 servers, 0 dead, 5.0000 average load
更多用法:
hbase(main):002:0> help 'status'
hbase> status
hbase> status 'simple'
hbase> status 'summary'
hbase> status 'detailed'
hbase> status 'replication'
hbase> status 'replication', 'source'
hbase> status 'replication', 'sink'
version
作用:查看hbase版本
实例:
hbase(main):010:0> version
1.0.3, rf1e1312f9790a7c40f6a4b5a1bab2ea1dd559890, Tue Jan 19 19:26:53 PST 2016
whoami
作用:查询当前hbase用户
实例:
hbase(main):011:0> whoami
datanode1 (auth:SIMPLE)
groups: datanode1
ddl
create
作用:创建一个表
实例:
#在命名空间ns1下,创建表t1,其中有一个列族f1,f1的版本数为5
hbase> create 'ns1:t1', {NAME => 'f1', VERSIONS => 5}
#在默认命名空间下,创建表t1,有三个列族f1,f2,f3
hbase> create 't1', {NAME => 'f1'}, {NAME => 'f2'}, {NAME => 'f3'}
#等价于
hbase> create 't1', 'f1', 'f2', 'f3'
#创建表t1,列族f1,并设置f1的版本数为1,属性TTL为2592000,属性BLOCKCACHE为true。属性的含义在这就不解释了。
hbase> create 't1', {NAME => 'f1', VERSIONS => 1, TTL => 2592000, BLOCKCACHE => true}
# 创建表t1,列族f1,并设置f1的配置hbase.hstore.blockingStoreFiles 为 10
hbase> create 't1', {NAME => 'f1', CONFIGURATION => {
'hbase.hstore.blockingStoreFiles' => '10'}}
#创建表时,配置信息可以放在最后,例如:
hbase> create 'ns1:t1', 'f1', SPLITS => ['10',