1、phoenix简介

Apache Phoenix是构建在HBase之上的关系型数据库层,作为内嵌的客户端JDBC驱动用以对HBase中的数据进行低延迟访问。Apache Phoenix会将用户编写的sql查询编译为一系列的scan操作,最终产生通用的JDBC结果集返回给客户端。数据表的元数据存储在HBase的表中被会标记版本号,所以进行查询的时候会自动选择正确的schema。直接使用HBase的API,结合协处理器(coprocessor)和自定义的过滤器的话,小范围的查询在毫秒级响应,千万数据的话响应速度为秒级。

2、安装phoenix

参考官方文档:http://phoenix.apache.org/installation.html

hbase 0.98.1+以上hbase版本需要下载phoenix 4.x版本。

此处使用的phoenix版本为:phoenix-4.3.0-bin.tar.gz

根据官档说明,安装一个预编译的phoenix需要执行以下步骤:

1)下载并且解压phoenix-[version]-bin.tar.

2)将phoenix-[version]-server.jar添加到hbase master和regionserver的classpath路径,这里可以直接cp phoenix-[version]-server.jar到hbase master和regionserver的lib/目录下(phoenix 3.x版本对应jar包:phoenix-core-[version].jar)。

3)重启hbase

4)将phoenix-[version]-client.jar添加到phoenix client的classpath中。

3、连接HBase

执行如下命令连接HBase集群:

$ bin/sqlline.py chavin.king:2181

--说明:这里的chavin.king参数是HBase集群zookeeper集群的hostname,2181是zookeeper端口号。

phoenix中通过!tables可以查看table信息:

0: jdbc:phoenix:chavin.king:2181> !table

+-----------+-------------+-------------+---------------+-----------------+

|TABLE_CAT  | TABLE_SCHEM | TABLE_NAME  | TABLE_TYPE    |                 |

+-----------+-------------+-------------+---------------+-----------------+

|           | SYSTEM      | CATALOG     | SYSTEM TABLE  |                 |

|           | SYSTEM      | SEQUENCE    | SYSTEM TABLE  |                 |

|           | SYSTEM      | STATS       | SYSTEM TABLE  |                 |

|           |             | WEB_STAT    | TABLE         |                 |

+-----------+-------------+-------------+---------------+-----------------+

--说明:CATALOG、SEQUENCE、STATS这三张表是系统自带的表。HBase中已存在的表不会自动映射过来,需要手动创建相同结果的数据表,具体过程后面会说到。

从HBase的CLI界面查看是否同样多出这三张表:

hbase(main):021:0> list

TABLE                                                                                                                                                                                         

SYSTEM.CATALOG                                                                                                                                                                                

SYSTEM.SEQUENCE                                                                                                                                                                               

SYSTEM.STATS                                                                                                                                                                                  

WEB_STAT

phoenix安装完成。

4、phoenix cli CRUD操作

参考文档:http://phoenix.apache.org/language/index.html#alter

1)phoenix中创建表:

0: jdbc:phoenix:chavin.king:2181> CREATE TABLE user_temp (id varchar PRIMARY KEY,account varchar ,passwd varchar);

No rows affected (2.626 seconds)

此时,hbase中也可以看到相应的USER_TEMP表(phoenix会将字母默认转换为大写,如果想保持小写字母形式,可以使用双引号引起来):

hbase(main):030:0> describe 'USER_TEMP'

