玉女心经HBase——HBase安装及简单使用

转载请注明出处:http://blog.csdn.net/dongdong9223/article/details/86493197
本文出自【我是干勾鱼的博客】

Ingredients:

Language

  • Java:Java SE Development Kit 8u162(Oracle Java Archive),Linux下安装JDK并修改环境变量

  • Hadoop:hadoop-2.9.1.tar.gz(Apache Hadoop Releases Downloads, All previous releases of Hadoop are available from the Apache release archive site)

  • HBase:hbase-2.1.2-bin.tar.gz(mirrors.tuna.tsinghua.edu.cn,Downloads,Apache HBASE Mirrors),Apache HBase ™ Reference Guide

注意!先说明一下! HBase对版本的要求非常苛刻,可参考HBase官网中对Hadoop版本的要求,在安装之前要看一下玉女心经HBase——启动HBase报错“java.lang.NoClassDefFoundError: org/apache/htrace/SamplerBuilder”问题的解决这篇文章。

安装HBASE之前的准备

1.1 安装JAVA

参考Linux下安装JDK并修改环境变量。

1.2 安装并启动Hadoop

安装Hadoop是为了使用HDFS作为存储,其实HBase的standlone版本不一定非要安装Hadoop,因为也可以将数据存储在本地。这里还是安装并启动Hadoop,具体方法可参见阿里云ECS上搭建Hadoop集群环境——使用两台ECS服务器搭建“Cluster mode”的Hadoop集群环境。

2 下载HBase

wget -c http://mirrors.hust.edu.cn/apache/hbase/2.1.2/hbase-2.1.2-bin.tar.gz

3 解压缩

将文件存放在:

/opt/hive/

目录下并解压缩。

4 配置

4.1 编辑hbase-site.xml

[root@shizhi002 hbase-2.1.2]# vi conf/hbase-site.xml

加入内容如下:

<configuration>
<property>
    <name>hbase.rootdirname>
    <value>hdfs://shizhi002:9000/tmp/hbasevalue>
  property>
  <property>
    <name>hbase.zookeeper.property.dataDirname>
    <value>hdfs://shizhi002:9000/tmp/zookeepervalue>
  property>
  <property>
    <name>hbase.unsafe.stream.capability.enforcename>
    <value>falsevalue>
    <description>
      Controls whether HBase will check for stream capabilities (hflush/hsync).

      Disable this if you intend to run on LocalFileSystem, denoted by a rootdir
      with the 'file://' scheme, but be mindful of the NOTE below.

      WARNING: Setting this to false blinds you to potential data loss and
      inconsistent system state in the event of process and/or node failures. If
      HBase is complaining of an inability to use hsync or hflush it's most
      likely not a false positive.
    description>
  property>

        <property>
                <name>hbase.wal.providername>
                <value>filesystemvalue>
        property>
configuration>

这些内容可以在Apache HBase ™ Reference Guide中找到。

而最后那部分:

<property>
	<name>hbase.wal.providername>
	<value>filesystemvalue>
property>

可以在玉女心经HBase——启动HBase报错“java.lang.NoClassDefFoundError: org/apache/htrace/SamplerBuilder”问题的解决中查看到为什么要添加这段内容。

4.2 拷贝jar包

cp lib/client-facing-thirdparty/htrace-core-3.1.0-incubating.jar lib/

5 启动HBase

使用:

./bin/hbase shell

命令启动HBase,如下:

[root@shizhi002 hbase-2.1.2]# ./bin/hbase shell
SLF4J: Class path contains multiple SLF4J bindings.
SLF4J: Found binding in [jar:file:/opt/hadoop/hadoop-2.9.1/share/hadoop/common/lib/slf4j-log4j12-1.7.25.jar!/org/slf4j/impl/StaticLoggerBinder.class]
SLF4J: Found binding in [jar:file:/opt/hbase/hbase-2.1.2/lib/client-facing-thirdparty/slf4j-log4j12-1.7.25.jar!/org/slf4j/impl/StaticLoggerBinder.class]
SLF4J: See http://www.slf4j.org/codes.html#multiple_bindings for an explanation.
SLF4J: Actual binding is of type [org.slf4j.impl.Log4jLoggerFactory]
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.1.2, r1dfc418f77801fbfb59a125756891b9100c1fc6d, Sun Dec 30 21:45:09 PST 2018
Took 0.0040 seconds                                                             
hbase(main):001:0> 

