HBASE 安装使用

下载

hbase所有版本下载地址

https://www.apache.org/dyn/closer.lua/hbase/2.2.0/hbase-2.2.0-bin.tar.gz

http://mirror.bit.edu.cn/apache/hbase/2.2.0/hbase-2.2.0-bin.tar.gz

http://mirrors.tuna.tsinghua.edu.cn/apache/hbase/2.2.0/hbase-2.2.0-bin.tar.gz

下载完解压

配置

修改 bin/hbase-env.sh 文件

设置JAVA_HOME export JAVA_HOME=/Library/Java/JavaVirtualMachines/jdk1.8.0_211.jdk/Contents/Home/

修改 bin/hbase-site.xml 文件

<configuration>
    <property>
        <name>hbase.rootdir</name>
        <value>file:///Users/weikeqin1/SoftWare/hbase-2.2.0/data</value>
    </property>
    <property>
        <name>hbase.zookeeper.property.dataDir</name>
        <value>/Users/weikeqin1/SoftWare/hbase-2.2.0/data_zookeeper</value>
    </property>
    <!-- use localhost zookeeper -->
    <property>
        <name>hbase.zookeeper.quorum</name>
        <value>localhost</value>
    </property>
    <property>
        <name>hbase.cluster.distributed</name>
        <value>true</value>
    </property>
</configuration>

启动hbase ./bin/start-hbase.sh

ZBMAC-C02PGMT0F:bin weikeqin1$ ./start-hbase.sh
running master, logging to /Users/weikeqin1/SoftWare/hbase-2.2.0/bin/../logs/hbase-weikeqin1-master-ZBMAC-C02PGMT0F.local.out

验证是否启动成功 jps -l

找到 pid org.apache.hadoop.hbase.master.HMaster 说明启动成功,也可以用 ./hbase shell 验证

hbase 语句

查看所有命名空间

list_namespace

创建命名空间

create_namespace 'ns_h'

查看所有表

list

查看指定命名空间下的表

list_namespace_tables 'ns_h'

新建表

create 'ns_h:user_xyj', 'cf1', 'cf2'
新建一个以命名空间ns_h的表 user_xyj,列族为cf1,cf2。

删除表

disable 'ns_h:user_xyj'
drop 'ns_h:user_xyj'

查看表内容

scan 'ns_h:user_xyj', {LIMIT=>5} 查看前5行数据

插入

put 'namespace:table1', 'rowkey_1', 'cf1:field1', 'field1_value'

put 'ns_h:user_xyj','rowkey_1','cf1:name','孙悟空'
put 'ns_h:user_xyj','rowkey_1','cf1:sex','男'
put 'ns_h:user_xyj','rowkey_1','cf1:age','18'
put 'ns_h:user_xyj','rowkey_1','cf2:address','北京市朝阳区'

hbase shell

ZBMAC-C02PGMT0F:bin weikeqin1$ ./hbase shell
2019-07-26 18:35:23,037 WARN  [main] util.NativeCodeLoader: Unable to load native-hadoop library for your platform... using builtin-java classes where applicable
HBase Shell
Use "help" to get list of supported commands.
Use "exit" to quit this interactive shell.
For Reference, please visit: http://hbase.apache.org/2.0/book.html#shell
Version 2.2.0, rUnknown, Tue Jun 11 04:30:30 UTC 2019
Took 0.0038 seconds
hbase(main):001:0> help
HBase Shell, version 2.2.0, rUnknown, Tue Jun 11 04:30:30 UTC 2019
Type 'help "COMMAND"', (e.g. 'help "get"' -- the quotes are necessary) for help on a specific command.
Commands are grouped. Type 'help "COMMAND_GROUP"', (e.g. 'help "general"') for help on a command group.