DESCRIPTION                                                                                                                 ENABLED                                                           
  'USER_TEMP', {TABLE_ATTRIBUTES => {coprocessor$1 => '|org.apache.phoenix.coprocessor.ScanRegionObserver|805306366|', copro true                                                              
  cessor$2 => '|org.apache.phoenix.coprocessor.UngroupedAggregateRegionObserver|805306366|', coprocessor$3 => '|org.apache.p                                                                   
  hoenix.coprocessor.GroupedAggregateRegionObserver|805306366|', coprocessor$4 => '|org.apache.phoenix.coprocessor.ServerCac                                                                   
  hingEndpointImpl|805306366|', coprocessor$5 => '|org.apache.phoenix.hbase.index.Indexer|805306366|index.builder=org.apache                                                                   
  .phoenix.index.PhoenixIndexBuilder,org.apache.hadoop.hbase.index.codec.class=org.apache.phoenix.index.PhoenixIndexCodec',                                                                    
  coprocessor$6 => '|org.apache.hadoop.hbase.regionserver.LocalIndexSplitter|805306366|'}, {NAME => '0', DATA_BLOCK_ENCODING                                                                   
   => 'FAST_DIFF', BLOOMFILTER => 'ROW', REPLICATION_SCOPE => '0', VERSIONS => '1', COMPRESSION => 'NONE', MIN_VERSIONS => '                                                                   
  0', TTL => 'FOREVER', KEEP_DELETED_CELLS => 'FALSE', BLOCKSIZE => '65536', IN_MEMORY => 'false', BLOCKCACHE => 'true'}                                                                       

1 row(s) in 0.4060 seconds

创建指定列族与列的建表语句:

0: jdbc:phoenix:chavin.king:2181> CREATE TABLE user_temp_cf (id varchar PRIMARY KEY,INFO.account varchar ,INFO.passwd varchar);

No rows affected (3.467 seconds)

hbase中查看表结构:

hbase(main):035:0* describe 'USER_TEMP_CF'

DESCRIPTION                                                                                                                 ENABLED                                                           
  'USER_TEMP_CF', {TABLE_ATTRIBUTES => {coprocessor$1 => '|org.apache.phoenix.coprocessor.ScanRegionObserver|805306366|', co true                                                              
  processor$2 => '|org.apache.phoenix.coprocessor.UngroupedAggregateRegionObserver|805306366|', coprocessor$3 => '|org.apach                                                                   
  e.phoenix.coprocessor.GroupedAggregateRegionObserver|805306366|', coprocessor$4 => '|org.apache.phoenix.coprocessor.Server                                                                   
  CachingEndpointImpl|805306366|', coprocessor$5 => '|org.apache.phoenix.hbase.index.Indexer|805306366|index.builder=org.apa                                                                   
  che.phoenix.index.PhoenixIndexBuilder,org.apache.hadoop.hbase.index.codec.class=org.apache.phoenix.index.PhoenixIndexCodec                                                                   
  ', coprocessor$6 => '|org.apache.hadoop.hbase.regionserver.LocalIndexSplitter|805306366|'}, {NAME => 'INFO', DATA_BLOCK_EN                                                                   
  CODING => 'FAST_DIFF', BLOOMFILTER => 'ROW', REPLICATION_SCOPE => '0', VERSIONS => '1', COMPRESSION => 'NONE', MIN_VERSION                                                                   
  S => '0', TTL => 'FOREVER', KEEP_DELETED_CELLS => 'FALSE', BLOCKSIZE => '65536', IN_MEMORY => 'false', BLOCKCACHE => 'true                                                                   
  '}                                                                                                                                                                                           

1 row(s) in 0.3380 seconds

2)向表中插入数据:这里插入关键字与rdbms不同,为upsert:

0: jdbc:phoenix:chavin.king:2181> upsert into user_temp(id, account, passwd) values('001', 'admin', 'admin');

1 row affected (0.77 seconds)

3)查新数据

0: jdbc:phoenix:chavin.king:2181> select * from user_temp;

+------+----------+----------+

| ID   | ACCOUNT  | PASSWD   |

+------+----------+----------+

| 001  | admin    | admin    |

+------+----------+----------+

4)更新数据:语法等同于插入数据

0: jdbc:phoenix:chavin.king:2181> upsert into user_temp(id, account, passwd) values('001', 'admin', 'admin');

1 row affected (0.77 seconds)

5)删除数据:

0: jdbc:phoenix:chavin.king:2181> delete from user_temp where id='001';

1 row affected (0.245 seconds)

6)删除表:

0: jdbc:phoenix:chavin.king:2181> drop table user_temp;

No rows affected (4.577 seconds)

5、phoenix JDBC CRUD操作

http://blog.csdn.net/maomaosi2009/article/details/45582321

http://blog.csdn.net/maomaosi2009/article/details/45583259

6、Phoenix配置Squirrel GUI连接Phoenix

参考官方文档:http://phoenix.apache.org/installation.html#SQL_Client     -->     SQL Client模块

1)Remove prior phoenix-[oldversion]-client.jar from the lib directory of SQuirrel, copy phoenix-[newversion]-client.jar to the lib directory (newversion should be compatible with the version of the phoenix server jar used with your HBase installation)

2)Start SQuirrel and add new driver to SQuirrel (Drivers -> New Driver)

