hbase 官方文档 0.97


本站和网页 http://abloz.com/hbase/book.html#zookeeper 的作者无关,不对其内容负责。快照谨为网络故障时之索引,不代表被搜索网站的即时页面。


HBase 官方文档 0.97
Apache HBase™ 参考指南
HBase
官方文档中文版
Copyright © 2012 Apache Software Foundation。保留所有权利。 Apache Hadoop, Hadoop, MapReduce, HDFS, Zookeeper, HBase 及 HBase项目 logo 是Apache Software Foundation的商标。
Revision History
Revision 0.97.0-SNAPSHOT
2013-04-07T14:59
中文版翻译整理
周海汉
译者
:HBase新版 0.97 文档和0.90版相比,变化较大,文档补充更新了很多内容,章节调整较大。本翻译文档的部分工作基于
颜开
工作。英文原文地址在
此处
。旧版0.90版由颜开翻译文档在
。0.97版翻译最后更新请到
http://abloz.com/hbase/book.html
)浏览。反馈和参与请到
此处 (https://github.com/ablozhou/hbasedoc_cn/)
或访问我的
blog(http://abloz.com)
,或给我发email。
可以通过浏览器直接存储为pdf或本地文件。
贡献者:
周海汉邮箱:ablozhou@gmail.com, QQ:7268188 网址:
http://abloz.com/
颜开邮箱: yankaycom@gmail.com, 网址:
http://www.yankay.com/
摘要
这是
Apache HBas
e (TM)
的官方文档。
HBase是一个分布式,版本化,面向列的数据库,构建在
Apache Hadoop
Apache ZooKeeper
之上。
 
目录
1. 入门
1.1. 介绍
1.2. 快速开始
2. Apache HBase (TM)
配置
2.1. 基础条件
2.2. HBase 运行模式: 独立和分布式
2.3.
配置文件
2.4. 配置示例
2.5.
重要配置
3. 升级
3.1. 从 0.94.x 升级到 0.96.x
3.2. 从 0.92.x 升级到 0.94.x
3.3. 从 0.90.x 升级到 0.92.x
3.4. 从0.20x或0.89x升级到0.90.x
4. HBase Shell
4.1.
使用脚本
4.2.
Shell 技巧
5.
数据模型
5.1.
概念视图
5.2.
物理视图
5.3.
5.4.
5.5. 列族
5.6. Cells
5.7. Data Model Operations
5.8. 版本
5.9. 排序
5.10. 列元数据
5.11. Joins
5.12. ACID
6. HBase 和 Schema 设计
6.1. Schema
创建
6.2.
column families的数量
6.3. Rowkey 设计
6.4. 版本数量
6.5. 支持的数据类型
6.6. Joins
6.7. 生存时间 (TTL)
6.8. 保留删除的单元
6.9. 第二索引和替代查询路径
6.10. 限制
6.11. 模式设计用例
6.12. 操作和性能配置选项
7. HBase 和 MapReduce
7.1. Map-Task 分割
7.2. HBase MapReduce 示例
7.3. 在MapReduce工作中访问其他 HBase 表
7.4. 推测执行
8. HBase安全
8.1. 安全客户端访问 HBase
8.2. 访问控制
8.3. 安全批量加载
9. 架构
9.1. 概述
9.2. 目录表
9.3. 客户端
9.4. 客户请求过滤器
9.5. Master
9.6. RegionServer
9.7. 分区(Regions
9.8. 批量加载
9.9. HDFS
10. 外部 APIs
10.1. 非Java语言和 JVM交互
10.2. REST
10.3. Thrift
10.4. C/C++ Apache HBase Client
11. 性能调优
11.1. 操作系统
11.2. 网络
11.3. Java
11.4. HBase 配置
11.5. ZooKeeper
11.6. Schema 设计
11.7. HBase General Patterns
11.8. 写到 HBase
11.9. 从 HBase读取
11.10. 从 HBase删除
11.11. HDFS
11.12. Amazon EC2
11.13. 案例
12. 故障排除和调试 HBase
12.1. 通用指引
12.2. Logs
12.3. 资源
12.4. 工具
12.5. 客户端
12.6. MapReduce
12.7. NameNode
12.8. 网络
12.9. RegionServer
12.10. Master
12.11. ZooKeeper
12.12. Amazon EC2
12.13. HBase 和 Hadoop 版本相关
12.14. 案例
13. 案例研究
13.1. 概要
13.2. Schema 设计
13.3. 性能/故障排除
14. HBase 运维管理
14.1. HBase 工具和实用程序
14.2. 分区管理
14.3. 节点管理
14.4. HBase 度量(Metrics)
14.5. HBase 监控
14.6. Cluster 复制
14.7. HBase 备份
14.8. 容量规划
15. 创建和开发 HBase
15.1. HBase 仓库
15.2. IDEs
15.3. 创建 HBase
15.4. 添加 Apache HBase 发行版到Apache的 Maven Repository
15.5. 生成HBase 参考指南
15.6. 更新 hbase.apache.org
15.7. 测试
15.8. Maven 创建命令
15.9. 加入
15.10. 开发
15.11. 提交补丁
16. ZooKeeper
16.1.
和已有的ZooKeeper一起使用
16.2.
通过ZooKeeper 的SASL 认证
17. 社区
17.1. 决策
17.2. 社区角色
A. FAQ
B. 深入hbck
B.1. 运行 hbck 以查找不一致
B.2. 不一致(Inconsistencies)
B.3. 局部修补
B.4. 分区重叠修补
C.
HBase中的压缩
C.1. CompressionTest 工具
C.2. hbase.regionserver.codecs
C.3. LZO
C.4. GZIP
C.5. SNAPPY
C.6. 修改压缩 Schemes
D. YCSB: Yahoo! 云服务评估和 HBase
E. HFile 格式版本 2
E.1. Motivation
E.2. HFile 格式版本 1 概览
E.3. HBase 文件格式带 inline blocks (version 2)
F.
HBase的其他信息
F.1. HBase 视频
F.2. HBase 展示 (Slides)
F.3. HBase 论文
F.4. HBase 网站
F.5. HBase 书籍
F.6. Hadoop 书籍
G. HBase 历史
H. HBase 和 Apache 软件基金会(ASF)
H.1. ASF开发进程
H.2. ASF 报告板
I. Enabling Dapper-like Tracing in HBase
I.1. SpanReceivers
I.2. Client Modifications
J. 0.95 RPC Specification
J.1. Goals
J.2. TODO
J.3. RPC
J.4. Notes
词汇表
表索引
2.1. 
Hadoop version support matrix
5.1. 
Table webtable
5.2. 
ColumnFamily anchor
5.3. 
ColumnFamily contents
8.1. 
Operation To Permission Mapping
这本书是
的官方指南。
版本为
0.95-SNAPSHOT
。可以在HBase官网上找到它。也可以在
javadoc
JIRA
wiki
找到更多的资料。
此书正在编辑中。 可以向 HBase 官方提供补丁
这个版本系译者水平限制,没有理解清楚或不需要翻译的地方保留英文原文。
最前面的话
若这是你第一次踏入分布式计算的精彩世界,你会感到这是一个有趣的年代。分布式计算是很难的,做一个分布式系统需要很多软硬件和网络的技能。你的集群可以会因为各式各样的错误发生故障。比如HBase本身的Bug,错误的配置(包括操作系统),硬件的故障(网卡和磁盘甚至内存)
如果你一直在写单机程序的话,你需要重新开始学习。这里就是一个好的起点:
分布式计算的谬论
Chapter 1. 入门
Table of Contents
1.2.1. 下载解压最新版本
1.2.2. 启动 HBase
1.2.3. Shell 练习
1.2.4. 停止 HBase
1.2.5. 下一步该做什么
1.1. 介绍
Section 1.2, “快速开始”
会介绍如何运行一个单机版的HBase.他运行在本地磁盘上。
Section 2, “配置”
会介绍如何运行一个分布式的HBase。他运行在HDFS上
1.2. 快速开始
本指南介绍了在单机安装HBase的方法。会引导你通过
shell
创建一个表,插入一行,然后删除它,最后停止HBase。只要10分钟就可以完成以下的操作。
1.2.1. 下载解压最新版本
选择一个
Apache 下载镜像
,下载
HBase Releases
. 点击
stable
目录,然后下载后缀为
.tar.gz
的文件; 例如
hbase-0.95-SNAPSHOT.tar.gz
解压缩,然后进入到那个要解压的目录.
$ tar xfz hbase-0.95-SNAPSHOT.tar.gz
$ cd hbase-0.95-SNAPSHOT
现在你已经可以启动HBase了。但是你可能需要先编辑
conf/hbase-site.xml
去配置
hbase.rootdir
,来选择HBase将数据写到哪个目录
<?xml version="1.0"?>
<?xml-stylesheet type="text/xsl" href="configuration.xsl"?>
<configuration>
<property>
<name>hbase.rootdir</name>
<value>file:///DIRECTORY/hbase</value>
</property>
</configuration>
DIRECTORY
替换成你期望写文件的目录. 默认
是指向
/tmp/hbase-${user.name}
,也就说你会在重启后丢失数据(重启的时候操作系统会清理
/tmp
目录)
1.2.2. 启动 HBase
现在启动HBase:
$ ./bin/start-hbase.sh
starting Master, logging to logs/hbase-user-master-example.org.out
现在你运行的是单机模式的Hbaes。所有的服务都运行在一个JVM上,包括HBase和Zookeeper。HBase的日志放在
logs
目录,当你启动出问题的时候,可以检查这个日志。
是否安装了
java
你需要确认安装了Oracle的1.6 版本的
.如果你在命令行键入java有反应说明你安装了Java。如果没有装,你需要先安装,然后编辑
conf/hbase-env.sh
,将其中的
JAVA_HOME
指向到你Java的安装目录。
1.2.3. Shell 练习
连接你的HBase
$ ./bin/hbase shell
HBase Shell; enter 'help<RETURN>' for list of supported commands.
Type "exit<RETURN>" to leave the HBase Shell
Version: 0.90.0, r1001068, Fri Sep 24 13:55:42 PDT 2010
hbase(main):001:0>
输入
help
然后
<RETURN>
可以看到一列shell命令。这里的帮助很详细,要注意的是表名,行和列需要加引号。
创建一个名为
test
的表,这个表只有一个 列族 为
cf
。可以列出所有的表来检查创建情况,然后插入些值。
hbase(main):003:0> create 'test', 'cf'
0 row(s) in 1.2200 seconds
hbase(main):003:0> list 'table'
1 row(s) in 0.0550 seconds
hbase(main):004:0> put 'test', 'row1', 'cf:a', 'value1'
0 row(s) in 0.0560 seconds
hbase(main):005:0> put 'test', 'row2', 'cf:b', 'value2'
0 row(s) in 0.0370 seconds
hbase(main):006:0> put 'test', 'row3', 'cf:c', 'value3'
0 row(s) in 0.0450 seconds
以上我们分别插入了3行。第一个行key为
row1
, 列为
cf:a
, 值是
value1
。HBase中的列是由 列族前缀和列的名字组成的,以冒号间隔。例如这一行的列名就是
检查插入情况.
Scan这个表,操作如下
hbase(main):007:0> scan 'test'
ROW
COLUMN+CELL
column=cf:a, timestamp=1288380727188, value=value1
row2
column=cf:b, timestamp=1288380738440, value=value2
row3
column=cf:c, timestamp=1288380747365, value=value3
3 row(s) in 0.0590 seconds
Get一行,操作如下
hbase(main):008:0> get 'test', 'row1'
COLUMN
CELL
timestamp=1288380727188, value=value1
1 row(s) in 0.0400 seconds
disable 再 drop 这张表,可以清除你刚刚的操作
hbase(main):012:0> disable 'test'
0 row(s) in 1.0930 seconds
hbase(main):013:0> drop 'test'
0 row(s) in 0.0770 seconds
关闭shell
hbase(main):014:0> exit
1.2.4. 停止 HBase
运行停止脚本来停止HBase.
$ ./bin/stop-hbase.sh
stopping hbase...............
1.2.5. 下一步该做什么
以上步骤仅仅适用于实验和测试。接下来你可以看
Section 2., “配置”
,我们会介绍不同的HBase运行模式,运行分布式HBase中需要的软件 和如何配置。
2. 配置
本章是慢速开始配置指导。
HBase有如下需要,请仔细阅读本章节以确保所有的需要都被满足。如果需求没有能满足,就有可能遇到莫名其妙的错误甚至丢失数据。
HBase使用和Hadoop一样配置系统。要配置部署,编辑conf/hbase-env.sh文件中的环境变量——该配置文件主要启动脚本用于获取已启动的集群——然后增加配置到XML文件,如同覆盖HBase缺省配置,告诉HBase用什么文件系统, 全部ZooKeeper位置 [
] 。
在分布模式下运行时,在编辑HBase配置文件之后,确认将conf目录复制到集群中的每个节点。HBase不会自动同步。使用
rsync
] 小心编辑XML。确认关闭所有元素。采用 
xmllint
 或类似工具确认文档编辑后是良好格式化的。
2.1. 基础条件
This section lists required services and some required system configuration.
2.1.1 java
和Hadoop一样,HBase需要Oracle版本的
Java6
.除了那个有问题的u18版本其他的都可以用,最好用最新的。
2.1. 操作系统
2.1.2.1. ssh
必须安装
ssh
sshd
也必须运行,这样Hadoop的脚本才可以远程操控其他的Hadoop和HBase进程。ssh之间必须都打通,不用密码都可以登录,详细方法可以Google一下 ("ssh passwordless login").
2.1.2.2. DNS
HBase使用本地 hostname 才获得IP地址.
正反向的DNS都是可以的.
如果你的机器有多个接口,HBase会使用hostname指向的主接口.
如果还不够,你可以设置
hbase.regionserver.dns.interface
来指定主接口。当然你的整个集群的配置文件都必须一致,每个主机都使用相同的网络接口
还有一种方法是设置
hbase.regionserver.dns.nameserver
来指定nameserver,不使用系统带的.
2.1.2.3. Loopback IP
HBase expects the loopback IP address to be 127.0.0.1.
Ubuntu and some other distributions,
for example, will default to 127.0.1.1 and this will cause problems for you.
/etc/hosts
should look something like this:
127.0.0.1 localhost
127.0.0.1 ubuntu.ubuntu-domain ubuntu
2.1.2.4. NTP
集群的时钟要保证基本的一致。稍有不一致是可以容忍的,但是很大的不一致会造成奇怪的行为。 运行
NTP
或者其他什么东西来同步你的时间.
如果你查询的时候或者是遇到奇怪的故障,可以检查一下系统时间是否正确!
2.1.2.5. 
ulimit
nproc
HBase是数据库,会在同一时间使用很多的文件句柄。大多数linux系统使用的默认值1024是不能满足的,会导致
FAQ: Why do I
see "java.io.IOException...(Too many open files)" in my logs?
异常。还可能会发生这样的异常
2010-04-06 03:04:37,542 INFO org.apache.hadoop.hdfs.DFSClient: Exception increateBlockOutputStream java.io.EOFException
2010-04-06 03:04:37,542 INFO org.apache.hadoop.hdfs.DFSClient: Abandoning block blk_-6935524980745310745_1391901
所以你需要修改你的最大文件句柄限制。可以设置到10k。大致的数学运算如下:每列族至少有1个存储文件(StoreFile) 可能达到5-6个如果区域有压力。将每列族的存储文件平均数目和每区域服务器的平均区域数目相乘。例如:假设一个模式有3个列族,每个列族有3个存储文件,每个区域服务器有100个区域,JVM 将打开3 * 3 * 100 = 900 个文件描述符(不包含打开的jar文件,配置文件等)
你还需要修改 hbase 用户的
,在压力下,如果过低会造成
OutOfMemoryError
异常[
] [
]。
需要澄清的,这两个设置是针对操作系统的,不是HBase本身的。有一个常见的错误是HBase运行的用户,和设置最大值的用户不是一个用户。在HBase启动的时候,第一行日志会现在ulimit信息,确保其正确。[
2.1.2.5.1. 在Ubuntu上设置
如果你使用的是Ubuntu,你可以这样设置:
在文件
/etc/security/limits.conf
添加一行,如:
hadoop
nofile
32768
可以把
替换成你运行HBase和Hadoop的用户。如果你用两个用户,你就需要配两个。还有配nproc hard 和 soft
limits.
如:
hadoop soft/hard nproc 32000
/etc/pam.d/common-session
加上这一行:
session required
pam_limits.so
否则在
上的配置不会生效.
还有注销再登录,这些配置才能生效!
2.1.2.6. Windows
HBase没有怎么在Windows下测试过。所以不推荐在Windows下运行.
如果你实在是想运行,需要安装
Cygwin
并虚拟一个unix环境.详情请看
Windows
安装指导
. 或者
搜索邮件列表
找找最近的关于windows的注意点
2.1.3. 
选择 Hadoop 版本对HBase部署很关键。下表显示不同HBase支持的Hadoop版本信息。基于HBase版本,应该选择合适的Hadoop版本。我们没有绑定 Hadoop 发行版选择。可以从Apache使用 Hadoop 发行版,或了解一下Hadoop发行商产品: 
http://wiki.apache.org/hadoop/Distributions%20and%20Commercial%20Support
Table 2.1. Hadoop version support matrix
HBase-0.92.x
HBase-0.94.x
HBase-0.96
Hadoop-0.20.205
Hadoop-0.22.x
Hadoop-1.0.x
Hadoop-1.1.x
NT
Hadoop-0.23.x
Hadoop-2.x
S = supported and tested,支持
X = not supported,不支持
NT =
not tested enough.可以运行但测试不充分
由于 HBase 依赖 Hadoop,它配套发布了一个Hadoop jar 文件在它的 lib 下。该套装jar仅用于独立模式。在分布式模式下,Hadoop版本必须和HBase下的版本一致。用你运行的分布式Hadoop版本jar文件替换HBase lib目录下的Hadoop jar文件,以避免版本不匹配问题。确认替换了集群中所有HBase下的jar文件。Hadoop版本不匹配问题有不同表现,但看起来都像挂掉了。
2.1.3.1. Apache HBase 0.92 and 0.94
HBase 0.92 and 0.94 versions can work with Hadoop versions, 0.20.205, 0.22.x, 1.0.x, and 1.1.x. HBase-0.94 can additionally work with Hadoop-0.23.x and 2.x, but you may have to recompile the code using the specific maven profile (see top level pom.xml)
2.1.3.2. Apache HBase 0.96
Apache HBase 0.96.0 requires Apache Hadoop 1.x at a minimum, and it can run equally well on hadoop-2.0. As of Apache HBase 0.96.x, Apache Hadoop 1.0.x at least is required. We will no longer run properly on older Hadoops such as 0.20.205 or branch-0.20-append. Do not move to Apache HBase 0.96.x if you cannot upgrade your Hadoop[
].
2.1.3.3. Hadoop versions 0.20.x - 1.x
HBase will lose data unless it is running on an HDFS that has a durable sync implementation. DO NOT use Hadoop 0.20.2, Hadoop 0.20.203.0, and Hadoop 0.20.204.0 which DO NOT have this attribute. Currently only Hadoop versions 0.20.205.x or any release in excess of this version -- this includes hadoop-1.0.0 -- have a working, durable sync[
]. Sync has to be explicitly enabled by setting dfs.support.append equal to true on both the client side -- in hbase-site.xml -- and on the serverside in hdfs-site.xml (The sync facility HBase needs is a subset of the append code path).
<name>dfs.support.append</name>
<value>true</value>
You will have to restart your cluster after making this edit. Ignore the chicken-little comment you'll find in the hdfs-default.xml in the description for thedfs.support.append configuration.
2.1.3.4. Hadoop 安全性
HBase运行在Hadoop 0.20.x上,就可以使用其中的安全特性 -- 只要你用这两个版本0.20S 和CDH3B3,然后把hadoop.jar替换掉就可以了.
2.1.3.5. 
dfs.datanode.max.xcievers
一个 Hadoop HDFS Datanode 有一个同时处理文件的上限. 这个参数叫
xcievers
(Hadoop的作者把这个单词拼错了). 在你加载之前,先确认下你有没有配置这个文件
conf/hdfs-site.xml
里面的
xceivers
参数,至少要有4096:
<name>dfs.datanode.max.xcievers</name>
<value>4096</value>
对于HDFS修改配置要记得重启.
如果没有这一项配置,你可能会遇到奇怪的失败。你会在Datanode的日志中看到xcievers exceeded,但是运行起来会报 missing blocks错误。例如:
10/12/08 20:10:31 INFO hdfs.DFSClient: Could not obtain block
blk_XXXXXXXXXXXXXXXXXXXXXX_YYYYYYYY from any node:
java.io.IOException: No live nodes contain current block. Will get new
block locations from namenode and retry...
See also 
Section 13.3.4, “Case Study #4 (xcievers Config)”
2.2. HBase运行模式:单机和分布式
HBase有两个运行模式:
Section 2.4.1, “单机模式”
Section 2.4.2, “分布式模式”
. 默认是单机模式,如果要分布式模式你需要编辑
conf
文件夹中的配置文件.
不管是什么模式,你都需要编辑
来告知HBase
的安装路径.在这个文件里你还可以设置HBase的运行环境,诸如 heapsize和其他
JVM
有关的选项, 还有Log文件地址,等等. 设置
指向
安装的路径.
2.21. 单机模式
这是默认的模式,在
一章中介绍的就是这个模式. 在单机模式中,HBase使用本地文件系统,而不是HDFS ,所有的服务和zooKeeper都运作在一个JVM中。zookeep监听一个端口,这样客户端就可以连接HBase了。
2.2.2. 分布式模式
分布式模式分两种。
伪分布式模式
是把进程运行在一台机器上,但不是一个JVM.而
完全分布式模式
就是把整个服务被分布在各个节点上了
分布式模式需要使用
Hadoop
Distributed File System
(HDFS).可以参见
HDFS需求和指导
来获得关于安装HDFS的指导。在操作HBase之前,你要确认HDFS可以正常运作。
在我们安装之后,你需要确认你的
或者
的配置是否正确。这两个模式可以使用同一个验证脚本
Section 2.2.3, “运行和确认你的安装”
2.2.2.1. 伪分布式模式
伪分布式模式是一个相对简单的分布式模式。这个模式是用来测试的。不能把这个模式用于生产环节,也不能用于测试性能。
你确认HDFS安装成功之后,就可以先编辑
。在这个文件你可以加入自己的配置,这个配置会覆盖
Section 2.6.1.1, “HBase 默认配置”
and
Section 2.2.2.2.3, “HDFS客户端配置”
. 运行HBase需要设置
属性.该属性是指HBase在HDFS中使用的目录的位置。例如,要想
/hbase
目录,让namenode 监听locahost的9000端口,只有一份数据拷贝(HDFS默认是3份拷贝)。可以在
hbase-site.xml
写上如下内容
...
<value>hdfs://localhost:9000/hbase</value>
<description>The directory shared by RegionServers.
</description>
<name>dfs.replication</name>
<value>1</value>
<description>The replication count for HLog & HFile storage. Should not be greater than HDFS datanode count.
Note
让HBase自己创建
上面我们绑定到
localhost
. 也就是说除了本机,其他机器连不上HBase。所以你需要设置成别的,才能使用它。
现在可以跳到
来运行和确认你的伪分布式模式安装了。
2.2.2.1.1. 伪分布模式配置文件
下面是伪分布模式设置的配置文件示例。
hdfs-site.xml
<name>dfs.name.dir</name>
<value>/Users/local/user.name/hdfs-data-name</value>
<name>dfs.data.dir</name>
<value>/Users/local/user.name/hdfs-data</value>
<value>hdfs://localhost:8020/hbase</value>
<name>hbase.zookeeper.quorum</name>
<value>localhost</value>
<name>hbase.cluster.distributed</name>
2.2.2.1.2. 伪分布模式附加
2.2.2.1.2.1. 启动
启动初始 HBase 集群...
% bin/start-hbase.sh
在同一服务器启动额外备份主服务器
% bin/local-master-backup.sh start 1
'1' 表示使用端口 60001 & 60011, 该备份主服务器及其log文件放在logs/hbase-${USER}-1-master-${HOSTNAME}.log.
启动多个备份主服务器...
% bin/local-master-backup.sh start 2 3
可以启动到 9 个备份服务器 (总数10 个).
启动更多 regionservers...
% bin/local-regionservers.sh start 1
'1' 表示使用端口 60201 & 60301 ,log文件在 logs/hbase-${USER}-1-regionserver-${HOSTNAME}.log.
在刚运行的regionserver上增加 4 个额外 regionservers ...
% bin/local-regionservers.sh start 2 3 4 5
支持到 99 个额外regionservers (总100个).
2.2.2.1.2.2. 停止
假设想停止备份主服务器 # 1, 运行...
% cat /tmp/hbase-${USER}-1-master.pid |xargs kill -9
注意 bin/local-master-backup.sh 停止 1 会尝试停止主服务器相关集群。
停止单独 regionserver, 运行...
% bin/local-regionservers.sh stop 1
2.2.2.2. 
要想运行完全分布式模式,你要进行如下配置,先在
, 加一个属性
hbase.cluster.distributed
设置为
true
然后把
设置为HDFS的NameNode的位置。
例如,你的namenode运行在namenode.example.org,端口是9000 你期望的目录是
,使用如下的配置
<value>hdfs://namenode.example.org:9000/hbase</value>
<description>The mode the cluster will be in. Possible values are
false: standalone and pseudo-distributed setups with managed Zookeeper
true: fully-distributed with unmanaged Zookeeper Quorum (see hbase-env.sh)
2.2.2.2.1. 
regionservers
完全分布式模式的还需要修改
conf/regionservers
. 在
Section 2.7.1.2, “
列出了你希望运行的全部
HRegionServer
,一行写一个host (就像Hadoop里面的
slaves
一样). 列在这里的server会随着集群的启动而启动,集群的停止而停止.
2.2.2.2.2. ZooKeeper 和 HBase
2.2.2.2.3. HDFS客户端配置
如果你希望Hadoop集群上做
HDFS 客户端配置
,例如你的HDFS客户端的配置和服务端的不一样。按照如下的方法配置,HBase就能看到你的配置信息:
hbase-env.sh
里将
HBASE_CLASSPATH
环境变量加上
HADOOP_CONF_DIR
${HBASE_HOME}/conf
下面加一个
(或者
hadoop-site.xml
) ,最好是软连接
如果你的HDFS客户端的配置不多的话,你可以把这些加到
上面.
例如HDFS的配置
dfs.replication
.你希望复制5份,而不是默认的3份。如果你不照上面的做的话,HBase只会复制3份。
2.2.3. 运行和确认你的安装
首先确认你的HDFS是运行着的。你可以运行
HADOOP_HOME
中的
bin/start-hdfs.sh
来启动HDFS.你可以通过
put
命令来测试放一个文件,然后有
get
命令来读这个文件。通常情况下HBase是不会运行mapreduce的。所以比不需要检查这些。
如果
你自己管理ZooKeeper集群,你需要确认它是运行着的。如果是HBase托管,ZoopKeeper会随HBase启动。
用如下命令启动HBase:
bin/start-hbase.sh
这个脚本在
HBASE_HOME
目录里面。
你现在已经启动HBase了。HBase把log记在
子目录里面. 当HBase启动出问题的时候,可以看看Log.
HBase也有一个界面,上面会列出重要的属性。默认是在Master的60010端口上H (HBase RegionServers 会默认绑定
60020端口,在端口60030上有一个展示信息的界面 ).如果Master运行在
master.example.org
,端口是默认的话,你可以用浏览器在
http://master.example.org:60010
看到主界面.
一旦HBase启动,参见
Section 1.2.3, “Shell 练习”
可以看到如何建表,插入数据,scan你的表,还有disable这个表,最后把它删掉。
可以在HBase Shell停止HBase
停止操作需要一些时间,你的集群越大,停的时间可能会越长。如果你正在运行一个分布式的操作,要确认在HBase彻底停止之前,Hadoop不能停.
2.3. 配置文件
HBase的配置系统和Hadoop一样。在
配置系统的部署信息和环境变量。 -- 这个配置会被启动shell使用 -- 然后在XML文件里配置信息,覆盖默认的配置。告知HBase使用什么目录地址,ZooKeeper的位置等等信息。
10
当你使用分布式模式的时间,当你编辑完一个文件之后,记得要把这个文件复制到整个集群的
目录下。HBase不会帮你做这些,你得用
2.3.1. 
hbase-default.xml
正如Hadoop放置HDFS的配置文件
,HBase的配置文件是
你可以在
Section 2.3.1.1, “HBase 默认配置”
找到配置的属性列表。你也可以看有代码里面的
文件,他在
src/main/resources
目录下。
不是所有的配置都在
出现.只要改了代码,配置就有可能改变,所以唯一了解这些被改过的配置的办法是读源代码本身。
要注意的是,要重启集群才能是配置生效。
2.3.1.1. HBase 默认配置
HBase 默认配置
该文档是用hbase默认配置文件生成的,文件源是
这个目录是region server的共享目录,用来持久化HBase。URL需要是'完全正确'的,还要包含文件系统的scheme。例如,要表示hdfs中的'/hbase'目录,namenode 运行在namenode.example.org的9090端口。则需要设置为hdfs://namenode.example.org:9000/hbase。默认情况下HBase是写到/tmp的。不改这个配置,数据会在重启的时候丢失。
默认:
file:///tmp/hbase-${user.name}/hbase
hbase.master.port
HBase的Master的端口.
60000
HBase的运行模式。false是单机模式,true是分布式模式。若为false,HBase和Zookeeper会运行在同一个JVM里面。
false
hbase.tmp.dir
本地文件系统的临时文件夹。可以修改到一个更为持久的目录上。(/tmp会在重启时清除)
默认:${java.io.tmpdir}/hbase-${user.name}
hbase.local.dir
作为本地存储,位于本地文件系统的路径。
默认: ${hbase.tmp.dir}/local/
hbase.master.info.port
HBase Master web 界面端口.
设置为-1 意味着你不想让他运行。
60010
hbase.master.info.bindAddress
HBase Master web 界面绑定的端口
0.0.0.0
hbase.client.write.buffer
HTable客户端的写缓冲的默认大小。这个值越大,需要消耗的内存越大。因为缓冲在客户端和服务端都有实例,所以需要消耗客户端和服务端两个地方的内存。得到的好处是,可以减少RPC的次数。可以这样估算服务器端被占用的内存: hbase.client.write.buffer * hbase.regionserver.handler.count
2097152
hbase.regionserver.port
HBase RegionServer绑定的端口
60020
hbase.regionserver.info.port
HBase RegionServer web 界面绑定的端口
设置为 -1 意味这你不想与运行 RegionServer 界面.
60030
hbase.regionserver.info.port.auto
Master或RegionServer是否要动态搜一个可以用的端口来绑定界面。当hbase.regionserver.info.port已经被占用的时候,可以搜一个空闲的端口绑定。这个功能在测试的时候很有用。默认关闭。
hbase.regionserver.info.bindAddress
HBase RegionServer web 界面的IP地址
hbase.regionserver.class
RegionServer 使用的接口。客户端打开代理来连接region server的时候会使用到。
org.apache.hadoop.hbase.ipc.HRegionInterface
hbase.client.pause
通常的客户端暂停时间。最多的用法是客户端在重试前的等待时间。比如失败的get操作和region查询操作等都很可能用到。
1000
hbase.client.retries.number
最大重试次数。所有需重试操作的最大值。例如从root region服务器获取root region,Get单元值,行Update操作等等。这是最大重试错误的值。  默认: 10.
hbase.bulkload.retries.number
最大重试次数。 原子批加载尝试的迭代最大次数。 0 永不放弃。默认: 0.
默认: 0
hbase.client.scanner.caching
当调用Scanner的next方法,而值又不在缓存里的时候,从服务端一次获取的行数。越大的值意味着Scanner会快一些,但是会占用更多的内存。当缓冲被占满的时候,next方法调用会越来越慢。慢到一定程度,可能会导致超时。例如超过了hbase.regionserver.lease.period。
默认: 100
hbase.client.keyvalue.maxsize
一个KeyValue实例的最大size.这个是用来设置存储文件中的单个entry的大小上界。因为一个KeyValue是不能分割的,所以可以避免因为数据过大导致region不可分割。明智的做法是把它设为可以被最大region size整除的数。如果设置为0或者更小,就会禁用这个检查。默认10MB。
10485760
hbase.regionserver.lease.period
客户端租用HRegion server 期限,即超时阀值。单位是毫秒。默认情况下,客户端必须在这个时间内发一条信息,否则视为死掉。
hbase.regionserver.handler.count
RegionServers受理的RPC Server实例数量。对于Master来说,这个属性是Master受理的handler数量
hbase.regionserver.msginterval
RegionServer 发消息给 Master 时间间隔,单位是毫秒
3000
hbase.regionserver.optionallogflushinterval
将Hlog同步到HDFS的间隔。如果Hlog没有积累到一定的数量,到了时间,也会触发同步。默认是1秒,单位毫秒。
hbase.regionserver.regionSplitLimit
region的数量到了这个值后就不会在分裂了。这不是一个region数量的硬性限制。但是起到了一定指导性的作用,到了这个值就该停止分裂了。默认是MAX_INT.就是说不阻止分裂。
2147483647
hbase.regionserver.logroll.period
提交commit log的间隔,不管有没有写足够的值。
3600000
hbase.regionserver.hlog.reader.impl
HLog file reader 的实现.
org.apache.hadoop.hbase.regionserver.wal.SequenceFileLogReader
hbase.regionserver.hlog.writer.impl
HLog file writer 的实现.
org.apache.hadoop.hbase.regionserver.wal.SequenceFileLogWriter
hbase.regionserver.nbreservationblocks
储备的内存block的数量(译者注:就像石油储备一样)。当发生out of memory 异常的时候,我们可以用这些内存在RegionServer停止之前做清理操作。
hbase.zookeeper.dns.interface
当使用DNS的时候,Zookeeper用来上报的IP地址的网络接口名字。
default
hbase.zookeeper.dns.nameserver
当使用DNS的时候,Zookeepr使用的DNS的域名或者IP 地址,Zookeeper用它来确定和master用来进行通讯的域名.
当使用DNS的时候,RegionServer用来上报的IP地址的网络接口名字。
当使用DNS的时候,RegionServer使用的DNS的域名或者IP 地址,RegionServer用它来确定和master用来进行通讯的域名.
hbase.master.dns.interface
当使用DNS的时候,Master用来上报的IP地址的网络接口名字。
hbase.master.dns.nameserver
当使用DNS的时候,RegionServer使用的DNS的域名或者IP 地址,Master用它来确定用来进行通讯的域名.
hbase.balancer.period
Master执行region balancer的间隔。
300000
hbase.regions.slop
当任一区域服务器有average + (average * slop)个分区,将会执行重新均衡。默认 20% slop .
默认:0.2
hbase.master.logcleaner.ttl
Hlog存在于.oldlogdir 文件夹的最长时间,
超过了就会被 Master 的线程清理掉.
600000
hbase.master.logcleaner.plugins
LogsCleaner服务会执行的一组LogCleanerDelegat。值用逗号间隔的文本表示。这些WAL/HLog cleaners会按顺序调用。可以把先调用的放在前面。你可以实现自己的LogCleanerDelegat,加到Classpath下,然后在这里写下类的全称。一般都是加在默认值的前面。
org.apache.hadoop.hbase.master.TimeToLiveLogCleaner
hbase.regionserver.global.memstore.upperLimit
单个region server的全部memtores的最大值。超过这个值,一个新的update操作会被挂起,强制执行flush操作。
0.4
hbase.regionserver.global.memstore.lowerLimit
当强制执行flush操作的时候,当低于这个值的时候,flush会停止。默认是堆大小的 35% .
如果这个值和 hbase.regionserver.global.memstore.upperLimit 相同就意味着当update操作因为内存限制被挂起时,会尽量少的执行flush(译者注:一旦执行flush,值就会比下限要低,不再执行)
0.35
hbase.server.thread.wakefrequency
service工作的sleep间隔,单位毫秒。
可以作为service线程的sleep间隔,比如log roller.
10000
hbase.server.versionfile.writeattempts
退出前尝试写版本文件的次数。每次尝试由 hbase.server.thread.wakefrequency 毫秒数间隔。
默认: 3
hbase.hregion.memstore.flush.size
当memstore的大小超过这个值的时候,会flush到磁盘。这个值被一个线程每隔hbase.server.thread.wakefrequency检查一下。
默认:134217728
hbase.hregion.preclose.flush.size
当一个region中的memstore的大小大于这个值的时候,我们又触发了close.会先运行“pre-flush”操作,清理这个需要关闭的memstore,然后将这个region下线。当一个region下线了,我们无法再进行任何写操作。如果一个memstore很大的时候,flush操作会消耗很多时间。"pre-flush"操作意味着在region下线之前,会先把memstore清空。这样在最终执行close操作的时候,flush操作会很快。
5242880
hbase.hregion.memstore.block.multiplier
如果memstore有hbase.hregion.memstore.block.multiplier倍数的hbase.hregion.flush.size的大小,就会阻塞update操作。这是为了预防在update高峰期会导致的失控。如果不设上界,flush的时候会花很长的时间来合并或者分割,最坏的情况就是引发out of memory异常。(译者注:内存操作的速度和磁盘不匹配,需要等一等。原文似乎有误)
hbase.hregion.memstore.mslab.enabled
体验特性:启用memStore分配本地缓冲区。这个特性是为了防止在大量写负载的时候堆的碎片过多。这可以减少GC操作的频率。(GC有可能会Stop the world)(译者注:实现的原理相当于预分配内存,而不是每一个值都要从堆里分配)
hbase.hregion.max.filesize
最大HStoreFile大小。若某个列族的HStoreFile增长达到这个值,这个Hegion会被切割成两个。
默认: 10G.
默认:10737418240
hbase.hstore.compactionThreshold
当一个HStore含有多于这个值的HStoreFiles(每一个memstore flush产生一个HStoreFile)的时候,会执行一个合并操作,把这HStoreFiles写成一个。这个值越大,需要合并的时间就越长。
hbase.hstore.blockingStoreFiles
当一个HStore含有多于这个值的HStoreFiles(每一个memstore flush产生一个HStoreFile)的时候,会执行一个合并操作,update会阻塞直到合并完成,直到超过了hbase.hstore.blockingWaitTime的值
hbase.hstore.blockingWaitTime
hbase.hstore.blockingStoreFiles所限制的StoreFile数量会导致update阻塞,这个时间是来限制阻塞时间的。当超过了这个时间,HRegion会停止阻塞update操作,不过合并还有没有完成。默认为90s.
90000
hbase.hstore.compaction.max
每个“小”合并的HStoreFiles最大数量。
hbase.hregion.majorcompaction
一个Region中的所有HStoreFile的major compactions的时间间隔。默认是1天。
设置为0就是禁用这个功能。
86400000
hbase.storescanner.parallel.seek.enable
允许 StoreFileScanner 并行搜索 StoreScanner, 一个在特定条件下降低延迟的特性。
默认: false
hbase.storescanner.parallel.seek.threads
并行搜索特性打开后,默认线程池大小。
默认: 10
hbase.mapreduce.hfileoutputformat.blocksize
MapReduce中HFileOutputFormat可以写 storefiles/hfiles.
这个值是hfile的blocksize的最小值。通常在HBase写Hfile的时候,bloocksize是由table schema(HColumnDescriptor)决定的,但是在mapreduce写的时候,我们无法获取schema中blocksize。这个值越小,你的索引就越大,你随机访问需要获取的数据就越小。如果你的cell都很小,而且你需要更快的随机访问,可以把这个值调低。
65536
hfile.block.cache.size
分配给HFile/StoreFile的block cache占最大堆(-Xmx setting)的比例。默认0.25意思是分配25%,设置为0就是禁用,但不推荐。
默认:0.25
hbase.hash.type
哈希函数使用的哈希算法。可以选择两个值:: murmur (MurmurHash) 和 jenkins (JenkinsHash).
这个哈希是给 bloom filters用的.
murmur
hfile.block.index.cacheonwrite
这允许在写入索引时将非根多级索引块写入到块缓存。
hfile.index.block.max.size
当多层次块索引中的叶级、中间层或根级索引块的大小增长到这个大小时,该块将被写入,并开始一个新的块。
默认: 131072
hfile.format.version
新文件使用的HFile格式版本。设置为1来测试向后兼容性。此选项的默认值应符合FixedFileTrailer.MAX_VERSION.
默认: 2
io.storefile.bloom.block.size
复合Bloom滤波器的单个块(“chunk”)的字节大小。这个大小是近似的,因为Bloom块只能在数据块边界中插入,并且每个数据块的键数是不同的。
hfile.block.bloom.cacheonwrite
允许对复合布鲁姆过滤器的内联块写缓存.
hbase.rs.cacheblocksonwrite
块结束时,是否 HFile块应添加块缓存。
hbase.rpc.server.engine
用于服务器的RPC调用编组的org.apache.hadoop.hbase.ipc.RpcServerEngine 实现.
默认: org.apache.hadoop.hbase.ipc.ProtobufRpcServerEngine
hbase.ipc.client.tcpnodelay
设置RPC套接字连接不延迟。参考 http://docs.oracle.com/javase/1.5.0/docs/api/java/net/Socket.html#getTcpNoDelay()
默认: true
hbase.master.keytab.file
HMaster server验证登录使用的kerberos keytab 文件路径。(译者注:HBase使用Kerberos实现安全)
hbase.master.kerberos.principal
例如. "hbase/_HOST@EXAMPLE.COM".
HMaster运行需要使用 kerberos principal name.
principal name 可以在: user/hostname@DOMAIN 中获取. 如果 "_HOST" 被用做hostname
portion,需要使用实际运行的hostname来替代它。
hbase.regionserver.keytab.file
HRegionServer验证登录使用的kerberos keytab 文件路径。
hbase.regionserver.kerberos.principal
HRegionServer运行需要使用 kerberos principal name.
portion,需要使用实际运行的hostname来替代它。在这个文件中必须要有一个entry来描述 hbase.regionserver.keytab.file
hadoop.policy.file
RPC服务器使用策略配置文件对客户端请求做出授权决策。仅当HBase启用了安全设置可用.
默认: hbase-policy.xml
hbase.superuser
拥有完整的特权用户或组的列表(逗号分隔), 不限于本地存储的 ACLs, 或整个集群. 仅当HBase启用了安全设置可用.
hbase.auth.key.update.interval
The update interval for master key for authentication tokens in servers in milliseconds. Only used when HBase security is enabled.
默认: 86400000
hbase.auth.token.max.lifetime
The maximum lifetime in milliseconds after which an authentication token expires. Only used when HBase security is enabled.
默认: 604800000
zookeeper.session.timeout
ZooKeeper 会话超时.HBase把这个值传递改zk集群,向他推荐一个会话的最大超时时间。详见http://hadoop.apache.org/zookeeper/docs/current/zookeeperProgrammers.html#ch_zkSessions
"客户端发送请求超时,服务器响应它可以给客户端的超时"。
单位是毫秒
180000
zookeeper.znode.parent
ZooKeeper中的HBase的根ZNode。所有的HBase的ZooKeeper会用这个目录配置相对路径。默认情况下,所有的HBase的ZooKeeper文件路径是用相对路径,所以他们会都去这个目录下面。
zookeeper.znode.rootserver
ZNode 保存的 根region的路径. 这个值是由Master来写,client和regionserver 来读的。如果设为一个相对地址,父目录就是 ${zookeeper.znode.parent}.默认情形下,意味着根region的路径存储在/hbase/root-region-server.
root-region-server
zookeeper.znode.acl.parent
Root ZNode for access control lists.
默认: acl
hbase.coprocessor.region.classes
一个逗号分隔的协处理器,通过在所有表的默认加载列表。对于任何重写协处理器方法,这些类将按顺序调用。实现你自己的协处理器后,就把它放在HBase的路径,在此添加完全限定名称。协处理器也可以装上设置HTableDescriptor需求。
hbase.coprocessor.master.classes
一个逗号分隔的org.apache.hadoop.hbase.coprocessor.MasterObserver 微处理器列表,主HMaster进程默认加载。对于任何实现的协处理器方法,列出的类将按顺序调用。实现你自己的MasterObserver后,就把它放在HBase的路径,在此处添加完全限定名称(fully qualified class name)。
hbase.zookeeper.quorum
Zookeeper集群的地址列表,用逗号分割。例如:"host1.mydomain.com,host2.mydomain.com,host3.mydomain.com".默认是localhost,是给伪分布式用的。要修改才能在完全分布式的情况下使用。如果在hbase-env.sh设置了HBASE_MANAGES_ZK,这些ZooKeeper节点就会和HBase一起启动。
hbase.zookeeper.peerport
ZooKeeper节点使用的端口。详细参见:http://hadoop.apache.org/zookeeper/docs/r3.1.1/zookeeperStarted.html#sc_RunningReplicatedZooKeeper
2888
hbase.zookeeper.leaderport
ZooKeeper用来选择Leader的端口,详细参见:http://hadoop.apache.org/zookeeper/docs/r3.1.1/zookeeperStarted.html#sc_RunningReplicatedZooKeeper
3888
hbase.zookeeper.useMulti
指示HBase使用ZooKeeper的多更新功能。这让某些管理员操作完成更迅速,防止一些问题与罕见的复制失败的情况下(见例hbase-2611版本说明)。重要的是:只有设置为true,如果集群中的所有服务器上的管理员3.4版本不会被降级。ZooKeeper管理员3.4之前的版本不支持多更新不优雅地失败如果多更新时把它放在HBase的路径,在这里添加完全限定名称。 (参考 ZOOKEEPER-1495).
hbase.zookeeper.property.initLimit
ZooKeeper的zoo.conf中的配置。
初始化synchronization阶段的ticks数量限制
hbase.zookeeper.property.syncLimit
发送一个请求到获得承认之间的ticks的数量限制
hbase.zookeeper.property.dataDir
快照的存储位置
${hbase.tmp.dir}/zookeeper
hbase.zookeeper.property.clientPort
客户端连接的端口
2181
hbase.zookeeper.property.maxClientCnxns
ZooKeeper集群中的单个节点接受的单个Client(以IP区分)的请求的并发数。这个值可以调高一点,防止在单机和伪分布式模式中出问题。
300
hbase.rest.port
HBase REST server的端口
8080
hbase.rest.readonly
定义REST server的运行模式。可以设置成如下的值:
false: 所有的HTTP请求都是被允许的 - GET/PUT/POST/DELETE.
true:只有GET请求是被允许的
hbase.defaults.for.version.skip
设置为true,跳过 'hbase.defaults.for.version' 检查。 设置为 true 相对maven 生成很有用,例如ide环境. 你需要将该布尔值设为 true,避免看到RuntimException 抱怨: "hbase-default.xml file seems to be for and old version of HBase (\${hbase.version}), this version is X.X.X-SNAPSHOT"
hbase.coprocessor.abortonerror
Set to true to cause the hosting server (master or regionserver) to abort if a coprocessor throws a Throwable object that is not IOException or a subclass of IOException. Setting it to true might be useful in development environments where one wants to terminate the server as soon as possible to simplify coprocessor failure analysis.
hbase.online.schema.update.enable
Set true to enable online schema changes. This is an experimental feature. There are known issues modifying table schemas at the same time a region split is happening so your table needs to be quiescent or else you have to be running with splits disabled.
hbase.table.lock.enable
Set to true to enable locking the table in zookeeper for schema change operations. Table locking from master prevents concurrent schema modifications to corrupt table state.
dfs.support.append
Does HDFS allow appends to files? This is an hdfs config. set in here so the hdfs client will do append support. You must ensure that this config. is true serverside too when running hbase (You will have to restart your cluster after setting it).
hbase.thrift.minWorkerThreads
The "core size" of the thread pool. New threads are created on every connection until this many threads are created.
默认: 16
hbase.thrift.maxWorkerThreads
The maximum size of the thread pool. When the pending request queue overflows, new threads are created until their number reaches this number. After that, the server starts dropping connections.
默认: 1000
hbase.thrift.maxQueuedRequests
The maximum number of pending Thrift connections waiting in the queue. If there are no idle threads in the pool, the server queues requests. Only when the queue overflows, new threads are added, up to hbase.thrift.maxQueuedRequests threads.
hbase.offheapcache.percentage
The amount of off heap space to be allocated towards the experimental off heap cache. If you desire the cache to be disabled, simply set this value to 0.
hbase.data.umask.enable
Enable, if true, that file permissions should be assigned to the files written by the regionserver
hbase.data.umask
hbase.data.umask.enable为真时,用于写数据文件文件的权限
默认: 000
hbase.metrics.showTableName
Whether to include the prefix "tbl.tablename" in per-column family metrics. If true, for each metric M, per-cf metrics will be reported for tbl.T.cf.CF.M, if false, per-cf metrics will be aggregated by column-family across tables, and reported for cf.CF.M. In both cases, the aggregated metric M across tables and cfs will be reported.
hbase.metrics.exposeOperationTimes
是否报告有关在区域服务器上执行操作的时间的度量。 Get, Put, Delete, Increment, 及 Append 都可以有他们的时间,每CF和每个区域都可以通过Hadoop metrics暴露出来。
hbase.master.hfilecleaner.plugins
一个以逗号分隔的HFileCleanerDelegate HFileCleaner调用的服务。这些HFile清除服务被按顺序调用,所以把清除大部分文件的清除服务放在最前面。实现自己的HFileCleanerDelegate,需把它放在HBase的类路径,并在此添加完全限定类名。总是添加上述日志清除服务,因为会被hbase-site.xml的配置覆盖。
默认: org.apache.hadoop.hbase.master.cleaner.TimeToLiveHFileCleaner
hbase.regionserver.catalog.timeout
Catalog Janitor从regionserver到 META的超时值.
默认: 600000
hbase.master.catalog.timeout
Catalog Janitor从master到 META的超时值.
hbase.config.read.zookeeper.config
设置为true,允许HBaseConfiguration读取 zoo.cfg 文件,获取ZooKeeper配置。切换为true是不推荐的,因为从zoo.cfg文件读取ZK配置功能已废弃。
hbase.snapshot.enabled
设置为true允许快照被取/恢复/克隆。
hbase.rest.threads.max
REST服务器线程池的最大线程数。池中的线程被重用以处理REST请求。该值控制同时处理的最大请求数。这可能有助于控制REST服务器内存,避免OOM问题。如果线程池已满,传入的请求将被排队等待一些空闲线程。默认值是100.
默认: 100
hbase.rest.threads.min
REST服务器线程池的最小线程数。线程池始终具有该数量的线程,以便REST服务器准备好为传入的请求服务。默认值是 2.
2.3.2. 
在这个文件里面设置HBase环境变量。比如可以配置JVM启动的堆大小或者GC的参数。你还可在这里配置HBase的参数,如Log位置,niceness(译者注:优先级),ssh参数还有pid文件的位置等等。打开文件
细读其中的内容。每个选项都是有详尽的注释的。你可以在此添加自己的环境变量。
这个文件的改动系统HBase重启才能生效。
2.3.3. 
log4j.properties
编辑这个文件可以改变HBase的日志的级别,轮滚策略等等。
日志级别的更改会影响到HBase UI
2.3.4. 连接HBase集群的客户端配置和依赖
因为HBase的Master有可能转移,所有客户端需要访问ZooKeeper来获得现在的位置。ZooKeeper会保存这些值。因此客户端必须知道Zookeeper集群的地址,否则做不了任何事情。通常这个地址存在
里面,客户端可以从
CLASSPATH
取出这个文件.
如果你是使用一个IDE来运行HBase客户端,你需要将
conf/
放入你的 classpath,这样
就可以找到了,(或者把hbase-site.xml放到
src/test/resources
,这样测试的时候可以使用).
HBase客户端最小化的依赖是 hbase, hadoop, log4j, commons-logging, commons-lang,
和 ZooKeeper ,这些jars 需要能在
中找到。
下面是一个基本的客户端
例子:
<value>example1,example2,example3</value>
<description>The directory shared by region servers.
2.3.4.1. Java客户端配置
Java是如何读到
的内容的
Java客户端使用的配置信息是被映射在一个
HBaseConfiguration
实例中.
HBaseConfiguration有一个工厂方法,
HBaseConfiguration.create();
,运行这个方法的时候,他会去
,下找
,读他发现的第一个配置文件的内容。
(这个方法还会去找
hbase.X.X.X.jar
里面也会有一个an hbase-default.xml). 不使用任何
文件直接通过Java代码注入配置信息也是可以的。例如,你可以用编程的方式设置ZooKeeper信息,只要这样做:
Configuration config = HBaseConfiguration.create();
config.set("hbase.zookeeper.quorum", "localhost");
// Here we are running zookeeper locally
如果有多ZooKeeper实例,你可以使用逗号列表。(就像在
文件中做得一样).
这个
Configuration
实例会被传递到
HTable
之类的实例里面去.
2.4.1. 简单的分布式HBase安装
这里是一个10节点的HBase的简单示例,这里的配置都是基本的,节点名为
example0
example1
... 一直到
example9
HBase Master 和
HDFS namenode 运作在同一个节点
上.
RegionServers 运行在节点
. 一个 3-节点
ZooKeeper 集群运行在
example2
, 和
example3
,端口保持默认. ZooKeeper 的数据保存在目录
/export/zookeeper
. 下面我们展示主要的配置文件--
-- 这些文件可以在
目录找到.
2.4.1.1. 
<name>hbase.zookeeper.property.dataDir</name>
<value>/export/zookeeper</value>
<description>Property from ZooKeeper's config zoo.cfg.
The directory where the snapshot is stored.
<value>hdfs://example0:9000/hbase</value>
2.4.1.2. 
这个文件把RegionServer的节点列了下来。在这个例子里面我们让所有的节点都运行RegionServer,除了第一个节点
,它要运行 HBase Master 和
HDFS namenode
example4
example5
example6
example7
example8
2.4.1.3. 
下面我们用
diff
命令来展示
文件相比默认变化的部分. 我们把HBase的堆内存设置为4G而不是默认的1G.
$ git diff hbase-env.sh
diff --git a/conf/hbase-env.sh b/conf/hbase-env.sh
index e70ebc6..96f8c27 100644
--- a/conf/hbase-env.sh
+++ b/conf/hbase-env.sh
@@ -31,7 +31,7 @@ export JAVA_HOME=/usr/lib//jvm/java-6-sun/
# export HBASE_CLASSPATH=
# The maximum amount of heap to use, in MB. Default is 1000.
-# export HBASE_HEAPSIZE=1000
+export HBASE_HEAPSIZE=4096
# Extra Java runtime options.
# Below are what we set by default.
May only work with SUN JVM.
你可以使用
来同步
文件夹到你的整个集群.
2.5. 重要的配置
下面我们会列举
重要
的配置. 这个章节讲述必须的配置和那些值得一看的配置。(译者注:淘宝的博客也有本章节的内容,
HBase性能调优
,很详尽)。
2.5.1. 必须的配置
参考 
Section 2.2, “操作系统”
 和 
Section 2.3, “Hadoop”
 节.
2.5.2. 推荐配置
2.5.2.1. zookeeper.session.timeout
这个默认值是3分钟。这意味着一旦一个server宕掉了,Master至少需要3分钟才能察觉到宕机,开始恢复。你可能希望将这个超时调短,这样Master就能更快的察觉到了。在你调这个值之前,你需要确认你的JVM的GC参数,否则一个长时间的GC操作就可能导致超时。(当一个RegionServer在运行一个长时间的GC的时候,你可能想要重启并恢复它).
要想改变这个配置,可以编辑
将配置部署到全部集群,然后重启。
我们之所以把这个值调的很高,是因为我们不想一天到晚在论坛里回答新手的问题。“为什么我在执行一个大规模数据导入的时候Region Server死掉啦”,通常这样的问题是因为长时间的GC操作引起的,他们的JVM没有调优。我们是这样想的,如果一个人对HBase不很熟悉,不能期望他知道所有,打击他的自信心。等到他逐渐熟悉了,他就可以自己调这个参数了。
2.5.2.2.  ZooKeeper 实例个数
Section 2.5, “ZooKeeper”
2.5.2.3. hbase.regionserver.handler.count
这个设置决定了处理用户请求的线程数量。默认是10,这个值设的比较小,主要是为了预防用户用一个比较大的写缓冲,然后还有很多客户端并发,这样region servers会垮掉。有经验的做法是,当请求内容很大(上MB,如大puts, 使用缓存的scans)的时候,把这个值放低。请求内容较小的时候(gets, 小puts, ICVs, deletes),把这个值放大。
当客户端的请求内容很小的时候,把这个值设置的和最大客户端数量一样是很安全的。一个典型的例子就是一个给网站服务的集群,put操作一般不会缓冲,绝大多数的操作是get操作。
把这个值放大的危险之处在于,把所有的Put操作缓冲意味着对内存有很大的压力,甚至会导致OutOfMemory.一个运行在内存不足的机器的RegionServer会频繁的触发GC操作,渐渐就能感受到停顿。(因为所有请求内容所占用的内存不管GC执行几遍也是不能回收的)。一段时间后,集群也会受到影响,因为所有的指向这个region的请求都会变慢。这样就会拖累集群,加剧了这个问题。
你可能会对handler太多或太少有感觉,可以通过 
Section 12.2.2.1, “启用 RPC级 日志”
 ,在单个RegionServer启动log并查看log末尾 (请求队列消耗内存)。
2.5.2.4. 
大内存机器的配置
HBase有一个合理的保守的配置,这样可以运作在所有的机器上。如果你有台大内存的集群-HBase有8G或者更大的heap,接下来的配置可能会帮助你. TODO.
2.5.2.5. 压缩
应该考虑启用ColumnFamily 压缩。有好几个选项,通过降低存储文件大小以降低IO,降低消耗且大多情况下提高性能。
Appendix C, 
HBase压缩
 获取更多信息.
2.5.2.6. 较大 Regions
更大的Region可以使你集群上的Region的总数量较少。
一般来言,更少的Region可以使你的集群运行更加流畅。(你可以自己随时手工将大Region切割,这样单个热点Region就会被分布在集群的更多节点上)。
较少的Region较好。一般每个RegionServer在20到小几百之间。 调整Region大小以适合该数字。
0.90.x 版本, 默认情况下单个Region是256MB。Region 大小的上界是 4Gb.
0.92.x 版本, 由于 HFile v2 已经将Region大小支持得大很多, (如, 20Gb).
可能需要实验,基于硬件和应用需要进行配置。
可以调整
属性. RegionSize 也可以基于每个表设置:  
HTableDescriptor
2.5.2.7. 
管理
Splitting
除了让HBase自动切割你的Region,你也可以手动切割。
12
随着数据量的增大,splite会被持续执行。如果你需要知道你现在有几个region,比如长时间的debug或者做调优,你需要手动切割。通过跟踪日志来了解region级的问题是很难的,因为他在不停的切割和重命名。data offlineing bug和未知量的region会让你没有办法。如果一个
HLog
StoreFile
由于一个奇怪的bug,HBase没有执行它。等到一天之后,你才发现这个问题,你可以确保现在的regions和那个时候的一样,这样你就可以restore或者replay这些数据。你还可以调优你的合并算法。如果数据是均匀的,随着数据增长,很容易导致split / compaction疯狂的运行。因为所有的region都是差不多大的。用手的切割,你就可以交错执行定时的合并和切割操作,降低IO负载。
为什么我关闭自动split呢?因为自动的splite是配置文件中的
决定的. 你把它设置成
Long.MAX_VALUE
是不推荐的做法,要是你忘记了手工切割怎么办.推荐的做法是设置成100GB,一旦到达这样的值,至少需要一个小时执行 major compactions。
那什么是最佳的在pre-splite regions的数量呢。这个决定于你的应用程序了。你可以先从低的开始,比如每个server10个pre-splite regions.然后花时间观察数据增长。有太少的region至少比出错好,你可以之后再rolling split.一个更复杂的答案是这个值是取决于你的region中的最大的storefile。随着数据的增大,这个也会跟着增大。 你可以当这个文件足够大的时候,用一个定时的操作使用
Store
的合并选择算法(compact selection algorithm)来仅合并这一个HStore。如果你不这样做,这个算法会启动一个 major compactions,很多region会受到影响,你的集群会疯狂的运行。需要注意的是,这样的疯狂合并操作是数据增长造成的,而不是手动分割操作决定的。
如果你 pre-split 导致 regions 很小,你可以通过配置
HConstants.MAJOR_COMPACTION_PERIOD
把你的major compaction参数调大
如果你的数据变得太大,可以使用
org.apache.hadoop.hbase.util.RegionSplitter
脚本来执行针对全部集群的一个网络IO安全的rolling split操作。
2.5.2.8. 
Compactions
通常管理技术是手动管理主紧缩(major compactions), 而不是让HBase 来做。 缺省HConstants.MAJOR_COMPACTION_PERIOD 是一天。主紧缩可能强行进行,在你并不太希望发生的时候——特别是在一个繁忙系统。关闭自动主紧缩,设置该值为0.
重点强调,主紧缩对存储文件(StoreFile)清理是绝对必要的。唯一变量是发生的时间。可以通过HBase shell进行管理,或通过 
HBaseAdmin
更多信息关于紧缩和紧缩文件选择过程,参考 
Section 9.7.5.5, “紧缩”
2.5.2.9. 
预测执行
(Speculative Execution)
MapReduce任务的预测执行缺省是打开的,HBase集群一般建议在系统级关闭预测执行,除非在某种特殊情况下需要打开,此时可以每任务配置。设置mapred.map.tasks.speculative.execution 和 mapred.reduce.tasks.speculative.execution 为 false.
2.5.3. 其他配置
2.5.3.1. 负载均衡
负载均衡器(LoadBalancer)是在主服务器上运行的定期操作,以重新分布集群区域。通过hbase.balancer.period 设置,缺省值300000 (5 分钟).
Section 9.5.4.1, “负载均衡”
 获取关于负载均衡器( LoadBalancer )的更多信息。
2.5.3.2. 禁止块缓存(Blockcache)
不要关闭块缓存 (通过hbase.block.cache.size 为 0 来设置)。当前如果关闭块缓存会很不好,因为区域服务器会花很多时间不停加载hfile指数。如果工作集如此配置块缓存没有好处,最少应保证hfile指数保存在块缓存内的大小(可以通过查询区域服务器的UI,得到大致的数值。可以看到网页的上方有块指数值统计).
2.5.3.3. 
Nagle算法
 或小包问题
如果操作HBase时看到大量40ms左右的偶然延时,尝试Nagles配置。如,参考用户邮件列表线索, 
Inconsistent scan performance with caching set to 1
 ,该议题在其中启用tcpNoDelay (译者注,本英文原文notcpdelay有误)提高了扫描速度。你也可以查看该文档的尾部图表
:HBASE-7008 Set scanner caching to a better default
  (xie liang),我们的Lars Hofhansl 尝试了各种不同的数据大小,Nagle打开或关闭的测量结果。
] Be careful editing XML. Make sure you close all elements. Run your file through 
 or similar to ensure well-formedness of your document after an edit session.
] The 
hadoop-dns-checker
 tool can be used to verify DNS is working correctly on the cluster. The project README file provides detailed instructions on usage.
] 参考 Jack Levin's 
major hdfs issues
 note up on the user list.
] The requirement that a database requires upping of system limits is not peculiar to HBase. 参考 for example the section 
Setting Shell Limits for the Oracle User
 in
