Hbase简介安装配置

时间:2021-11-05 01:31:30

HBase —— Hadoop Database的简称 ,hbase 是分布式,稀疏的,持久化的,多维有序映射,它基于行键rowkey,列键column key,时间戳timestamp建立索引。它是一个随机访问的存储和检索数据的平台。hbase 可以存储结构化,半结构化的数据

Hadoop使用分布式文件系统,用于存储大数据,并使用MapReduce来处理。Hadoop擅长于存储各种格式的庞大的数据,任意的格式甚至非结构化的处理。

Hadoop只能执行批量处理,并且只以顺序方式访问数据。这意味着必须搜索整个数据集,即使是最简单的搜索工作。

应用程序,如HBase, Cassandra, couchDB, Dynamo 和 MongoDB 都是一些存储大量数据和以随机方式访问数据的数据库。

HBase是建立在Hadoop文件系统之上的分布式面向列的数据库。它是一个开源项目,是横向扩展的。

HBase是一个数据模型,类似于谷歌的大表设计,可以提供快速随机访问海量结构化数据。它利用了Hadoop的文件系统(HDFS)提供的容错能力。

从功能上来讲,HBase不折不扣是一个数据库,与我们熟悉的Oracle、MySQL、MSSQL等一样,对外提供数据的存储和读取服务。而从应用的角度来说,HBase与一般的数据库又有所区别,HBase本身的存取接口相当简单,不支持复杂的数据存取,更不支持SQL等结构化的查询语言;HBase也没有除了rowkey以外的索引,所有的数据分布和查询都依赖rowkey。所以,HBase在表的设计上会有很严格的要求。架构上,HBase是分布式数据库的典范,这点比较像MongoDB的sharding模式,能根据键值的大小,把数据分布到不同的存储节点上,MongoDB根据configserver来定位数据落在哪个分区上,HBase通过访问Zookeeper来获取-ROOT-表所在地址,通过-ROOT-表得到相应.META.表信息,从而获取数据存储的region位置。

HDFS HBase
HDFS是适于存储大容量文件的分布式文件系统。 HBase是建立在HDFS之上的数据库。
HDFS不支持快速单独记录查找。 HBase提供在较大的表快速查找
它提供了高延迟批量处理;没有批处理概念。 它提供了数十亿条记录低延迟访问单个行记录(随机存取)。
它提供的数据只能顺序访问。 HBase内部使用哈希表和提供随机接入,并且其存储索引,可将在HDFS文件中的数据进行快速查找。

HBase是一个面向列的数据库,在表中它由行排序。表模式定义只能列族,也就是键值对。一个表有多个列族以及每一个列族可以有任意数量的列。后续列的值连续地存储在磁盘上。表中的每个单元格值都具有时间戳。总之,在一个HBase:

  • 表是行的集合。
  • 行是列族的集合。
  • 列族是列的集合。
  • 列是键值对的集合。
行式数据库 列式数据库
它适用于联机事务处理(OLTP)。 它适用于在线分析处理(OLAP)。
这样的数据库被设计为小数目的行和列。 面向列的数据库设计的巨大表。

区别

HBase RDBMS
HBase无模式,它不具有固定列模式的概念;仅定义列族。 RDBMS有它的模式,描述表的整体结构的约束。
它专门创建为宽表。 HBase是横向扩展。 这些都是细而专为小表。很难形成规模。
没有任何事务存在于HBase。 RDBMS是事务性的。
它反规范化的数据。 它具有规范化的数据。
它用于半结构以及结构化数据是非常好的。 用于结构化数据非常好。

hbase的安装配置

下载

http://mirrors.tuna.tsinghua.edu.cn/apache/hbase/2.0.0/hbase-2.0.0-bin.tar.gz

解压后配置hbase-site.xml

<configuration>
<property>
    <name>hbase.rootdir</name>
    <value>hdfs://host:9000/hbase</value>
</property>
<property>
     <name>hbase.cluster.distributed</name>
     <value>true</value>
  </property>
  <property>
    <name>hbase.zookeeper.quorum</name>
    <value>192.168.53.122</value>
  </property>
<!-- 指定HLog和Hfile的副本个数  -->
<property>
    <name>dfs.replication</name>
    <value>1</value>
</property>
<property> 
<name>hbase.master.info.port</name> 
<value>60010</value> 
</property> 
</configuration>

配置环境变量/etc/profile,~/.bashrc

根据实际路径配置

添加

export HBASE_HOME=/root/hbase-2.0.0
export PATH=$HBASE_HOME/bin:$PATH

启动hbase