3)In Add Driver dialog box, set Name to Phoenix, and set the Example URL to jdbc:phoenix:localhost.

4)Type “org.apache.phoenix.jdbc.PhoenixDriver” into the Class Name textbox and click OK to close this dialog.

5)Switch to Alias tab and create the new Alias (Aliases -> New Aliases)

6)In the dialog box, Name: any name, Driver: Phoenix, User Name: anything, Password: anything

7)Construct URL as follows: jdbc:phoenix: zookeeper quorum server. For example, to connect to a local HBase use: jdbc:phoenix:localhost

8)Press Test (which should succeed if everything is setup correctly) and press OK to close.

9)Now double click on your newly created Phoenix alias and click Connect. Now you are ready to run SQL queries against Phoenix.

6.1)下载SQuirreL SQL Client:

https://jaist.dl.sourceforge.net/project/squirrel-sql/1-stable/3.8.0/squirrel-sql-3.8.0-standard.jar

注意,squirrel-sql要匹配对应jdk版本。

6.2)安装SQuirreL SQL Client:

双击下载squirrel-sql-3.8.0-standard.jar,直接下一步就可以了。

6.3)配置SQuirreL SQL Client:

拷贝phoenix-4.3.0-client.jar到SQuirreL的lib/目录下。

进入SQuirreL安装目录,双击squirrel-sql.bat启动SQuirreL。

驱动程序->添加驱动程序:

Name:phoenix

ExampleURL:jdbc:phoenix:chavin.king:2181

Website URL:

Java Class Path:选择phoenix-4.3.0-client.jar

Class Name:org.apache.phoenix.jdbc.PhoenixDriver

配置aliases,选择上一步配置的驱动。

现在可以通过GUI界面操作hbase了。

7、Phoenix映射HBase中创建的表

安装好phoenix后对于HBase中已经存在的数据表或者在hbase中创建的表不会自动进行映射,所以想要再phoenix中操作HBase已有数据表就需要手动进行配置。

hbase中存在的表:

hbase(main):043:0> scan 'user'

ROW                                              COLUMN+CELL                                                                                                                                  
  10001                                           column=info:age, timestamp=1490389800933, value=28                                                                                           
  10001                                           column=info:name, timestamp=1490389743583, value=zhangsan                                                                                    
  10001                                           column=info:sex, timestamp=1490389809756, value=man                                                                                          
  10002                                           column=info:address, timestamp=1490846659202, value=beijing                                                                                  
  10002                                           column=info:age, timestamp=1490846659202, value=\x00\x00\x00\x1C                                                                             
  10002                                           column=info:name, timestamp=1490846659202, value=lisi                                                                                        

2 row(s) in 0.1170 seconds

在phoenix中映射hbase中user表:

create table "user"(

ROW varchar primary key,

"info"."name" varchar,

"info"."age" varchar,

"info"."sex" varchar,

"info"."address" varchar

);

如下:

0: jdbc:phoenix:chavin.king:2181> create table "user"(

. . . . . . . . . . . . . . . . > ROW varchar primary key,

. . . . . . . . . . . . . . . . > "info"."name" varchar,

. . . . . . . . . . . . . . . . > "info"."age" varchar,

. . . . . . . . . . . . . . . . > "info"."sex" varchar,

. . . . . . . . . . . . . . . . > "info"."address" varchar

. . . . . . . . . . . . . . . . > );

2 rows affected (5.593 seconds)

8、通过alter table命令修改phoenix表结构

0: jdbc:phoenix:chavin.king:2181> alter table "user" drop column "address";

9、phoenix执行sql脚本

phoenix工具自带了执行sql脚本的功能,主要目的是方便将rdbms中的数据迁移至hbase中。

在examples/目录下创建脚本p_user.sql,输入内容如下:

-- create table p_user

create table if not exists p_user (id varchar primary key,account varchar ,passwd varchar);

-- insert data

upsert into p_user(id, account, passwd) values('001', 'admin', 'admin');

upsert into p_user(id, account, passwd) values('002', 'test', 'test');

upsert into p_user(id, account, passwd) values('003', 'zx', 'zx');

-- query data

select * from p_user;

使用phoenix工具psql.py执行脚本:

bin/psql.py chavin.king:2181 examples/p_user.sql

