HBase的standalone模式:
在一个JVM中启动Master 、 RegionServers 、 Zookeeper。
支持的JDK 版本
图片.png建议使用JDK8 。
下载、安装Hbase
- 至 Apache Download Mirrors. 下载稳定版本。
- 解压
$ tar xzvf hbase-3.0.0-SNAPSHOT-bin.tar.gz
$ cd hbase-3.0.0-SNAPSHOT/
- 设置JAVA_HOME , 可以export到用户profile ; 也可以在conf/hbase-env.sh下配置。
- 配置conf/hbase-site.xml 文件。 这是hbash的主配置文件 。 需要指定本地文件系统目录用户hbase和zk写数据和发现风险。 默认情况下创建在/tmp下。
实例1: standalone模式下的hbase-site.xml:
<configuration>
<property>
<name>hbase.rootdir</name>
<value>file:///home/testuser/hbase</value>
</property>
<property>
<name>hbase.zookeeper.property.dataDir</name>
<value>/home/testuser/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>
Hbase会自动创建数据目录, 不需要手工创建。 如果你创建了,hbase将尝试进行迁移。
上例中的hbase.rootdir
指向本地文件系统中的一个目录。'file://'前缀表示本地文件系统。 在生产环境不建议使用本地文件系统目录。
要在现有的HDFS上安装HBase,请将hbase.rootdir
设置为hdfs上的目录:例如hdfs://namenode.example.org:8020 / hbase
。
启动
使用bin/start-hbase.sh 脚本启动hbase。 正常情况下回打印日志信息到标准输出。
可以使用jps 命令验证启动的守护进程: 包括HMaster 、 HRegionserver
和ZooKeeper 守护进程。
同样,可以通过webui验证: http://localhost:16010
使用hbase 客户端
- 使用 bin/hbase shell 命令连接HBase服务。
2018-05-23 00:51:17,199 INFO [main] Configuration.deprecation: hadoop.native.lib is deprecated. Instead, use io.native.lib.available
HBase Shell; enter 'help<RETURN>' for list of supported commands.
Type "exit<RETURN>" to leave the HBase Shell
Version 1.2.0-cdh5.13.0, rUnknown, Wed Oct 4 11:16:18 PDT 2017
hbase(main):001:0>
-
使用help 命令显示帮助。
-
创建table , 笔数指定表名 和 列族名:
hbase(main):002:0> create 'test1' , 'cf'
0 row(s) in 2.7650 seconds
=> Hbase::Table - test1
hbase(main):003:0>
- 使用list 命令查看表:
hbase(main):004:0> list 'test1'
TABLE
test1
1 row(s) in 0.0060 seconds
=> ["test1"]
- 使用 describe 命令查询表的详细信息
hbase(main):005:0> describe 'test1'
Table test1 is ENABLED
test1
COLUMN FAMILIES DESCRIPTION
{NAME => 'cf', DATA_BLOCK_ENCODING => 'NONE', BLOOMFILTER => 'ROW', REPLICATION_SCOPE => '0', VERSIONS => '1', COMPRESSION => 'NONE', MIN_VERSIONS => '0', TTL => 'FOREVER',
KEEP_DELETED_CELLS => 'FALSE', BLOCKSIZE => '65536', IN_MEMORY => 'false', BLOCKCACHE => 'true'}
1 row(s) in 0.1490 seconds
- 使用put 向表中插入数据 :
hbase(main):006:0> put 'test1' , 'row1', 'cf:a', '123'
0 row(s) in 0.2350 seconds
hbase(main):007:0> put 'test1', '22', 'cf:a', 'value22'
0 row(s) in 0.0090 seconds
hbase(main):008:0> put 'test1', 'row3', 'cf:c', '32'
0 row(s) in 0.0170 seconds
- 使用scan命令显示表中数据 :
hbase(main):003:0> scan 'test1'
ROW COLUMN+CELL
22 column=cf:a, timestamp=1527062378011, value=value22
row1 column=cf:a, timestamp=1527062518191, value=vadddddddddd
row1 column=cf:ac, timestamp=1527062671499, value=123
row3 column=cf:c, timestamp=1527062406780, value=32
3 row(s) in 0.0240 seconds
- 使用get 命令 获取一条row
hbase(main):009:0> get 'test1' , 'row1'
COLUMN CELL
cf:a timestamp=1527062518191, value=vadddddddddd
cf:ac timestamp=1527062671499, value=123
2 row(s) in 0.0190 seconds
- 禁用table , 使用disable 命令 (在删除表之前需要先禁用之); enable 命令启用table。
hbase(main):010:0> disable 'test1'
hbase(main):012:0> enable 'test1'
- 删除表
hbase(main):011:0> drop 'test'
0 row(s) in 0.1370 seconds
- 退出hbase shell
quit
停止hbase
$ ./bin/stop-hbase.sh
stopping hbase....................
$
停止命令可能会需要几分钟的时间完成, 使用jps命令确定HMatster 和 HRegionServer进程已被关闭。
hbase-env.sh
设置JAVA_HOME 环境变量。
设置JVM 堆栈参数 。
设置 日志文件路径等。
Standalone 模式是默认模式。
Standalone模式使用HDFS
当考虑在该模式下使用hdfs时, 部署简单、 负载小,但是数据必须分布式存放。
配置hbase-site.xml文件, 设置hbase.rootdir 为hdfs上的目录; 并且 设置hbase.cluster.distributed = false :
<configuration>
<property>
<name>hbase.rootdir</name>
<value>hdfs://namenode.example.org:8020/hbase</value>
</property>
<property>
<name>hbase.cluster.distributed</name>
<value>false</value>
</property>
</configuration>
网友评论