hbase 安装笔记

1、安装

在官方镜像站点下载hbase2.0,地址:https://www.apache.org/dyn/closer.lua/hbase/

解压
tar xzvf hbase-2.0.4-bin.tar.gz

设置好JAVA_HOME环境变量,或者直接在hbase的配置文件(conf/hbase-env.sh)里设置JAVA_HOME

设置HBASE_HOME,这个不是必须。

本例是在/etc/profile文件里追加java环境变量,设置后需要source /etc/profile使设置生效,或者重新登录

#set java environment
JAVA_HOME=/home/java/jdk1.8.0_172
JRE_HOME=/home/java/jdk1.8.0_172/jre
CLASS_PATH=.:$JAVA_HOME/lib/dt.jar:$JAVA_HOME/lib/tools.jar:$JRE_HOME/lib
PATH=$PATH:$JAVA_HOME/bin:$JRE_HOME/bin
export JAVA_HOME JRE_HOME CLASS_PATH PATH


#set hbase environment
export HBASE_HOME=/opt/hbase-2.0.4
export PATH=$PATH:$HBASE_HOME/bin

2、配置hbase-site.xml

vi $HBASE_HOME/conf/hbase-site.xml 

<configuration>
  <property>
#hbase的数据目录 <name>hbase.rootdir</name> <value>file:///opt/hbase_data</value> #本例使用本地文件系统,如果是需要把数据存在hdfs上,需配置相应的hdfs目录,例如:hdfs://namenode.example.org:9000/hbase </property> <property> <name>hbase.zookeeper.property.dataDir</name> <value>/opt/hbase_data/zookeeper</value> </property> <property> <name>hbase.unsafe.stream.capability.enforce</name> <value>false</value> </property> </configuration>

3、启动hbase,在standalone模式下hbase所有守护进程都运行在一个JVM里,例如:HMaster、HRegionServer、ZooKeeper daemon等。

执行在hbase的bin目录下的脚本 bin/start-hbase.sh

启动后通过jps可以看到hMaster的进程 [root@bigdata-senior01 ~]# jps 2082 Jps 1523 HMaster

4、进入shell,通过hbase的bin目录下的bin/hbase shell启动

[hadoop@bigdata-senior01 conf]$ hbase shell
SLF4J: Class path contains multiple SLF4J bindings.
SLF4J: Found binding in [jar:file:/opt/hbase-2.0.4/lib/slf4j-log4j12-1.7.25.jar!/org/slf4j/impl/StaticLoggerBinder.class]
SLF4J: Found binding in [jar:file:/opt/hadoop/hadoop-3.2.0/share/hadoop/common/lib/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.0.4, r205e39c5704bf38568b34926dde9f1ee76e6b5d0, Fri Dec 28 22:13:42 PST 2018
Took 0.0220 seconds 

5、检查hbase是否正常

hbase(main):004:0> status
1 active master, 0 backup masters, 1 servers, 0 dead, 2.0000 average load
Took 0.0159 seconds  

5.1、hbase的WEB UI

http://主机:16010

 

6、基本的表操作

6.1、建表

hbase(main):005:0> create 'test','c01f01'
Created table test
Took 0.8601 seconds                                                                                           
=> Hbase::Table - test

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

hbase(main):004:0> desc 'test'
Table test is ENABLED                                                                                         
test                                                                                                          
COLUMN FAMILIES DESCRIPTION                                                                                   
{NAME => 'c01f01', VERSIONS => '1', EVICT_BLOCKS_ON_CLOSE => 'false', NEW_VERSION_BEHAVIOR => 'false', KEEP_DE
LETED_CELLS => 'FALSE', CACHE_DATA_ON_WRITE => 'false', DATA_BLOCK_ENCODING => 'NONE', TTL => 'FOREVER', MIN_V
ERSIONS => '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', BLOCKCAC
HE => 'true', BLOCKSIZE => '65536'}                                                                           
1 row(s)
Took 0.2176 seconds

 6.2、新增数据

hbase(main):005:0> put 'test','row1','c01f01:a','value 1'
Took 0.1123 seconds                                                                                           
hbase(main):006:0> put 'test','row2','c01f01:b','value 2'
Took 0.0090 seconds                                                                                           
hbase(main):007:0> put 'test','row2','c01f01:c','value 3'
Took 0.0350 seconds                                                                                           
hbase(main):008:0> put 'test','row3','c01f01:c','value 4'
Took 0.0090 seconds                                                                                           
hbase(main):009:0> put 'test','row3','c01f01:a','value a4'
Took 0.0162 seconds     
hbase(main):010:0> scan 'test' ROW COLUMN+CELL row1 column=c01f01:a, timestamp=1552814291353, value=value 1 row2 column=c01f01:b, timestamp=1552814331971, value=value 2 row2 column=c01f01:c, timestamp=1552814345885, value=value 3 row3 column=c01f01:a, timestamp=1552814789352, value=value a4 row3 column=c01f01:c, timestamp=1552814492278, value=value 4 3 row(s) Took 0.0371 seconds

6.3、获取行数据

hbase(main):011:0> get 'test','row1'
COLUMN                       CELL                                                                             
 c01f01:a                    timestamp=1552814291353, value=value 1                                           
1 row(s)
Took 0.0313 seconds          
hbase(main):012:0> get 'test','row2' COLUMN CELL c01f01:b timestamp=1552814331971, value=value 2 c01f01:c timestamp=1552814345885, value=value 3 1 row(s) Took 0.0111 seconds

6.4、删除数据

hbase(main):015:0> scan 'test'
ROW                          COLUMN+CELL                                                                      
 row1                        column=c01f01:a, timestamp=1552814291353, value=value 1                          
 row2                        column=c01f01:b, timestamp=1552815215576, value=value b4                         
 row2                        column=c01f01:c, timestamp=1552814345885, value=value 3                          
 row3                        column=c01f01:a, timestamp=1552814789352, value=value a4                         
 row3                        column=c01f01:c, timestamp=1552814492278, value=value 4                          
3 row(s)
Took 0.0151 seconds     
                                                                                      
hbase(main):016:0> delete 'test','row2','c01f01:c'
Took 0.0417 seconds           
                                                                                
hbase(main):017:0> scan 'test'
ROW                          COLUMN+CELL                                                                      
 row1                        column=c01f01:a, timestamp=1552814291353, value=value 1                          
 row2                        column=c01f01:b, timestamp=1552815215576, value=value b4                         
 row3                        column=c01f01:a, timestamp=1552814789352, value=value a4                         
 row3                        column=c01f01:c, timestamp=1552814492278, value=value 4                          
3 row(s)
Took 0.0152 seconds                                                       

 6.5、禁用表

hbase(main):003:0> disable 'test'
Took 0.6266 seconds                   

6.6、删除表

hbase(main):006:0> drop 'test'
Took 0.2697 seconds 

 7、停止hbase

[hadoop@bigdata-senior01 ~]$ stop-hbase.sh
stopping hbase..............

 

posted @ 2019-03-17 12:23  我是属车的  阅读(249)  评论(0编辑  收藏  举报