phoenix技术(安装部署和基本使用)讲解
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技术(安装部署和基本使用)讲解的更多相关文章
- 大数据技术之_13_Azkaban学习_Azkaban(阿兹卡班)介绍 + Azkaban 安装部署 + Azkaban 实战
一 概述1.1 为什么需要工作流调度系统1.2 常见工作流调度系统1.3 各种调度工具特性对比1.4 Azkaban 与 Oozie 对比二 Azkaban(阿兹卡班) 介绍三 Azkaban 安装部 ...
- DEVOPS技术实践_10:安装部署Artifactory
需要一种机制去存储所有的二进制代码(build,packages,third-party plugins等)到类似于版本控制系统的系统. 像Git,SVN存储代码,它们存储的往往是源代码,不是二进制文 ...
- 浅谈Excel开发:八 Excel 项目的安装部署
前面几篇文章讲解了Excel开发的几个比较主要的也是比较重要的方面,比如菜单系统,Excel对象模型,自定义函数,RTD函数,异步自定义函数,用户自定义任务面板等,在实际开发中我们还会遇到各种“千奇百 ...
- Apache Solr 初级教程(介绍、安装部署、Java接口、中文分词)
Python爬虫视频教程零基础小白到scrapy爬虫高手-轻松入门 https://item.taobao.com/item.htm?spm=a1z38n.10677092.0.0.482434a6E ...
- Phoenix的安装使用与SQL查询HBase
一. Phoenix的简介 1. 什么是phoenix 现有hbase的查询工具有很多如:Hive,Tez,Impala,Shark/Spark,Phoenix等.今天主要说Phoenix.phoen ...
- 2-MySQL DBA笔记-MySQL安装部署和入门
第2章 MySQL安装部署和入门 第1章介绍了MySQL的一些基础知识,本章将为读者介绍MySQL的部署.安装及一些常用命令和参数的设置.2.1 如何选择MySQL版本 在选择MySQL的版本时,要根 ...
- 第06讲:Flink 集群安装部署和 HA 配置
Flink系列文章 第01讲:Flink 的应用场景和架构模型 第02讲:Flink 入门程序 WordCount 和 SQL 实现 第03讲:Flink 的编程模型与其他框架比较 第04讲:Flin ...
- KVM安装部署
KVM安装部署 公司开始部署KVM,KVM的全称是kernel base virtual machine,对KVM虚拟化技术研究了一段时间, KVM是基于硬件的完全虚拟化,跟vmware.xen.hy ...
- Hadoop入门进阶课程13--Chukwa介绍与安装部署
本文版权归作者和博客园共有,欢迎转载,但未经作者同意必须保留此段声明,且在文章页面明显位置给出原文连接,博主为石山园,博客地址为 http://www.cnblogs.com/shishanyuan ...
- discourse 基于ember.js+rails项目的安装部署
最近公司在讨论做一个ERP运维问答的论坛系统,看了很多开源系统,觉得discourse功能比较完善,灵活.可配置性非常好,部署方便,瀑布流的主题布局模式也很符合未来论坛的趋势,于是在 ucloud 上 ...
随机推荐
- ES6入门基础
let和const 一.块级作用域 ES5 只有全局作用域和函数作用域,没有块级作用域,这样的缺点是:1.用来计数的循环变量泄露为全局变量.2.内层变量可能会覆盖外层变量 var tmp = new ...
- linux每日命令(30):Linux 用户及用户组相关文件、命令详解
一. 用户.用户组概念及其文件结构详解 Linux用户只有两个等级:root及非root.Linux中还有一部分用户,如:apache.mysql.nobody.ftp等,这些也都是非root用户,即 ...
- border绘制三角形
(1)有边框的三角形 我们来写下带边框的三角形. 如果是一个正方形,我们写边时,会用到border,但我们这里讨论的三角形本身就是border,不可能再给border添加border属性,所以我们需要 ...
- c++命名空间---namespace
C++ 命名空间 C++ 应用程序中.例如,您可能会写一个名为 func() 的函数,在另一个可用的库中也存在一个相同的函数 func().这样,编译器就无法判断您所使用的是哪一个 func() 函数 ...
- egret3.x升级5.2
第一步 先用新建项目向导新建一个5.2的项目 第二步 把3.x的代码和资源文件复制过来替换掉 修改资源加载代码 在3.x里 egret采用的是事件机制来加载资源,在5.2里则采用了await/asyn ...
- Geany的"跳转到标记定义“功能如何使用
Geany是个比较轻量级的代码编辑器,在一些不怎么需要编辑的代码上,我比较常用它来浏览代码.不过它的 跳转到标记定义(Go to tag definition) 功能有点奇怪,一开始死活不知道怎么用, ...
- Maven包下载不下来的情况
从svn上遇到过项目下载下来,缺丢失了一些包,怎么都下载不了,只能从同事的电脑上给拷贝下来? 千万别这样,别问为何,说多了都是泪,然后发现. 如果是eclipse的话: 勾选这两个选项,就能下载下来了 ...
- 【iCore4 双核心板_ARM】例程十三:SDIO实验——读取SD卡信息
实验现象: 核心代码: int main(void) { system_clock.initialize(); led.initialize(); usart6.initialize(); usart ...
- opencv 无法使用 dll 动态链接库 UnsatisfiedLinkError java.library.path Can't find dependent libraries
System.loadLibrary(Core.NATIVE_LIBRARY_NAME) 使用如上方法加载本地 dll文件. 一般会出现两种错误: 1. UnsatisfiedLinkError ja ...
- Halcon之 Variation Model(转)
Variation Model的主要原理是将待检测的图像与一张标准图像作比较,找出待检测图像与标准图像(ideal image)的明显差异(也就是不良).标准图像可以采用几张OK品的图像训练(trai ...