Short Guide to install Oracle 10 on Linux
] A useful read setting config on you hadoop cluster is Aaron Kimballs' Configuration Parameters: What can you just ignore?
] <title>On Hadoop Versions</title>
] The Cloudera blog post 
An update on Apache Hadoop 1.0
 by Charles Zedlweski has a nice exposition on how all the Hadoop versions relate. Its worth checking out if you are having trouble making sense of the Hadoop version morass.
] Until recently only the 
branch-0.20-append
 branch had a working sync but no official release was ever made from this branch. You had to build it yourself. Michael Noll wrote a detailed blog, 
Building an Hadoop 0.20.x version for HBase 0.90.2
, on how to build an Hadoop from branch-0.20-append. Recommended.
] Praveen Kumar has written a complimentary article, 
Building Hadoop and HBase for HBase Maven application development
] dfs.support.append
] 参考 
Hadoop HDFS: Deceived by Xciever
 for an informative rant on xceivering.
11
] The pseudo-distributed vs fully-distributed nomenclature comes from Hadoop.
Section 2.4.2.1.2, “Pseudo-distributed Extras”
 for notes on how to start extra Masters and RegionServers when running pseudo-distributed.
13
] 对 ZooKeeper 全部配置,参考ZooKeeper 的
zoo.cfg
. HBase 没有包含
,所以需要浏览合适的独立ZooKeeper下载版本的
目录找到。
14
] 下面是来自org.apache.hadoop.hbase.util.RegionSplitter的javadoc的文件头。自HBase post-0.90.0版添加。
Chapter 3. 升级
不能跳过主要版本升级。如果想从0.20.x 升级到 0.92.x,必须从0.20.x 升级到 0.90.x ,再从0.90.x 升级到 0.92.x.
参见
, 需要特别注意有关Hadoop 版本的信息.
3.1. 从 0.94.x 升级到 0.96.x
奇点
You will have to stop your old 0.94 cluster completely to upgrade. If you are replicating between clusters, both clusters will have to go down to upgrade. Make sure it is a clean shutdown so there are no WAL files laying around (TODO: Can 0.96 read 0.94 WAL files?). Make sure zookeeper is cleared of state. All clients must be upgraded to 0.96 too.
The API has changed in a few areas; in particular how you use coprocessors (TODO: MapReduce too?)
3.2. 从 0.92.x 升级到 0.94.x
0.92 和 0.94 接口兼容,可平滑升级。
3.3. 从 0.90.x 到 0.92.x 升级
升级指引
You will find that 0.92.0 runs a little differently to 0.90.x releases. Here are a few things to watch out for upgrading from 0.90.x to 0.92.0.
If you've not patience, here are the important things to know upgrading.
Once you upgrade, you can’t go back.
MSLAB is on by default. Watch that heap usage if you have a lot of regions.
Distributed splitting is on by defaul. It should make region server failover faster.
There’s a separate tarball for security.
If -XX:MaxDirectMemorySize is set in your hbase-env.sh, it’s going to enable the experimental off-heap cache (You may not want this).
3.3.1. 不可回退!
To move to 0.92.0, all you need to do is shutdown your cluster, replace your hbase 0.90.x with hbase 0.92.0 binaries (be sure you clear out all 0.90.x instances) and restart (You cannot do a rolling restart from 0.90.x to 0.92.x -- you must restart). On startup, the .META. table content is rewritten removing the table schema from the info:regioninfo column. Also, any flushes done post first startup will write out data in the new 0.92.0 file format, 
HFile V2
. This means you cannot go back to 0.90.x once you’ve started HBase 0.92.0 over your HBase data directory.
3.3.2. MSLAB 缺省启用
In 0.92.0, the 
 flag is set to true (参考 
Section 11.3.1.1, “Long GC pauses”
). In 0.90.x it was false. When it is enabled, memstores will step allocate memory in MSLAB 2MB chunks even if the memstore has zero or just a few small elements. This is fine usually but if you had lots of regions per regionserver in a 0.90.x cluster (and MSLAB was off), you may find yourself OOME'ing on upgrade because the thousands of regions * number of column families * 2MB MSLAB (at a minimum) puts your heap over the top. Set hbase.hregion.memstore.mslab.enabled to false or set the MSLAB size down from 2MB by setting hbase.hregion.memstore.mslab.chunksize to something less.
3.3.3. 分布式分割缺省启用
Previous, WAL logs on crash were split by the Master alone. In 0.92.0, log splitting is done by the cluster (参考 “HBASE-1364 [performance] Distributed splitting of regionserver commit logs”). This should cut down significantly on the amount of time it takes splitting logs and getting regions back online again.
3.3.4. 内存计算改变
In 0.92.0, 
Appendix E, 
HFile format version 2
 indices and bloom filters take up residence in the same LRU used caching blocks that come from the filesystem. In 0.90.x, the HFile v1 indices lived outside of the LRU so they took up space even if the index was on a ‘cold’ file, one that wasn’t being actively used. With the indices now in the LRU, you may find you have less space for block caching. Adjust your block cache accordingly. 参考 the 