COMMAND GROUPS:
  Group name: general
  Commands: processlist, status, table_help, version, whoami

  Group name: ddl
  Commands: alter, alter_async, alter_status, clone_table_schema, create, describe, disable, disable_all, drop, drop_all, enable, enable_all, exists, get_table, is_disabled, is_enabled, list, list_regions, locate_region, show_filters

  Group name: namespace
  Commands: alter_namespace, create_namespace, describe_namespace, drop_namespace, list_namespace, list_namespace_tables

  Group name: dml
  Commands: append, count, delete, deleteall, get, get_counter, get_splits, incr, put, scan, truncate, truncate_preserve

  Group name: tools
  Commands: assign, balance_switch, balancer, balancer_enabled, catalogjanitor_enabled, catalogjanitor_run, catalogjanitor_switch, cleaner_chore_enabled, cleaner_chore_run, cleaner_chore_switch, clear_block_cache, clear_compaction_queues, clear_deadservers, close_region, compact, compact_rs, compaction_state, compaction_switch, decommission_regionservers, flush, is_in_maintenance_mode, list_deadservers, list_decommissioned_regionservers, major_compact, merge_region, move, normalize, normalizer_enabled, normalizer_switch, recommission_regionserver, rit, split, splitormerge_enabled, splitormerge_switch, stop_master, stop_regionserver, trace, unassign, wal_roll, zk_dump

  Group name: replication
  Commands: add_peer, append_peer_exclude_namespaces, append_peer_exclude_tableCFs, append_peer_namespaces, append_peer_tableCFs, disable_peer, disable_table_replication, enable_peer, enable_table_replication, get_peer_config, list_peer_configs, list_peers, list_replicated_tables, remove_peer, remove_peer_exclude_namespaces, remove_peer_exclude_tableCFs, remove_peer_namespaces, remove_peer_tableCFs, set_peer_bandwidth, set_peer_exclude_namespaces, set_peer_exclude_tableCFs, set_peer_namespaces, set_peer_replicate_all, set_peer_serial, set_peer_tableCFs, show_peer_tableCFs, update_peer_config

  Group name: snapshots
  Commands: clone_snapshot, delete_all_snapshot, delete_snapshot, delete_table_snapshots, list_snapshots, list_table_snapshots, restore_snapshot, snapshot

  Group name: configuration
  Commands: update_all_config, update_config

  Group name: quotas
  Commands: disable_exceed_throttle_quota, disable_rpc_throttle, enable_exceed_throttle_quota, enable_rpc_throttle, list_quota_snapshots, list_quota_table_sizes, list_quotas, list_snapshot_sizes, set_quota

  Group name: security
  Commands: grant, list_security_capabilities, revoke, user_permission

  Group name: procedures
  Commands: list_locks, list_procedures

  Group name: visibility labels
  Commands: add_labels, clear_auths, get_auths, list_labels, set_auths, set_visibility

  Group name: rsgroup
  Commands: add_rsgroup, balance_rsgroup, get_rsgroup, get_server_rsgroup, get_table_rsgroup, list_rsgroups, move_namespaces_rsgroup, move_servers_namespaces_rsgroup, move_servers_rsgroup, move_servers_tables_rsgroup, move_tables_rsgroup, remove_rsgroup, remove_servers_rsgroup

SHELL USAGE:
Quote all names in HBase Shell such as table and column names.  Commas delimit
command parameters.  Type <RETURN> after entering a command to run it.
Dictionaries of configuration used in the creation and alteration of tables are
Ruby Hashes. They look like this:

  {'key1' => 'value1', 'key2' => 'value2', ...}

and are opened and closed with curley-braces.  Key/values are delimited by the
'=>' character combination.  Usually keys are predefined constants such as
NAME, VERSIONS, COMPRESSION, etc.  Constants do not need to be quoted.  Type
'Object.constants' to see a (messy) list of all constants in the environment.

If you are using binary keys or values and need to enter them in the shell, use
double-quote'd hexadecimal representation. For example:

  hbase> get 't1', "key\x03\x3f\xcd"
  hbase> get 't1', "key\003\023\011"
  hbase> put 't1', "test\xef\xff", 'f1:', "\x01\x33\x40"

