在Alluxio上运行Apache HBase

Slack Docker Pulls GitHub edit source

该文档介绍如何运行Apache HBase,以能够在不同存储层将HBase的表格存储到Alluxio当中。

前期准备

开始之前你需要安装好Java。同时使用本地模式集群模式构建好Alluxio。

请在Apache HBase Configuration网站上阅读HBase安装说明。

配置

Apache HBase可以通过通用文件系统包装类(可用于Hadoop文件系统)来使用Alluxio。因此,Alluxio的配置主要在HBase配置文件中完成。

hbase-site.xml中设置属性

需要添加以下3个属性到HBase安装的conf目录下的hbase-site.xml文件中(确保这些属性在所有HBase集群节点中都被配置好):

无需在Alluxio中创建/hbase目录,HBase将会创建。

<property>
  <name>fs.alluxio.impl</name>
  <value>alluxio.hadoop.FileSystem</value>
</property>
<property>
  <name>fs.AbstractFileSystem.alluxio.impl</name>
  <value>alluxio.hadoop.AlluxioFileSystem</value>
</property>
<property>
  <name>hbase.rootdir</name>
  <value>alluxio://<ALLUXIO_MASTER_HOSTNAME>:<PORT>/hbase</value>
</property>

分发Alluxio客户端Jar包

接下来需要让Alluxio client jar文件对HBase可用,因为其中包含了配置好的alluxio.hadoop.FileSystem类。 我们建议您从Alluxio下载页面下载tarball。 高级用户也可以选择从源代码中编译得到客户端jar文件。参照编译Alluxio源代码以支持计算框架的 指示,并且在本文中的余下部分使用生成在``路径中的jar文件。

有2种方式实现:

  • /<PATH_TO_ALLUXIO>/client/alluxio-2.6.2-client.jar文件复制到HBase的lib目录下。
  • $HBASE_CLASSPATH环境变量中指定该jar文件的路径(要保证该路径对集群中的所有节点都有效)。例如:
$ export HBASE_CLASSPATH=/<PATH_TO_ALLUXIO>/client/alluxio-2.6.2-client.jar:${HBASE_CLASSPATH}

添加Alluxio site中额外属性到HBase

如果Alluxio site中有任何想要指定给HBase的属性,将其添加到hbase-site.xml。例如, 将alluxio.user.file.writetype.default从默认的MUST_CACHE改为CACHE_THROUGH

<property>
 <name>alluxio.user.file.writetype.default</name>
 <value>CACHE_THROUGH</value>
</property>

在HBase中使用Alluxio

启动HBase

$ ${HBASE_HOME}/bin/start-hbase.sh

访问HBase网址http://<HBASE_MASTER_HOSTNAME>:16010的Web用户界面以确认HBase在Alluxio上运行 (检查HBase Root Directory属性):

HBaseRootDirectory

并且访问Alluxio网址为http://<ALLUXIO_MASTER_HOSTNAME>:19999的Web用户界面,点击 “Browse” 就会看到HBase存储在Alluxio上的文件,包括数据和WALs:

HBaseRootDirectoryOnAlluxio

HBase shell示例

创建一个文本文件simple_test.txt并且将这些命令写进去:

create 'test', 'cf'
for i in Array(0..9999)
 put 'test', 'row'+i.to_s , 'cf:a', 'value'+i.to_s
end
list 'test'
scan 'test', {LIMIT => 10, STARTROW => 'row1'}
get 'test', 'row1'

从HBase最顶层项目目录运行以下命令:

$ bin/hbase shell simple_test.txt

将会看到一些类似这样的输出:

HBaseShellOutput

如果已经安装了Hadoop,可以在HBase shell中运行一个Hadoop功能程序以统计新创建的表的行数:

$ bin/hbase org.apache.hadoop.hbase.mapreduce.RowCounter test

在这个mapreduce作业结束后,会看到如下结果:

HBaseHadoopOutput