SLF4J: Failed to load class "org.slf4j.impl.StaticLoggerBinder".

SLF4J: Defaulting to no-operation (NOP) logger implementation

SLF4J: See http://www.slf4j.org/codes.html#StaticLoggerBinder for further details.

17/10/22 00:59:26 WARN util.NativeCodeLoader: Unable to load native-hadoop library for your platform... using builtin-java classes where applicable

17/10/22 00:59:31 WARN impl.MetricsConfig: Cannot locate configuration: tried hadoop-metrics2-phoenix.properties,hadoop-metrics2.properties

no rows upserted

Time: 3.23 sec(s)

1 row upserted

Time: 0.297 sec(s)

1 row upserted

Time: 0.038 sec(s)

1 row upserted

Time: 0.029 sec(s)

ID                                       ACCOUNT                                  PASSWD                                  

---------------------------------------- ---------------------------------------- ----------------------------------------

001                                      admin                                    admin                                   

002                                      test                                     test                                    

003                                      zx                                       zx                                      

Time: 0.142 sec(s)

--其中chavin.king:2181为hbase注册zookeeper地址。

10、通过phoenix加载特定格式文件存储数据到hbase

1)单线程psql.py工具导入小批量数据到hbase

在examples/目录下创建文件data.csv:

12345,John,Doe

67890,Mary,Poppins

phoenix中创建用于加载上面数据的表:

CREATE TABLE example (
     my_pk bigint not null,
     m.first_name varchar(50),
     m.last_name varchar(50)
     CONSTRAINT pk PRIMARY KEY (my_pk))

使用psql.py工具导入数据data.csv到表example中:

bin/psql.py chavin.king:2181 -t EXAMPLE examples/data.csv

2)使用MapReduce并行加载大批量数据到hbase

创建测试表:

create table p_user0 (id varchar primary key,account varchar ,passwd varchar);

examples/目录生成测试数据:

vim examples/data_mr.csv

001,google,AM

002,baidu,BJ

003,alibaba,HZ

通过mapreduce加载数据:

export HBASE_HOME=/opt/cdh-5.3.6/hbase-0.98.6-cdh5.3.6

export HADOOP_HOME=/opt/cdh-5.3.6/hadoop-2.5.0-cdh5.3.6

HADOOP_CLASSPATH=`${HBASE_HOME}/bin/hbase mapredcp`:${HBASE_HOME}/conf $HADOOP_HOME/bin/hadoop jar \

phoenix-4.3.0-client.jar org.apache.phoenix.mapreduce.CsvBulkLoadTool \

--table P_USER0 \

--input file:///opt/cdh-5.3.6/phoenix-4.3.0-bin/examples/data_mr.csv \

--zookeeper chavin.king:2181

phoenix技术(安装部署和基本使用)讲解的更多相关文章

  1. 大数据技术之_13_Azkaban学习_Azkaban(阿兹卡班)介绍 + Azkaban 安装部署 + Azkaban 实战

    一 概述1.1 为什么需要工作流调度系统1.2 常见工作流调度系统1.3 各种调度工具特性对比1.4 Azkaban 与 Oozie 对比二 Azkaban(阿兹卡班) 介绍三 Azkaban 安装部 ...

  2. DEVOPS技术实践_10:安装部署Artifactory

    需要一种机制去存储所有的二进制代码(build,packages,third-party plugins等)到类似于版本控制系统的系统. 像Git,SVN存储代码,它们存储的往往是源代码,不是二进制文 ...

  3. 浅谈Excel开发:八 Excel 项目的安装部署

    前面几篇文章讲解了Excel开发的几个比较主要的也是比较重要的方面,比如菜单系统,Excel对象模型,自定义函数,RTD函数,异步自定义函数,用户自定义任务面板等,在实际开发中我们还会遇到各种“千奇百 ...

  4. Apache Solr 初级教程(介绍、安装部署、Java接口、中文分词)

    Python爬虫视频教程零基础小白到scrapy爬虫高手-轻松入门 https://item.taobao.com/item.htm?spm=a1z38n.10677092.0.0.482434a6E ...

  5. Phoenix的安装使用与SQL查询HBase

    一. Phoenix的简介 1. 什么是phoenix 现有hbase的查询工具有很多如:Hive,Tez,Impala,Shark/Spark,Phoenix等.今天主要说Phoenix.phoen ...

  6. 2-MySQL DBA笔记-MySQL安装部署和入门

    第2章 MySQL安装部署和入门 第1章介绍了MySQL的一些基础知识,本章将为读者介绍MySQL的部署.安装及一些常用命令和参数的设置.2.1 如何选择MySQL版本 在选择MySQL的版本时,要根 ...

  7. 第06讲:Flink 集群安装部署和 HA 配置

    Flink系列文章 第01讲:Flink 的应用场景和架构模型 第02讲:Flink 入门程序 WordCount 和 SQL 实现 第03讲:Flink 的编程模型与其他框架比较 第04讲:Flin ...

  8. KVM安装部署

    KVM安装部署 公司开始部署KVM,KVM的全称是kernel base virtual machine,对KVM虚拟化技术研究了一段时间, KVM是基于硬件的完全虚拟化,跟vmware.xen.hy ...

  9. Hadoop入门进阶课程13--Chukwa介绍与安装部署

    本文版权归作者和博客园共有,欢迎转载,但未经作者同意必须保留此段声明,且在文章页面明显位置给出原文连接,博主为石山园,博客地址为 http://www.cnblogs.com/shishanyuan  ...

  10. discourse 基于ember.js+rails项目的安装部署

    最近公司在讨论做一个ERP运维问答的论坛系统,看了很多开源系统,觉得discourse功能比较完善,灵活.可配置性非常好,部署方便,瀑布流的主题布局模式也很符合未来论坛的趋势,于是在 ucloud 上 ...

