本文讲述如何安装, 部署, 启停 HBase 集群, 如何通过命令行对 Hbase 进行基本操作.
并介绍 Hbase 的配置文件.
在安装前需要将所有先决条件安装完成.
一, 先决条件
1,JDK
和 Hadoop 一样, Hbase 需要 JDK1.6 或者更高的版本, 所以请安装好 JDK 并配置环境变量.
Hbase 版本与 JDK 版本
2,Zookeeper
zookeeper 是 Hbase 集群的协调器, 负责解决 HMaster 的单点问题, 所以必须先安装好一个 zookeeper.
3,Hadoop
集群模式下, 我们需要 Hadoop 环境
Hadoop 版本支持
T = 支持
F = 不支持
N = 未测试
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 有两种运行模式, 单机模式和分布式模式.
1, 单机模式
下载
首先在这里下载 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/
- JAVA_HOME
在启动 HBase 之前, 您需要设置 JAVA_HOME 环境变量. 您可以通过操作系统的常用设置来设置变量, HBase 也提供了一个中心机制 conf/hbase-env.sh. 编辑此文件, 取消注释以 JAVA_HOME 开头的行, 并将其设置为适合您的操作系统的路径.
- JAVA_HOME=/usr
- hbase-site.xml
编辑 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 进程是否开启关闭.
2, 集群模式
2.1 伪分布式模式
伪分布模式意味着 HBase 仍然在单个主机上完全运行, 但是每个 HBase 守护进程 (HMaster,HRegionServer 和 ZooKeeper) 作为一个单独的进程运行.
使用集群模式前, 要保证 HDFS 可以正常运行.
hbase-site.xml
编辑 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
2.2 完全分布式
实际上, 您需要一个完全分布式的配置来全面测试 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
- 3,web UI
在 HBase 0.98.x 以上, HBase Web UI 的端口从主节点的 60010 和 RegionServer 的 60030 变化为 16010 和 16030
在 Hbase 启动以后可以通过页面查看.
三, Hbase Shell
在 HBase 安装目录 bin/ 目录下使用 hbase shell 命令连接正在运行的 HBase 实例.
- $ ./bin/hbase shell
- hbase(main):001:0>
预览 HBase Shell 的帮助文本
输入 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
退出 HBase Shell
使用 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