[root@host bin]# start-hbase.sh
SLF4J: Class path contains multiple SLF4J bindings.
SLF4J: Found binding in [jar:file:/root/hbase-2.0.0/lib/slf4j-log4j12-1.7.25.jar!/org/slf4j/impl/StaticLoggerBinder.class]
SLF4J: Found binding in [jar:file:/root/hadoop/hadoop-2.7.4/share/hadoop/common/lib/slf4j-log4j12-1.7.10.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]
SLF4J: Class path contains multiple SLF4J bindings.
SLF4J: Found binding in [jar:file:/root/hbase-2.0.0/lib/slf4j-log4j12-1.7.25.jar!/org/slf4j/impl/StaticLoggerBinder.class]
SLF4J: Found binding in [jar:file:/root/hadoop/hadoop-2.7.4/share/hadoop/common/lib/slf4j-log4j12-1.7.10.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]
192.168.53.122: running zookeeper, logging to /root/hbase-2.0.0/logs/hbase-root-zookeeper-host.out
192.168.53.122: SLF4J: Class path contains multiple SLF4J bindings.
192.168.53.122: SLF4J: Found binding in [jar:file:/root/hbase-2.0.0/lib/slf4j-log4j12-1.7.25.jar!/org/slf4j/impl/StaticLoggerBinder.class]
192.168.53.122: SLF4J: Found binding in [jar:file:/root/hadoop/hadoop-2.7.4/share/hadoop/common/lib/slf4j-log4j12-1.7.10.jar!/org/slf4j/impl/StaticLoggerBinder.class]
192.168.53.122: SLF4J: See http://www.slf4j.org/codes.html#multiple_bindings for an explanation.
192.168.53.122: SLF4J: Actual binding is of type [org.slf4j.impl.Log4jLoggerFactory]
running master, logging to /root/hbase-2.0.0/logs/hbase-root-master-host.out
SLF4J: Class path contains multiple SLF4J bindings.
SLF4J: Found binding in [jar:file:/root/hbase-2.0.0/lib/slf4j-log4j12-1.7.25.jar!/org/slf4j/impl/StaticLoggerBinder.class]
SLF4J: Found binding in [jar:file:/root/hadoop/hadoop-2.7.4/share/hadoop/common/lib/slf4j-log4j12-1.7.10.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]
: running regionserver, logging to /root/hbase-2.0.0/logs/hbase-root-regionserver-host.out
: SLF4J: Class path contains multiple SLF4J bindings.
: SLF4J: Found binding in [jar:file:/root/hbase-2.0.0/lib/slf4j-log4j12-1.7.25.jar!/org/slf4j/impl/StaticLoggerBinder.class]
: SLF4J: Found binding in [jar:file:/root/hadoop/hadoop-2.7.4/share/hadoop/common/lib/slf4j-log4j12-1.7.10.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]

查看hdfs的hbase目录:

-rw-r--r--   1 root supergroup         42 2018-05-14 14:17 /hbase/hbase.id
-rw-r--r--   1 root supergroup          7 2018-05-14 14:17 /hbase/hbase.version
drwxr-xr-x   - root supergroup          0 2018-05-14 14:17 /hbase/mobdir
drwxr-xr-x   - root supergroup          0 2018-05-15 14:37 /hbase/oldWALs

----------------------------------------

启动停止主服务器

使用“local-master-backup.sh”就可以启动多达10台服务器。

[root@host bin]# local-master-backup.sh start 2
running master, logging to /root/hbase-2.0.0/logs/hbase-root-2-master-host.out
SLF4J: Class path contains multiple SLF4J bindings.
SLF4J: Found binding in [jar:file:/root/hbase-2.0.0/lib/slf4j-log4j12-1.7.25.jar!/org/slf4j/impl/StaticLoggerBinder.class]
SLF4J: Found binding in [jar:file:/root/hadoop/hadoop-2.7.4/share/hadoop/common/lib/slf4j-log4j12-1.7.10.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]

要中止备份主服务,需要它的进程ID,它被存储在一个文件名为“/tmp/hbase-USER-X-master.pid”中,可以使用下面的命令中止备份主服务。

[root@host ~]# cat /tmp/hbase-root-2-master.pid
16817

$ cat /tmp/hbase-root-2-master.pid |xargs kill -16817

启动和停止区域服务器

可以使用下面的命令来运行在单一系统中的多个区域的服务器。未测

$ .bin/local-regionservers.sh start 2 3

要停止区域服务器,可以使用下面的命令。

$ .bin/local-regionservers.sh stop 3

启动HBase Shell

[root@host ~]# hbase shell
SLF4J: Class path contains multiple SLF4J bindings.
SLF4J: Found binding in [jar:file:/root/hbase-2.0.0/lib/slf4j-log4j12-1.7.25.jar!/org/slf4j/impl/StaticLoggerBinder.class]
SLF4J: Found binding in [jar:file:/root/hadoop/hadoop-2.7.4/share/hadoop/common/lib/slf4j-log4j12-1.7.10.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.
Version 2.0.0, r7483b111e4da77adbfc8062b3b22cbe7c2cb91c1, Sun Apr 22 20:26:55 PDT 2018
Took 0.0039 seconds                                                                                                                          
hbase(main):001:0>

HBase的Web界面

hbase-site.xml文件中,端口号配置为60010

界面链接为

http://192.168.53.122:60010