转载请注明出处:http://blog.csdn.net/dongdong9223/article/details/86493197
本文出自【我是干勾鱼的博客】
Ingredients:
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”问题的解决这篇文章。
参考Linux下安装JDK并修改环境变量。
安装Hadoop是为了使用HDFS作为存储,其实HBase的standlone版本不一定非要安装Hadoop,因为也可以将数据存储在本地。这里还是安装并启动Hadoop,具体方法可参见阿里云ECS上搭建Hadoop集群环境——使用两台ECS服务器搭建“Cluster mode”的Hadoop集群环境。
wget -c http://mirrors.hust.edu.cn/apache/hbase/2.1.2/hbase-2.1.2-bin.tar.gz
将文件存放在:
/opt/hive/
目录下并解压缩。
[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”问题的解决中查看到为什么要添加这段内容。
cp lib/client-facing-thirdparty/htrace-core-3.1.0-incubating.jar lib/
使用:
./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>
hbase(main):008:0* create 'test', 'cf'
Created table test
Took 2.0486 seconds
=> Hbase::Table - test
hbase(main):016:0> list 'test'
TABLE
test
1 row(s)
Took 0.0112 seconds
=> ["test"]
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
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
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
hbase(main):028:0> get 'test', 'row1'
COLUMN CELL
cf:a timestamp=1547628023826, value=value1
1 row(s)
Took 0.0285 seconds
hbase(main):029:0> disable 'test'
Took 1.2997 seconds
hbase(main):030:0> enable 'test'
Took 0.7685 seconds
删除表需要先disable,然后再drop:
hbase(main):032:0> disable 'test'
Took 0.4358 seconds
hbase(main):033:0> drop 'test'
Took 0.4588 seconds
hbase(main):034:0> quit
tail -f logs/hbase-root-master-shizhi002.log
[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]
Apache HBase ™ Reference Guide
HBase官网中对Hadoop版本的要求
玉女心经HBase——启动HBase报错“java.lang.NoClassDefFoundError: org/apache/htrace/SamplerBuilder”问题的解决
HBase安装