本文讲述如何安装,部署,启停HBase集群,如何经过命令行对Hbase进行基本操做。html
并介绍Hbase的配置文件。node
在安装前须要将全部先决条件安装完成。shell
和Hadoop同样,Hbase须要JDK1.6或者更高的版本,因此请安装好JDK并配置环境变量。apache
Hbase版本与JDK版本安全
HBase Version | JDK 7 | JDK 8 | JDK 9 (Non-LTS) | JDK 10 (Non-LTS) | JDK 11 |
---|---|---|---|---|---|
2.0+ | HBASE-20264 | HBASE-20264 | HBASE-21110 | ||
1.2+ | HBASE-20264 | HBASE-20264 | HBASE-21110 |
zookeeper是Hbase集群的协调器,负责解决HMaster的单点问题,因此必须先安装好一个zookeeper。服务器
集群模式下,咱们须要Hadoop环境架构
Hadoop 版本支持框架
HBase-1.2.x, HBase-1.3.x | HBase-1.4.x | HBase-2.0.x | HBase-2.1.x | |
---|---|---|---|---|
Hadoop-2.4.x | T | F | F | F |
Hadoop-2.5.x | T | F | F | F |
Hadoop-2.6.0 | F | F | F | F |
Hadoop-2.6.1+ | T | F | T | F |
Hadoop-2.7.0 | F | F | F | F |
Hadoop-2.7.1+ | T | T | T | T |
Hadoop-2.8.[0-1] | F | F | F | F |
Hadoop-2.8.2 | N | N | N | N |
Hadoop-2.8.3+ | N | N | T | T |
Hadoop-2.9.0 | F | F | F | F |
Hadoop-2.9.1+ | N | N | N | N |
Hadoop-3.0.[0-2] | F | F | F | F |
Hadoop-3.0.3+ | F | F | T | T |
Hadoop-3.1.0 | F | F | F | F |
Hadoop-3.1.1+ | F | F | T | T |
Hbase有两种运行模式,单机模式和分布式模式。ssh
首先在这里下载Hbase的一个稳定版本,https://www.apache.org/dyn/closer.lua/hbase/分布式
建议点击顶部连接,进入 HBase Releases 点击 stable 的文件夹,而后下载将以 tar.gz 结尾的二进制文件到本地。暂时不要下载以 src.tar.gz 结尾的文件。
进入到那个要解压的目录
$ tar xzvf hbase-1.3.5-bin.tar.gz $ cd hbase-1.3.5/
在启动 HBase 以前,您须要设置JAVA_HOME
环境变量。您能够经过操做系统的经常使用设置来设置变量,HBase 也提供了一个中心机制 conf/hbase-env.sh。编辑此文件,取消注释以JAVA_HOME
开头的行,并将其设置为适合您的操做系统的路径。
JAVA_HOME=/usr
编辑 HBase 主配置文件 conf/hbase-site.xml.
您须要在本地文件系统上指定 HBase 和 ZooKeeper 数据存储目录.
<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>
bin/start-hbase.sh 为启动 HBase
bin/start-hbase.sh为中止 HBase
可使用 jps
确认 HMaster 和 HRegionServer 进程是否开启关闭。
伪分布模式意味着 HBase 仍然在单个主机上彻底运行,可是每一个 HBase 守护进程(HMaster,HRegionServer 和 ZooKeeper)做为一个单独的进程运行.
使用集群模式前,要保证HDFS能够正常运行。
编辑 HBase 主配置文件 conf/hbase-site.xml.
须要将分布式模式开启 指定hdfs的URI
<property> <name>hbase.cluster.distributed</name> <value>true</value> </property> <property> <name>hbase.rootdir</name> <value>hdfs://localhost:8020/hbase</value> </property>
使用 bin/start-hbase.sh 启动 HBase. 若是您的系统配置正确,该jps
命令应显示 HMaster 和 HRegionServer 进程正在运行。
启动和中止备份 HBase 主(HMaster)服务器
你能够启动最多 9 个备份 HMaster 服务器,这个服务器总共有 10 个 HMaster 计算主服务器。
$ ./bin/local-master-backup.sh start 2 3 5
启动和中止其余 RegionServers
$ .bin/local-regionservers.sh start 2 3 4 5
实际上,您须要一个彻底分布式的配置来全面测试 HBase,并将其用于实际场景中。在分布式配置中,集群包含多个节点,每一个节点运行一个或多个 HBase 守护进程。这些包括主要和备份主实例,多个 ZooKeeper 节点和多个 RegionServer 节点。
架构以下:
Node Name | Master | ZooKeeper | RegionServer |
---|---|---|---|
node-a.example.com | yes | yes | no |
node-b.example.com | backup | yes | yes |
node-c.example.com | no | yes | yes |
要保证节点有通信权限,好比配置ssh免密和防火墙权限,并将zookeeper配置好启动。
将Hbase下载并解压,将配置文件同步到各个机器上。
$ bin/start-hbase.sh node-c.example.com: starting zookeeper, logging to /home/hbuser/hbase-0.98.3-hadoop2/bin/../logs/hbase-hbuser-zookeeper-node-c.example.com.out node-a.example.com: starting zookeeper, logging to /home/hbuser/hbase-0.98.3-hadoop2/bin/../logs/hbase-hbuser-zookeeper-node-a.example.com.out node-b.example.com: starting zookeeper, logging to /home/hbuser/hbase-0.98.3-hadoop2/bin/../logs/hbase-hbuser-zookeeper-node-b.example.com.out starting master, logging to /home/hbuser/hbase-0.98.3-hadoop2/bin/../logs/hbase-hbuser-master-node-a.example.com.out node-c.example.com: starting regionserver, logging to /home/hbuser/hbase-0.98.3-hadoop2/bin/../logs/hbase-hbuser-regionserver-node-c.example.com.out node-b.example.com: starting regionserver, logging to /home/hbuser/hbase-0.98.3-hadoop2/bin/../logs/hbase-hbuser-regionserver-node-b.example.com.out node-b.example.com: starting master, logging to /home/hbuser/hbase-0.98.3-hadoop2/bin/../logs/hbase-hbuser-master-nodeb.example.com.out
在 HBase 0.98.x 以上, HBase Web UI 的端口从主节点的 60010 和 RegionServer 的 60030 变化为 16010 和 16030
在Hbase启动之后能够经过页面查看。
在 HBase 安装目录 bin/ 目录下使用hbase shell
命令链接正在运行的 HBase 实例。
$ ./bin/hbase shell hbase(main):001:0>
输入help
并回车, 能够看到 HBase Shell 的基本信息和一些示例命令.
使用 create
建立一个表 必须指定一个表名和列族名
hbase(main):001:0> create 'test', 'cf' 0 row(s) in 0.4170 seconds => Hbase::Table - test
使用 list
查看存在表
hbase(main):002:0> list 'test' TABLE test 1 row(s) in 0.0180 seconds => ["test"]
describe
查看表细节及配置hbase(main):003:0> describe 'test' Table test is ENABLED test COLUMN FAMILIES DESCRIPTION {NAME => 'cf', VERSIONS => '1', EVICT_BLOCKS_ON_CLOSE => 'false', NEW_VERSION_BEHAVIOR => 'false', KEEP_DELETED_CELLS => 'FALSE', CACHE_DATA_ON_WRITE => 'false', DATA_BLOCK_ENCODING => 'NONE', TTL => 'FOREVER', MIN_VERSIONS => '0', REPLICATION_SCOPE => '0', BLOOMFILTER => 'ROW', CACHE_INDEX_ON_WRITE => 'f alse', IN_MEMORY => 'false', CACHE_BLOOMS_ON_WRITE => 'false', PREFETCH_BLOCKS_ON_OPEN => 'false', COMPRESSION => 'NONE', BLOCKCACHE => 'true', BLOCKSIZE => '65536'} 1 row(s) Took 0.9998 seconds
使用 put
插入数据
hbase(main):003:0> put 'test', 'row1', 'cf:a', 'value1' 0 row(s) in 0.0850 seconds hbase(main):004:0> put 'test', 'row2', 'cf:b', 'value2' 0 row(s) in 0.0110 seconds hbase(main):005:0> put 'test', 'row3', 'cf:c', 'value3' 0 row(s) in 0.0100 seconds
从 HBase 获取数据的途径之一就是 scan
。使用 scan 命令扫描表数据。你能够对扫描作限制。
hbase(main):006:0> scan 'test' ROW COLUMN+CELL row1 column=cf:a, timestamp=1421762485768, value=value1 row2 column=cf:b, timestamp=1421762491785, value=value2 row3 column=cf:c, timestamp=1421762496210, value=value3 3 row(s) in 0.0230 seconds
使用 get
命令一次获取一条数据
hbase(main):007:0> get 'test', 'row1' COLUMN CELL cf:a timestamp=1421762485768, value=value1 1 row(s) in 0.0350 seconds
使用 disable
命令禁用表
hbase(main):008:0> disable 'test' 0 row(s) in 1.1820 seconds hbase(main):009:0> enable 'test' 0 row(s) in 0.1770 seconds
使用 enable
命令启用表
hbase(main):010:0> disable 'test' 0 row(s) in 1.1820 seconds
hbase(main):011:0> drop 'test' 0 row(s) in 0.1370 seconds
使用quit
命令退出命令行并从集群断开链接。
Apache HBase 使用与 Apache Hadoop 相同的配置系统。全部配置文件都位于 conf/ 目录中,须要保持群集中每一个节点的同步。
backup-masters 默认状况下不存在。这是一个纯文本文件,其中列出了主服务器应在其上启动备份主进程的主机,每行一台主机。 hadoop-metrics2-hbase.properties 用于链接 HBase Hadoop 的 Metrics2 框架。默认状况下只包含注释出的示例。 hbase-env.cmd and hbase-env.sh 用于 Windows 和 Linux/Unix 环境的脚本,以设置 HBase 的工做环境,包括 Java、Java 选项和其余环境变量的位置。该文件包含许多注释示例来提供指导。 hbase-policy.xml RPC 服务器使用默认策略配置文件对客户端请求进行受权决策。仅在启用 HBase安全模式下使用。 hbase-site.xml 主要的 HBase 配置文件。该文件指定覆盖 HBase 的默认配置的配置选项。您能够在 docs/hbase-default.xml 中查看(但不要编辑)默认配置文件。您还能够在 HBase Web UI 的 HBase 配置选项卡中查看群集的整个有效配置(默认和覆盖)。 log4j.properties 经过log4j进行 HBase 日志记录的配置文件。 regionservers 包含应该在 HBase 集群中运行 RegionServer 的主机列表的纯文本文件。默认状况下,这个文件包含单个条目localhostt。它应该包含主机名或 IP 地址列表,每行一个,若是集群中的每一个节点将在其localhost接口上运行 RegionServer 的话,则只应包含localhost
更多实时计算,Hbase,Flink,Kafka等相关技术博文,欢迎关注实时流式计算
原文出处:https://www.cnblogs.com/tree1123/p/11606588.html