6 数据表操作命令

6.1 创建表

hbase(main):008:0* create 'test', 'cf'
Created table test
Took 2.0486 seconds                                                             
=> Hbase::Table - test

6.2 查看:

hbase(main):016:0> list 'test'
TABLE                                                                           
test                                                                            
1 row(s)
Took 0.0112 seconds                                                             
=> ["test"]

6.3 查勘表的详细信息:

hbase(main):017:0> describe 'test'
Table test is ENABLED                                                           
test                                                                            
COLUMN FAMILIES DESCRIPTION                                                     
{NAME => 'cf', VERSIONS => '1', EVICT_BLOCKS_ON_CLOSE => 'false', NEW_VERSION_BE
HAVIOR => 'false', KEEP_DELETED_CELLS => 'FALSE', CACHE_DATA_ON_WRITE => 'false'
, DATA_BLOCK_ENCODING => 'NONE', TTL => 'FOREVER', MIN_VERSIONS => '0', REPLICAT
ION_SCOPE => '0', BLOOMFILTER => 'ROW', CACHE_INDEX_ON_WRITE => 'false', IN_MEMO
RY => 'false', CACHE_BLOOMS_ON_WRITE => 'false', PREFETCH_BLOCKS_ON_OPEN => 'fal
se', COMPRESSION => 'NONE', BLOCKCACHE => 'true', BLOCKSIZE => '65536'}         
1 row(s)
Took 0.2028 seconds

6.4 插入数据:

hbase(main):018:0> put 'test', 'row1', 'cf:a', 'value1'
Took 0.1470 seconds                                                             
hbase(main):019:0> put 'test', 'row2', 'cf:b', 'value2'
Took 0.0090 seconds                                                             
hbase(main):022:0> put 'test', 'row3', 'cf:c', 'value3'
Took 0.0044 seconds                                                             

6.5 扫描表的所有数据:

hbase(main):027:0> scan 'test'
ROW                   COLUMN+CELL                                               
 row1                 column=cf:a, timestamp=1547628023826, value=value1        
 row2                 column=cf:b, timestamp=1547628044143, value=value2        
 row3                 column=cf:c, timestamp=1547628090918, value=value3        
3 row(s)
Took 0.0311 seconds

6.6 获得某1行的数据:

hbase(main):028:0> get 'test', 'row1'
COLUMN                CELL                                                      
 cf:a                 timestamp=1547628023826, value=value1                     
1 row(s)
Took 0.0285 seconds 

6.7 disable数据表:

hbase(main):029:0> disable 'test'
Took 1.2997 seconds

6.8 enable数据表:

hbase(main):030:0> enable 'test'
Took 0.7685 seconds

6.9 删除表:

删除表需要先disable,然后再drop:

hbase(main):032:0> disable 'test'
Took 0.4358 seconds                                                             
hbase(main):033:0> drop 'test'
Took 0.4588 seconds 

7 退出HBase shell

hbase(main):034:0> quit

8 监控log

tail -f logs/hbase-root-master-shizhi002.log 

9 关闭HBase

[root@shizhi002 hbase-2.1.2]# ./bin/stop-hbase.sh 
stopping hbase..............
SLF4J: Class path contains multiple SLF4J bindings.
SLF4J: Found binding in [jar:file:/opt/hadoop/hadoop-2.9.1/share/hadoop/common/lib/slf4j-log4j12-1.7.25.jar!/org/slf4j/impl/StaticLoggerBinder.class]
SLF4J: Found binding in [jar:file:/opt/hbase/hbase-2.1.2/lib/client-facing-thirdparty/slf4j-log4j12-1.7.25.jar!/org/slf4j/impl/StaticLoggerBinder.class]
SLF4J: See http://www.slf4j.org/codes.html#multiple_bindings for an explanation.
SLF4J: Actual binding is of type [org.slf4j.impl.Log4jLoggerFactory]

10 参考

Apache HBase ™ Reference Guide

HBase官网中对Hadoop版本的要求

玉女心经HBase——启动HBase报错“java.lang.NoClassDefFoundError: org/apache/htrace/SamplerBuilder”问题的解决

HBase安装

你可能感兴趣的:(HBase)