The HBase shell is the (J)Ruby IRB with the above HBase-specific commands added.
For more on the HBase Shell, see http://hbase.apache.org/book.html
hbase(main):002:0> exit
ZBMAC-C02PGMT0F:bin weikeqin1$

创建表

hbase(main):001:0> create 'student', 'description', 'course'
Created table student
Took 1.3820 seconds
=> Hbase::Table - student
hbase(main):002:0>

信息明细

hbase(main):003:0* list 'student'
TABLE
student
1 row(s)
Took 0.0411 seconds
=> ["student"]
hbase(main):004:0>
hbase(main):005:0* list student
NameError: undefined local variable or method `student' for main:Object
hbase(main):007:0* put 'student', 'row1', 'descroption:age', '18'

ERROR: org.apache.hadoop.hbase.regionserver.NoSuchColumnFamilyException: Column family descroption does not exist in region student,,1564137475186.c45878edd2192b0caaac80b33c2f8915. in table 'student', {NAME => 'course', VERSIONS => '1', EVICT_BLOCKS_ON_CLOSE => 'false', NEW_VERSION_BEHAVIOR => 'false', KEEP_DELETED_CELLS => 'FALSE', CACHE_DATA_ON_WRITE => 'false', DATA_BLOCK_ENCODING => 'NONE', TTL => 'FOREVER', MIN_VERSIONS => '0', REPLICATION_SCOPE => '0', BLOOMFILTER => 'ROW', CACHE_INDEX_ON_WRITE => 'false', IN_MEMORY => 'false', CACHE_BLOOMS_ON_WRITE => 'false', PREFETCH_BLOCKS_ON_OPEN => 'false', COMPRESSION => 'NONE', BLOCKCACHE => 'true', BLOCKSIZE => '65536'}, {NAME => 'description', VERSIONS => '1', EVICT_BLOCKS_ON_CLOSE => 'false', NEW_VERSION_BEHAVIOR => 'false', KEEP_DELETED_CELLS => 'FALSE', CACHE_DATA_ON_WRITE => 'false', DATA_BLOCK_ENCODING => 'NONE', TTL => 'FOREVER', MIN_VERSIONS => '0', REPLICATION_SCOPE => '0', BLOOMFILTER => 'ROW', CACHE_INDEX_ON_WRITE => 'false', IN_MEMORY => 'false', CACHE_BLOOMS_ON_WRITE => 'false', PREFETCH_BLOCKS_ON_OPEN => 'false', COMPRESSION => 'NONE', BLOCKCACHE => 'true', BLOCKSIZE => '65536'}
	at org.apache.hadoop.hbase.regionserver.HRegion.doBatchMutate(HRegion.java:4308)
	at org.apache.hadoop.hbase.regionserver.HRegion.put(HRegion.java:3096)
	at org.apache.hadoop.hbase.regionserver.RSRpcServices.mutate(RSRpcServices.java:2870)
	at org.apache.hadoop.hbase.shaded.protobuf.generated.ClientProtos$ClientService$2.callBlockingMethod(ClientProtos.java:42000)
	at org.apache.hadoop.hbase.ipc.RpcServer.call(RpcServer.java:413)
	at org.apache.hadoop.hbase.ipc.CallRunner.run(CallRunner.java:132)
	at org.apache.hadoop.hbase.ipc.RpcExecutor$Handler.run(RpcExecutor.java:324)
	at org.apache.hadoop.hbase.ipc.RpcExecutor$Handler.run(RpcExecutor.java:304)

For usage try 'help "put"'

Took 0.4988 seconds
hbase(main):008:0> put 'student', 'row1', 'description:age', '18'
Took 0.0229 seconds
hbase(main):009:0>
hbase(main):010:0* put 'student', 'row1', 'description:name', 'liu'
Took 0.0127 seconds
hbase(main):011:0> put 'student', 'row1', 'course:chinese', '100'

References

[1] Mac下安装HBase及详解