介绍
介绍hbase 单机实例启动方式(Master, RegionSever, zookeeper). hbase 是Java现实的,所以需要JVM环境
下载
https://www.apache.org/dyn/closer.lua/hbase/2.0.2/hbase-2.0.2-bin.tar.gz
安装
- 解压
tar xzvf hbase-2.0.2-bin.tar.gz
cd hbase-2.0.2
- 设置JAVA_HOME路径 vi conf/hbase-env.sh
# 内容
export JAVA_HOME=/usr/java/jdk1.8.0_121
- 配置文件路径
3.1 hbase.rootdir
3.2 hbase.zookeeper.property.dataDir
<configuration>
<property>
<name>hbase.rootdir</name>
<value>/data/jiazhiqiang/dataDir/hbase</value>
</property>
<property>
<name>hbase.zookeeper.property.dataDir</name>
<value>/data/jiazhiqiang/dataDir/zookeeper</value>
</property>
<property>
<name>hbase.unsafe.stream.capability.enforce</name>
<value>false</value>
<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>
</configuration>
启动
./bin/start-hbase.sh
测试
http://ip:16010
使用
连接hbase
使用hbase shell指令本地连接
$ ./bin/hbase shell
hbase(main):001:0>
查询所有表
hbase(main):005:0> list
TABLE
0 row(s)
Took 0.0076 seconds
=> []
hbase(main):006:0>
创建表
语法: create [table], [column family]
创建表,并指定它的列族; 在hbase中,列不属于表的,而是直接属于列族
, 列族创建消耗很大的性能,所以在增加列族的时候,需要先disable table
hbase(main):006:0> create 'user', 'baseinfo'
Created table user
Took 0.9881 seconds
=> Hbase::Table - user
增加列族
alter [table], [column family]
disable 'test'
Took 0.4992 seconds
hbase(main):037:0> alter 'test', 'cf2'
Updating all regions with the new schema...
All regions updated.
Done.
Took 1.2430 seconds
hbase(main):038:0> enable 'test'
Took 0.7625 seconds
插入数据
4:0* put 'test', 'row1', 'cf:name', 'jack'
Took 0.3727 seconds
hbase(main):045:0> scan 'test'
ROW COLUMN+CELL
row1 column=cf:name, timestamp=1537953179108, value=jack
1 row(s)
Took 0.0560 seconds
查询单行数据
hbase(main):031:0> get 'user' ,'row2'
COLUMN CELL
id: timestamp=1537253166068, value=002
name: timestamp=1537253177855, value=lisi
phone: timestamp=1537253188730, value=3253953
1 row(s)
扫描全表
hbase(main):036:0> scan 'user'
ROW COLUMN+CELL
row1 column=id:, timestamp=1537253015327, value=001
row1 column=name:, timestamp=1537253027288, value=zhangsan
row1 column=phone:, timestamp=1537253058786, value=1234545
row2 column=id:, timestamp=1537253166068, value=002
row2 column=name:, timestamp=1537253177855, value=lisi
row2 column=phone:, timestamp=1537253188730, value=3253953
启用和禁用表
distable 'user'
enable 'user'
删除表
drop 'user'