具体部署流程可以参考cloudera官方文档:
https://docs.cloudera.com/cdp-private-cloud-base/7.1.4/phoenix-configure-hbase/topics/phoenix-configure-hbase.html
1. HBase服务配置
1.1 修改服务配置
- 找到WAL 编解码器类属性或搜索 hbase.regionserver.wal.codec.添加以下属性值:
org.apache.hadoop.hbase.regionserver.wal.IndexedWALEditCodec
- 设置HBase 服务高级配置片段和 HBase 客户端高级配置片段 属性以启用用户定义的功能。找到该属性或搜索 HBase Service Advanced Configuration Snippet (Safety Valve) for hbase-site.xml和HBase Client Advanced Configuration Snippet (Safety Valve) for hbase-site.xml。
添加以下属性值:
<property>
<name>phoenix.functions.allowUserDefinedFunctions</name>
<value>true</value>
</property>
1.2 调整java堆大小
注意:调整java堆栈大小,防止Phoenix生成系统表时因内存不够导致失败
- 重启HBase服务
2. Phoenix on CDP
CDP7以上版本才支持安装Phoenix。
2.1 Phoenix服务部署
1.自定义角色分配
2.首次运行Phoenix服务
3.安装完成
4.执行Phoenix-sqline,执行此命令后会在HBase中生成系统表
2.2 验证Phoenix服务
- 创建表
CREATE TABLE IF NOT EXISTS us_population (
state CHAR(2) NOT NULL,
city VARCHAR NOT NULL,
population BIGINT
CONSTRAINT my_pk PRIMARY KEY (state, city));
- 插入数据
UPSERT INTO us_population VALUES('NY','New York',8143197);
UPSERT INTO us_population VALUES('CA','Los Angeles',3844829);
UPSERT INTO us_population VALUES('IL','Chicago',2842518);
UPSERT INTO us_population VALUES('TX','Houston',2016582);
- 查询数据
SELECT state as "State",count(city) as "City Count",sum(population) as "Population Sum"
FROM us_population
GROUP BY state
ORDER BY sum(population) DESC;
3. HBase映射Phoenix
- 创建hbase表
create 'test',{NAME => 'info'}
- 插入数据
put 'test', 'row001','info:name','phoenix'
put 'test', 'row002','info:name','hbase'
- 创建Phoenix表映射:在Phoenix中创建相同结构的数据表
create table "test"("row" varchar primary key, "info"."name" varchar);
select * from "test";
注意:这里表名和列族以及列名需要用双引号括起来,因为HBase是区分大小写的,如果不用双引号括起来的话Phoenix在创建表的时候会自动将小写转换为大写字母,这样HBase中会创建另外一张表PHOENIX
。
4. Hive映射HBase的外部表,使用Phoenix查询数据
- 创建HBase表
create 'test_table' , 'info'
- 创建hive映射 HBase表
create external table test_table(
key int,
id String,
name String
)
STORED BY 'org.apache.hadoop.hive.hbase.HBaseStorageHandler'
WITH SERDEPROPERTIES ("hbase.columns.mapping" =
":key,
info:id,
info:name
")
TBLPROPERTIES("hbase.table.name" ="test_table");
- 插入数据
insert into test_table values(1,"1","zhangsan");
insert into test_table values(2,"2","wangwu");
- 创建Phoenix表
create table "test_table"("row" varchar primary key,
"info"."id" varchar,
"info"."name" varchar);
select * from "test_table";