HBbase单机快速入门环境搭建

来源:互联网 发布:qq显示网络状态准确吗 编辑:程序博客网 时间:2024/05/29 14:48

下载解压最新版本

HBase下载地址 :http://archive.apache.org/dist/hbase/ 点击stable目录选择不同版本,然后下载后缀为 .tar.gz 的文件; 例如 hbase-0.98.9-hadoop2-bin.tar.gz,解压缩,然后解压到指定的目录.

# tar -zxvf hbase-0.98.9-hadoop2-bin.tar.gz -C /usr/local

- jdk1.6以上版本配置

如果你在命令行键入java有反应说明你安装了Java。如果没有装,你需要先安装,然后编辑conf/hbase-env.sh,将其中的JAVA_HOME指向到你Java的安装目录。

# vi conf/hbase-env.sh

这里写图片描述

- 去配置hbase.rootdir

编辑 conf/hbase-site.xml 去配置hbase.rootdir,来选择HBase将数据写到哪个目录 将 DIRECTORY 替换成你期望写文件的目录. 默认 hbase.rootdir 是指向 /tmp/hbase-${user.name} ,也就说你会在重启后丢失数据(重启的时候操作系统会清理/tmp目录)

# vi conf/hbase-site.xml

这里写图片描述

- 启动 HBase

# ./bin/start-hbase.shstarting Master, logging to logs/hbase-user-master-example.org.out
  • 客户端访问结果

这里写图片描述

- 用shell连接你的HBase

# ./bin/hbase shellHBase Shell; enter 'help<RETURN>' for list of supported commands.Type "exit<RETURN>" to leave the HBase ShellVersion: 0.90.0, r1001068, Fri Sep 24 13:55:42 PDT 2010hbase(main):001:0>
  • 输入 help 然后 可以看到一列shell命令。这里的帮助很详细,要注意的是表名,行和列需要加引号。
hbase(main):001:0> helpHBase Shell, version 0.98.9-hadoop2, r96878ece501b0643e879254645d7f3a40eaf101f, Mon Dec 15 23:00:20 PST 2014Type '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: status, table_help, version, whoami  Group name: ddl  Commands: 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  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, incr, put, scan, truncate, truncate_preserve  Group name: tools  Commands: assign, balance_switch, balancer, catalogjanitor_enabled, catalogjanitor_run, catalogjanitor_switch, close_region, compact, compact_rs, flush, hlog_roll, major_compact, merge_region, move, split, trace, unassign, zk_dump  Group name: replication  Commands: add_peer, disable_peer, enable_peer, list_peers, list_replicated_tables, remove_peer, set_peer_tableCFs, show_peer_tableCFs  Group name: snapshots  Commands: clone_snapshot, delete_all_snapshot, delete_snapshot, list_snapshots, restore_snapshot, snapshot  Group name: security  Commands: grant, revoke, user_permission  Group name: visibility labels  Commands: add_labels, clear_auths, get_auths, list_labels, set_auths, set_visibilitySHELL USAGE:Quote all names in HBase Shell such as table and column names.  Commas delimitcommand parameters.  Type <RETURN> after entering a command to run it.Dictionaries of configuration used in the creation and alteration of tables areRuby 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 asNAME, 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, usedouble-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.htm
  • 创建一个名为 test 的表,这个表只有一个 列族 为 cf。可以列出所有的表来检查创建情况,然后插入些值
hbase(main):003:0> create 'test', 'cf'0 row(s) in 1.2200 secondshbase(main):003:0> list 'table'test1 row(s) in 0.0550 seconds
  • 分别插入了3行。第一个行key为row1, 列为 cf:a, 值是 value1。HBase中的列是由 列族前缀和列的名字组成的,以冒号间隔。例如这一行的列名就是a.
hbase(main):004:0> put 'test', 'row1', 'cf:a', 'value1'0 row(s) in 0.0560 secondshbase(main):005:0> put 'test', 'row2', 'cf:b', 'value2'0 row(s) in 0.0370 secondshbase(main):006:0> put 'test', 'row3', 'cf:c', 'value3'0 row(s) in 0.0450 seconds
  • 检查插入情况.
hbase(main):007:0> scan 'test'ROW        COLUMN+CELLrow1       column=cf:a, timestamp=1288380727188, value=value1row2       column=cf:b, timestamp=1288380738440, value=value2row3       column=cf:c, timestamp=1288380747365, value=value33 row(s) in 0.0590 seconds
  • Get一行,操作如下
hbase(main):008:0> get 'test', 'row1'COLUMN      CELLcf:a        timestamp=1288380727188, value=value11 row(s) in 0.0400 seconds
  • disable 再 drop 这张表,可以清除你刚刚的操作
hbase(main):012:0> disable 'test'0 row(s) in 1.0930 secondshbase(main):013:0> drop 'test'0 row(s) in 0.0770 seconds 
  • 关闭shell,用exit/quit
hbase(main):014:0> exit
  • 运行停止脚本来停止HBase.
# ./bin/stop-hbase.shstopping hbase...............
原创粉丝点击