随机推荐

  1. Swift Defer 延迟调用

    1.Defer 在一些语言中,有 try/finally 这样的控制语句,比如 Java.这种语句可以让我们在 finally 代码块中执行必须要执行的代码,不管之前怎样的兴风作浪.在 Swift 2 ...

  2. PHP 扩展开发之Zephir

    最近对代码进行性能分析后,发现两个耗时的地方:自动加载文件数太多:参数验证函数调用超过1000次.这也是许多php语言框架面临的问题,所以发展出来诸如Yaf,Swoole,Phalcon这些C语言扩展 ...

  3. 数据源从druid迁移到HikariCP

    最近正好在做新项目,使用的是druid数据源,也真是巧,有朋友建议我使用HikariCP这个数据源,可以说是牛的一笔,速度快的飞起,性能极高! 要比druid不知道好多少倍,druid其实在某些情况下 ...

  4. Atitit 手机图片备份解决方案attilax总结

    Atitit 手机图片备份解决方案attilax总结 1.1. 图片分类 相机图片与app图片1 1.2. 增量备份,只能使用按照时间法备份..1 1.3. 备份工具选型1 1.4. App图片,只好 ...

  5. MemoryFile偷取安卓内存

    参考链接:http://www.jcodecraeer.com/a/anzhuokaifa/androidkaifa/2016/0111/3859.html MemoryFile memoryFile ...

  6. 《转》vue更新到2.0之后vue-resource不在更新,axios的使用

    vue更新到2.0之后,作者就宣告不再对vue-resource更新,而是推荐的axios,前一段时间用了一下,现在说一下它的基本用法. 首先就是引入axios,如果你使用es6,只需要安装axios ...

  7. 解决Redis之MISCONF Redis is configured to save RDB snapshots, but is currently not able to persist o...

    解决Redis之MISCONF Redis is configured to save RDB snapshots, but is currently not able to persist o... ...

  8. 【iCore4 双核心板_ARM】例程八:定时器PWM实验——呼吸灯

    实验原理: STM32的定时器有PWM功能,iCore4的蓝色LED连接在定时器的输出接口上, 可以通过定时器的PWM输出控制LED的亮度,从而实验呼吸灯的功能. 核心代码: int main(voi ...

  9. 9patch图的尺寸尽量为偶数

    美工做了一张.9的背景图,宽度110*80 像素,描点如下: 放到720p的智能电视上观看,总感觉怪怪的.仔细观看可以发现,前景图总是不能完全的覆盖掉背景图.总有那么一个像素的点多余出来,如图所示: ...

  10. mysql之我们终将踩过的坑(优化)

    一.EXPLAIN 做MySQL优化,我们要善用 EXPLAIN 查看SQL执行计划. 下面来个简单的示例,标注(1,2,3,4,5)我们要重点关注的数据 type列,连接类型.一个好的sql语句至少 ...