Table of Contents generated with DocToc
Standalone 实例包含所有的 HBase 守护进程:
- Master
- RegionServer
- ZooKeeper
HBase 需要安装 JDK。
| HBase Version | JDK 7 | JDK 8 |
|---|---|---|
| 2.0 | Not Supported | yes |
| 1.3 | yes | yes |
| 1.2 | yes | yes |
| 1.1 | yes | Running with JDK 8 will work but is not well tested. |
-
前往Apache Download Mirrors下载 HBase,选择
stable目录下带.bin.tar.gz后缀的二进制文件。 -
解压文件
-
设置
JAVA_HOME环境变量。HBase 提用了一个配置中心:conf/hbase-env.sh,在这里设置环境变量。 -
更改
conf/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>
</configuration>- 启动 HBase
bin/start-hbase.sh。使用jps命令可以查看HMaster进程。
首次使用 HBase
-
连接到 HBase:
hbase shell。 -
查看
help选项。 -
创建表:
create 'test', 'cf'。 -
查看表的信息:
list 'test'。 -
Put数据到表中:put 'test', 'row1', 'cf:a', 'value1'。 -
扫描表中的所有数据:
scan 'test'。 -
取单行数据:
get 'test', 'row1'。 -
Disable 一个表:
disable 'test'。 -
Drop 表:
drop 'test'。 -
退出 HBase Shell:
quit。
关闭 HBase
bin/stop-hbase.sh脚本执行需要几分钟时间,在此之后使用 jps 命令确认进程是否终止。
伪分布模式意味着 HBase 在一台机器上运行HMaster、HRegionServer、ZooKeeper等独立的进程,而 Standalone 模式下所有的后台服务都是运行在一个 JVM 进程中。默认的 hbase.rootdir 为 /tmp/。
-
确保关闭了 HBase。
-
配置 HBase,修改
hbase-site.xml中的配置hbase.cluster.distributed为true。 -
启动 HBase,
bin/start-hbase.sh。 -
检查 HDFS 中 HBase 的目录。
hdfs dfs -ls /hbase。 -
创建表,填充数据。
-
启动和终止一个备用 HMaster 服务器,
local-master-back.sh,终止一一个备用 HMaster,只能kill -9。HMaster 控制着整个 HBase 集群。 -
启动和终止额外的 RegionServer,
local-regionservers.sh start 2 3 4 5和local-regionservers.sh stop 3。 RegionServer 使用 StoreFile 管理数据,直接受 HMaster 领导。通常来说,一台 HRegionServer 运行在一个节点上。一个机器上运行多个 HRegionServer 是伪分布模式。 -
关闭 HBase,
bin/stop-hbase.sh。
一个全分布式的 HBase 集群包括多个节点,每个节点运行一个或多个 HBase 后台服务,包括 primary 和 backup Master、多个 ZooKeeper 节点、多个 RegionServer 节点。
假设有三个节点 node-a、node-b、node-c:
| 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 连接
- node-a 上,生成 ssh key:以
hbase用户登录,ssh-keygen -t rsa。 - 在 node-b 和 node-c 上,创建
~/.ssh目录。 - 将 node-a 的公钥拷贝到 node-b 和 node-c的
.ssh/authorized_keys。 - 测试 ssh 登录。从 node-a 登录其他节点试试。
- 因为 node-b 是备用 Master,将 HBase 的公钥也部署到其他节点。
准备 node-a
-
修改
conf/regionservers,移除localhost,添加 node-b 和 node-c。 -
配置 HBase 使用 node-b 作为备用 master。创建新文件
conf/backup-masters,添加 node-b 的地址。 -
配置 ZooKeeper,参考zookeeper,在 node-a 上,修改
conf/hbase-site.xml:<property> <name>hbase.zookeeper.quorum</name> <value>node-a.example.com,node-b.example.com,node-c.example.com</value> </property> <property> <name>hbase.zookeeper.property.dataDir</name> <value>/usr/local/zookeeper</value> </property>
-
将所有配置中的
localhost替换为 node-a。
准备 node-b 和 node-c
- 下载、解压 HBase。
- 复制 node-a 的配置文件到 node-b 和 node-c。
启动、测试集群
- 确保 HBase 没有在任何节点上运行。
- 启动集群:在 node-a 上,
start-hbase.sh,ZooKeeper 会先启动,接着是 Master,然后是 RegionServer,最后是备用 Master。 - 检查进程是否运行正常:
jps。 - 查看 Web UI。
- 测试节点下线后集群的状态。
更多配置查看 configuration