Section 9.6.4, “Block Cache”
 for more detail. The block size default size has been changed in 0.92.0 from 0.2 (20 percent of heap) to 0.25.
3.3.5.  可用 Hadoop 版本
Run 0.92.0 on Hadoop 1.0.x (or CDH3u3 when it ships). The performance benefits are worth making the move. Otherwise, our Hadoop prescription is as it has been; you need an Hadoop that supports a working sync. 参考 
If running on Hadoop 1.0.x (or CDH3u3), enable local read. 参考 
Practical Caching
 presentation for ruminations on the performance benefits ‘going local’ (and for how to enable local reads).
3.3.6. HBase 0.92.0 带 ZooKeeper 3.4.2
If you can, upgrade your zookeeper. If you can’t, 3.4.2 clients should work against 3.3.X ensembles (HBase makes use of 3.4.2 API).
3.3.7. 在线切换缺省关闭
In 0.92.0, we’ve added an experimental online schema alter facility (参考 
). Its off by default. Enable it at your own risk. Online alter and splitting tables do not play well together so be sure your cluster quiescent using this feature (for now).
3.3.8. WebUI
The webui has had a few additions made in 0.92.0. It now shows a list of the regions currently transitioning, recent compactions/flushes, and a process list of running processes (usually empty if all is well and requests are being handled promptly). Other additions including requests by region, a debugging servlet dump, etc.
3.3.9. 安全 tarball
我们发布两个tarball: 安全和非安全 HBase. 如何设置安全HBase的文档正在制定中。
3.3.10. 试验离堆(off-heap)缓存
(译者注:on-heap和off-heap是Terracotta 公司提出的概念。on-heap指java对象在GC内存储管理,效率较高,但GC只能管理2G内存,有时成为性能瓶颈。off-heap又叫
BigMemory
,是JVM的GC机制的替代,在GC外存储,100倍速于DiskStore,cache量目前(2012年底)达到350GB)
A new cache was contributed to 0.92.0 to act as a solution between using the “on-heap” cache which is the current LRU cache the region servers have and the operating system cache which is out of our control. To enable, set “-XX:MaxDirectMemorySize” in hbase-env.sh to the value for maximum direct memory size and specify hbase.offheapcache.percentage in hbase-site.xml with the percentage that you want to dedicate to off-heap cache. This should only be set for servers and not for clients. Use at your own risk. See this blog post for additional information on this new experimental feature: http://www.cloudera.com/blog/2012/01/caching-in-hbase-slabcache/
3.3.11. HBase 复制的变动
0.92.0 adds two new features: multi-slave and multi-master replication. The way to enable this is the same as adding a new peer, so in order to have multi-master you would just run add_peer for each cluster that acts as a master to the other slave clusters. Collisions are handled at the timestamp level which may or may not be what you want, this needs to be evaluated on a per use case basis. Replication is still experimental in 0.92 and is disabled by default, run it at your own risk.
3.3.12. 对OOME ,RegionServer 现在退出
If an OOME, we now have the JVM kill -9 the regionserver process so it goes down fast. Previous, a RegionServer might stick around after incurring an OOME limping along in some wounded state. To disable this facility, and recommend you leave it in place, you’d need to edit the bin/hbase file. Look for the addition of the -XX:OnOutOfMemoryError="kill -9 %p" arguments (参考 [HBASE-4769] - ‘Abort RegionServer Immediately on OOME’)
3.3.13. HFile V2 和 “更大, 更少” 趋势
0.92.0 stores data in a new format, 
. As HBase runs, it will move all your data from HFile v1 to HFile v2 format. This auto-migration will run in the background as flushes and compactions run. HFile V2 allows HBase run with larger regions/files. In fact, we encourage that all HBasers going forward tend toward Facebook axiom #1, run with larger, fewer regions. If you have lots of regions now -- more than 100s per host -- you should look into setting your region size up after you move to 0.92.0 (In 0.92.0, default size is not 1G, up from 256M), and then running online merge tool (参考 “HBASE-1621 merge tool should work on online cluster, but disabled table”).
3.4. 从HBase 0.20.x or 0.89.x 升级到 HBase 0.90.x
0.90.x 版本的HBase可以在
HBase 0.20.x 或者 HBase 0.89.x的数据上启动. 不需要转换数据文件,
HBase 0.89.x 和 0.90.x 的region目录名是不一样的 -- 老版本用md5 hash 而不是jenkins hash 来命名region-- 这就意味着,一旦启动,再也不能回退到 HBase 0.20.x.
在升级的时候,一定要将
从你的
目录删掉。
0.20.x 版本的配置对于 0.90.x HBase不是最佳的.
现在已经被打包在
HBase jar 里面了.
如果你想看看这个文件内容,你可以在src目录下
src/main/resources/hbase-default.xml
或者在
Section 2.31.1, “HBase 默认配置”
看到.
最后,如果从0.20.x升级,需要在shell里检查
.META.
schema .
过去,我们推荐用户使用16KB的
MEMSTORE_FLUSHSIZE
在shell中运行
hbase> scan '-ROOT-'
. 会显示当前的
schema.
检查
的大小. 看看是不是 16KB (16384)? 如果是的话,你需要修改它(默认的值是 64MB (67108864))
运行脚本
bin/set_meta_memstore_size.rb
这个脚本会修改
如果不运行的话,集群会比较慢
15
HBASE-3499 Users upgrading to 0.90.0 need to have their .META. table updated with the right MEMSTORE_SIZE
Chapter 4.  HBase Shell
4.1. 使用脚本
4.2. Shell 技巧
4.2.1.
irbrc
4.2.2. LOG 时间转换
4.2.3. 调试
HBase Shell is 在
(J)Ruby
的IRB的基础上加上了HBase的命令。任何你可以在IRB里做的事情都可在在HBase Shell中做。
你可以这样来运行HBase Shell:
就会返回Shell的命令列表和选项。可以看看在Help文档尾部的关于如何输入变量和选项。尤其要注意的是表名,行,列名必须要加引号。
可以看到Shell的基本使用例子。
4.1. 使用脚本
如果要使用脚本,可以看HBase的
bin
目录.在里面找到后缀为
*.rb
的脚本.要想运行这个脚本,要这样
$ ./bin/hbase org.jruby.Main PATH_TO_SCRIPT
就可以了
4.2. Shell 技巧
4.2.1. 
可以在你自己的Home目录下创建一个
.irbrc
文件. 在这个文件里加入自定义的命令。有一个有用的命令就是记录命令历史,这样你就可以把你的命令保存起来。
$ more .irbrc
require 'irb/ext/save-history'
IRB.conf[:SAVE_HISTORY] = 100
IRB.conf[:HISTORY_FILE] = "#{ENV['HOME']}/.irb-save-history"
可以参见
ruby
关于
的文档来学习更多的关于IRB的配置方法。
4.2.2. LOG 时间转换
可以将日期'08/08/16 20:56:29'从hbase log 转换成一个 timestamp, 操作如下:
hbase(main):021:0> import java.text.SimpleDateFormat
hbase(main):022:0> import java.text.ParsePosition
hbase(main):023:0> SimpleDateFormat.new("yy/MM/dd HH:mm:ss").parse("08/08/16 20:56:29", ParsePosition.new(0)).getTime() => 1218920189000
也可以逆过来操作。
hbase(main):021:0> import java.util.Date
hbase(main):022:0> Date.new(1218920189000).toString() => "Sat Aug 16 20:56:29 UTC 2008"
要想把日期格式和HBase log格式完全相同,可以参见文档
SimpleDateFormat
4.2.3. 调试
4.2.3.1. Shell 切换成debug 模式
你可以将shell切换成debug模式。这样可以看到更多的信息。
-- 例如可以看到命令异常的stack trace:
hbase> debug <RETURN>
4.2.3.2. DEBUG log level
想要在shell中看到 DEBUG 级别的 logging ,可以在启动的时候加上
-d
参数.
$ ./bin/hbase shell -d
Chapter 5. 数据模型
5.1. 概念视图
5.2. 物理视图
5.3. 表
5.4. 行
5.7. 版本
5.7.1. HBase的操作(包含版本操作)
5.7.2. 现有的限制
简单来说,应用程序是以表的方式在HBase存储数据的。表是由行和列构成的,所有的列是从属于某一个列族的。行和列的交叉点称之为cell,cell是版本化的。cell的内容是不可分割的字节数组。
表的行键也是一段字节数组,所以任何东西都可以保存进去,不论是字符串或者数字。HBase的表是按key排序的,排序方式之针对字节的。所有的表都必须要有主键-key.
5.1. 概念视图
下面是根据
BigTable
论文稍加修改的例子。
有一个名为
webtable
的表,包含两个列族
:contents
anchor
.在这个例子里面,
有两个列 (
anchor:cssnsi.com
anchor:my.look.ca
),
contents
仅有一列(
contents:html
列名
一个列名是由它的列族前缀和
修饰符(qualifier)
连接而成。例如列
是列族
加冒号(
)加
修饰符
html
组成的。
Table 5.1. 表
Row Key
Time Stamp
ColumnFamily
"com.cnn.www"
t9
anchor:cnnsi.com
= "CNN"
t8
= "CNN.com"
t6
= "<html>..."
t5
t3
5.2. 物理视图
尽管在概念视图里,表可以被看成是一个稀疏的行的集合。但在物理上,它的是区分列族 存储的。新的columns可以不经过声明直接加入一个列族.
Table 5.2. ColumnFamily
Column Family
Table 5.3. ColumnFamily
ColumnFamily "contents:"
值得注意的是在上面的概念视图中空白cell在物理上是不存储的,因为根本没有必要存储。因此若一个请求为要获取
时间的
,他的结果就是空。相似的,若请求为获取
,结果也是空。但是,如果不指明时间,将会返回最新时间的行,每个最新的都会返回。例如,如果请求为获取行键为"com.cnn.www",没有指明时间戳的话,活动的结果是
下的contents:html,
下的
For more information about the internals of how HBase stores data, see 
Section 9.7, “Regions”
5.3. 表
表是在schema声明的时候定义的。
5.4. 行
行键是不可分割的字节数组。行是按字典排序由低到高存储在表中的。一个空的数组是用来标识表空间的起始或者结尾。
5.5. 列族
在HBase是
列族
一些列的集合。一个列族所有列成员是有着相同的前缀。比如,列
courses:history
courses:math
都是 列族
courses
的成员.冒号(:)是列族的分隔符,用来区分前缀和列名。column 前缀必须是可打印的字符,剩下的部分(称为qualify),可以由任意字节数组组成。列族必须在表建立的时候声明。column就不需要了,随时可以新建。
在物理上,一个的列族成员在文件系统上都是存储在一起。因为存储优化都是针对列族级别的,这就意味着,一个colimn family的所有成员的是用相同的方式访问的。
5.6. Cells
{row, column, version}
元组就是一个HBase中的一个
cell
。Cell的内容是不可分割的字节数组。
5.7. 数据模型操作
四个主要的数据模型操作是 Get, Put, Scan, 和 Delete.
通过
<a class="link" href="http://hbase.