前言:
- 在HBase默认只支持对行键rowkey的索引,如果要针对其它的列来进行查询,就只能全表扫描
- 全表扫描: scan + filter的形式(引发出来的问题: 网络传输压力大,客户端压力大.)
1. Apache Phoenix的出现:
解决了:
- 如果每次需要我们开发二级索引来查询数据,这样使用起来很麻烦。再者,查询数据都是HBase Java API,使用起来不是很方便。为了让其他开发人员更容易使用该接口。如果有一种SQL引擎,通过SQL语句来查询数据会更加方便。
- 简而言之: 提供了一种类似SQL的语法来解决我们开发中的问题,而且是对单表进行操作(HBase不支持Join,所以用起来非常简单,而且还大大提高了HBase的性能)
HBase + Phoenix与 Hadoop + Hive:
2. 安装
简介: Phoenix建立在安装好HBase之上,我这里下载好了安装包,直接上传解压
2.1 上传安装包到Linux系统,并解压
cd /export/software
tar -xvzf apache-phoenix-5.0.0-HBase-2.0-bin.tar.gz -C /export/server/
2.2 将phoenix的所有jar包添加到所有HBase RegionServer和Master的复制到HBase的lib目录
# 拷贝jar包到hbase lib目录
cp /export/server/apache-phoenix-5.0.0-HBase-2.0-bin/phoenix-*.jar /export/server/hbase-2.1.0/lib/
# 进入到hbase lib 目录
cd /export/server/hbase-2.1.0/lib/
# 分发jar包到每个HBase 节点
scp phoenix-*.jar node2.xxyl.cn:$PWD ##自己主机配置的域名
scp phoenix-*.jar node3.xxyl.cn:$PWD
3.3 修改配置文件
cd /export/server/hbase-2.1.0/conf/
vim hbase-site.xml
------
# 1. 将以下配置添加到 hbase-site.xml 后边
<!-- 支持HBase命名空间映射 -->
<property>
<name>phoenix.schema.isNamespaceMappingEnabled</name>
<value>true</value>
</property>
<!-- 支持索引预写日志编码 -->
<property>
<name>hbase.regionserver.wal.codec</name>
<value>org.apache.hadoop.hbase.regionserver.wal.IndexedWALEditCodec</value>
</property>
# 2. 将hbase-site.xml分发到每个节点
scp hbase-site.xml node2.xxyl.cn:$PWD
scp hbase-site.xml node3.xxyl.cn:$PWD
3.4 将配置后的hbase-site.xml拷贝到phoenix的bin目录
cp /export/server/hbase-2.1.0/conf/hbase-site.xml /export/server/apache-phoenix-5.0.0-HBase-2.0-bin/bin/
#重新启动HBase
stop-hbase.sh
start-hbase.sh
3.5 启动Phoenix客户端,连接Phoenix Server
cd /export/server/apache-phoenix-5.0.0-HBase-2.0-bin/
bin/sqlline.py node1.xxyl.cn:2181
# 输入!table查看Phoenix中的表
!table
HBase的webUI发现多了6张表:
到此 Phoenix安装结束!!!