安装使用手册详细版.docx

上传人:b****1 文档编号:14062233 上传时间:2023-06-20 格式:DOCX 页数:14 大小:131.52KB
下载 相关 举报
安装使用手册详细版.docx_第1页
第1页 / 共14页
安装使用手册详细版.docx_第2页
第2页 / 共14页
安装使用手册详细版.docx_第3页
第3页 / 共14页
安装使用手册详细版.docx_第4页
第4页 / 共14页
安装使用手册详细版.docx_第5页
第5页 / 共14页
安装使用手册详细版.docx_第6页
第6页 / 共14页
安装使用手册详细版.docx_第7页
第7页 / 共14页
安装使用手册详细版.docx_第8页
第8页 / 共14页
安装使用手册详细版.docx_第9页
第9页 / 共14页
安装使用手册详细版.docx_第10页
第10页 / 共14页
安装使用手册详细版.docx_第11页
第11页 / 共14页
安装使用手册详细版.docx_第12页
第12页 / 共14页
安装使用手册详细版.docx_第13页
第13页 / 共14页
安装使用手册详细版.docx_第14页
第14页 / 共14页
亲,该文档总共14页,全部预览完了,如果喜欢就下载吧!
下载资源
资源描述

安装使用手册详细版.docx

《安装使用手册详细版.docx》由会员分享,可在线阅读,更多相关《安装使用手册详细版.docx(14页珍藏版)》请在冰点文库上搜索。

安装使用手册详细版.docx

安装使用手册详细版

Phoenix安装与使用文档

作者:

宋亚飞

2015年3月27日

目录

Phoenix安装与使用文档1

目录1

描述2

Phoenix安装2

1、下载Phoenix2

2、上传压缩包3

3、解压缩文件3

4、配置Phoenix4

5、修改权限4

6、验证是否成功4

Phoenix使用5

1、建表5

2、导入数据5

3、查询数据5

查询1、查询全部记录5

查询2、查询记录总条数6

查询3、查询结果分组排序6

查询4、求平均值6

查询5、多字段分组,排序,别名。

7

查询6、查询日期类型字段7

查询7、字符串,日期类型转换7

4、Phoenix基本shell命令8

5、用PhoenixJavaapi操作HBase9

Phoenix支持12

描述

现有hbase的查询工具有很多如:

Hive,Tez,Impala,Shark/Spark,Phoenix等。

今天主要记录Phoenix。

phoenix,中文译为“凤凰”,很美的名字。

Phoenix是由开源的一个项目,后又捐给了Apache基金会。

它相当于一个Java中间件,提供jdbc连接,操作hbase数据表。

但是在生产环境中,不可以用在OLTP中。

在线事务处理的环境中,需要低延迟,而Phoenix在查询HBase时,虽然做了一些优化,但延迟还是不小。

所以依然是用在OLAT中,再将结果返回存储下来。

Phoenix官网上,对Phoenix讲解已经很详细了。

如果英语好,可以看官网,更正式一些。

Phoenix安装

1、下载Phoenix

下载地址:

phoenix与HBase版本对应关系

Phoenix2.x-HBase0.94.x

Phoenix3.x-HBase0.94.x

Phoenix4.x-HBase0.98.1+

我目前测试使用版本概况:

Hadoop2.2.0--HBase0.98.2

所以我可以用phoenix4.x。

下载的压缩包为phoenix-4.3.0-bin.tar.gz

2、上传压缩包

将phoenix-4.3.0-bin.tar.gz上传hbase集群的其中一个服务器的一个目录下

我上传的目录为/usr/lib

3、解压缩文件

tar–zxvfphoenix-4.3.0-bin.tar.gz

可看到有个phoenix-4.3.0-bin/目录,里面包含了Phoenix的所有文件。

4、配置Phoenix

4.1、将phoenix-4.3.0-bin/目录下phoenix-core-4.3.0.jar、phoenix-4.3.0-client.jar拷贝到各个hbase的lib目录下。

4.2、重启hbase集群,使Phoenix的jar包生效。

4.3、将hbase的配置文件hbase-site.xml放到phoenix-4.3.0-bin/bin/下,替换Phoenix原来的配置文件。

5、修改权限

切换到下,修改psql.py和sqlline.py的权限为777

命令:

chmod777文件名

6、验证是否成功

6.1、在phoenix-4.3.0-bin/bin/下输入命令:

./sqlline.pylocalhost

如果看到如下界面表示启动成功。

6.2、输入!

tables,查看都有哪些表。

红框部分是用户建的表,其他为Phoenix系统表,系统表中维护了用户表的元数据信息。

6.3、退出Phoenix。

输入!

exit命令(PS:

Phoenix早期版本如(2.11版本)需输入!

quilt才可退出,目前高版本已改为!

exit命令)

Phoenix使用

1、建表

./psql.pylocalhost:

2181../examples/stock_symbol.sql,其中../examples/stock_symbol.sql是建表的sql语句

CREATETABLEIFNOTEXISTSWEB_STAT(

HOSTCHAR

(2)NOTNULL,

DOMAINVARCHARNOTNULL,

FEATUREVARCHARNOTNULL,

DATEDATENOTNULL,

USAGE.COREBIGINT,--usage指定列族名

USAGE.DBBIGINT,--usage指定列族名

STATS.ACTIVE_VISITORINTEGER

CONSTRAINTPKPRIMARYKEY(HOST,DOMAIN,FEATURE,DATE)--指定主键

);

2、导入数据

命令:

./psql.py-tWEB_STATlocalhost:

2181../examples/web_stat.csv

PS:

其中-t后面是表名,../examples/web_stat.csv是csv数据(注意数据的分隔符需要是逗号)。

3、查询数据

首先使用sqlline查看(截图为部分列的数据),查询表名不区分大小写。

查询1、查询全部记录

语句:

select*fromweb_stat;

查询2、查询记录总条数

语句:

selectcount

(1)fromweb_stat;

查询3、查询结果分组排序

语句:

selectdomain,count

(1)asnumfromweb_statgroupbydomainorderbynumdesc;

查询4、求平均值

语句:

selectavg(core)fromweb_stat;

查询5、多字段分组,排序,别名。

语句:

selectdomain,count

(1)asnum,avg(core)ascore,avg(db)asdbfromweb_statgroupbydomainorderbynumdesc;

查询6、查询日期类型字段

语句:

selecthost,domain,datefromweb_statwhereTO_CHAR(date)='2013-01-1507:

09:

01.000';

查询7、字符串,日期类型转换

语句:

selectTO_DATE('20131125','yyyyMMdd')fromweb_stat;

Ps:

输入的日期字符串会被转换为hbase表date的日期类型。

总结:

Phoenix还支持了很多函数和sql语法,在这里不再一一列举。

更多请参考Phoenix支持部分

4、Phoenix基本shell命令

PS:

以下,可能有部分命令在Phoenix更高版本中已失效,改为其他命令代替,请注意。

0:

jdbc:

phoenix:

localhost>help

!

allExecutethespecifiedSQLagainstallthecurrentconnections

!

autocommitSetautocommitmodeonoroff

!

batchStartorexecuteabatchofstatements

!

briefSetverbosemodeoff

!

callExecuteacallablestatement

!

closeClosethecurrentconnectiontothedatabase

!

closeallCloseallcurrentopenconnections

!

columnsListallthecolumnsforthespecifiedtable

!

commitCommitthecurrenttransaction(ifautocommitisoff)

!

connectOpenanewconnectiontothedatabase.

!

dbinfoGivemetadatainformationaboutthedatabase

!

describeDescribeatable

!

dropallDropalltablesinthecurrentdatabase

!

exportedkeysListalltheexportedkeysforthespecifiedtable

!

goSelectthecurrentconnection

!

helpPrintasummaryofcommandusage

!

historyDisplaythecommandhistory

!

importedkeysListalltheimportedkeysforthespecifiedtable

!

indexesListalltheindexesforthespecifiedtable

!

isolationSetthetransactionisolationforthisconnection

!

listListthecurrentconnections

!

manualDisplaytheSQLLinemanual

!

metadataObtainmetadatainformation

!

nativesqlShowthenativeSQLforthespecifiedstatement

!

outputformatSettheoutputformatfordisplayingresults

(table,vertical,csv,tsv,xmlattrs,xmlelements)

!

primarykeysListalltheprimarykeysforthespecifiedtable

!

proceduresListalltheprocedures

!

propertiesConnecttothedatabasespecifiedinthepropertiesfile(s)

!

quitExitstheprogram此命令在Phoenix4.3版本已改为!

exit

!

reconnectReconnecttothedatabase

!

recordRecordalloutputtothespecifiedfile

!

rehashFetchtableandcolumnnamesforcommandcompletion

!

rollbackRollbackthecurrenttransaction(ifautocommitisoff)

!

runRunascriptfromthespecifiedfile

!

saveSavethecurrentvariabesandaliases

!

scanScanforinstalledJDBCdrivers

!

scriptStartsavingascripttoafile

!

setSetasqllinevariable

5、用PhoenixJavaapi操作HBase

开发环境准备:

eclipse3.5、jdk1.7、window8、hadoop2.2.0、hbase0.98.0.2、phoenix4.3.0

1、从集群拷贝以下文件:

core-site.xml、hbase-site.xml、hdfs-site.xml文件放到工程src下

2、把phoenix的phoenix-4.3.0-client.jar和phoenix-core-4.3.0.jar添加到工程classpath

3、配置集群中各节点的hosts文件,把客户端的hostname:

IP添加进去

4、在客户端host文件中加入集群的hostname和IP

5、工程截图

6、工程代码

packagecom.byzoro.phoenix.test;

importjava.sql.Connection;

importjava.sql.DriverManager;

importjava.sql.ResultSet;

importjava.sql.Statement;

publicclassPhoenix_Test{

/**

*使用phoenix提供的api操作hbase读取数据

*@authorsongyafei

*@paramargs

*@throwsThrowable

*@date2015-03-25

*/

publicstaticvoidmain(String[]args)throwsThrowable{

try{

//下面的驱动为Phoenix老版本使用2.11使用,对应hbase0.94+

//Class.forName("com.salesforce.phoenix.jdbc.PhoenixDriver");

//phoenix4.3用下面的驱动对应hbase0.98+

Class.forName("org.apache.phoenix.jdbc.PhoenixDriver");

}catch(Exceptione){

e.printStackTrace();

}

//这里配置zookeeper的地址,可单个,也可多个。

可以是域名或者ip

Stringurl="jdbc:

phoenix:

10.14.9.41:

2181";

//Stringurl="jdbc:

phoenix:

,:

2181";

Connectionconn=DriverManager.getConnection(url);

Statementstatement=conn.createStatement();

Stringsql="selectcount

(1)asnumfromweb_stat";

longtime=System.currentTimeMillis();

ResultSetrs=statement.executeQuery(sql);

while(rs.next()){

intcount=rs.getInt("num");

System.out.println("rowcountis"+count);

}

longtimeUsed=System.currentTimeMillis()-time;

System.out.println("time"+timeUsed+"mm");

//关闭连接

rs.close();

statement.close();

conn.close();

}

}

7、运行截图:

实例二:

packagecom.byzoro.phoenix.test;

importjava.sql.Connection;

importjava.sql.DriverManager;

importjava.sql.ResultSet;

importjava.sql.Statement;

publicclassPhoenix_Test{

/**

*使用phoenix提供的api操作hbase中读取数据

*@authorsongyafei

*@paramargs

*@throwsThrowable

*@date2015-03-25

*/

publicstaticvoidmain(String[]args)throwsThrowable{

try{

//下面的驱动为Phoenix老版本使用2.11使用,对应hbase0.94+

//Class.forName("com.salesforce.phoenix.jdbc.PhoenixDriver");

//phoenix4.3用下面的驱动对应hbase0.98+

Class.forName("org.apache.phoenix.jdbc.PhoenixDriver");

}catch(Exceptione){

e.printStackTrace();

}

//这里配置zk的地址,可单个,也可多个。

可以是域名或者ip

Stringurl="jdbc:

phoenix:

10.14.9.41:

2181";

//Stringurl="jdbc:

phoenix:

,:

2181";

Connectionconn=DriverManager.getConnection(url);

Statementstatement=conn.createStatement();

//Stringsql="selectcount

(1)asnumfromweb_stat";

Stringsql="select*fromweb_statwherecore=35";

longtime=System.currentTimeMillis();

ResultSetrs=statement.executeQuery(sql);

while(rs.next()){

//获取core字段值

intcore=rs.getInt("core");

//获取core字段值

Stringhost=rs.getString("host");

//获取domain字段值

Stringdomain=rs.getString("domain");

//获取feature字段值

Stringfeature=rs.getString("feature");

//获取date字段值,数据库中字段为Date类型,这里代码会自动转化为string类型

Stringdate=rs.getString("date");

//获取db字段值

Stringdb=rs.getString("db");

System.out.println("host:

"+host+"\tdomain:

"+domain+"\tfeature:

"+feature+"\tdate:

"+date+"\tcore:

"+core+"\tdb:

"+db);

}

longtimeUsed=System.currentTimeMillis()-time;

System.out.println("time"+timeUsed+"mm");

//关闭连接

rs.close();

statement.close();

conn.close();

}

}

Phoenix支持

Phoenix中的语法

Phoenix中的数据类型

Phoenix中的方法

本文档为原创,转载请注明出处,尊重作者劳动成果。

更多大数据技术知识请访问:

宋亚飞.中国

展开阅读全文
相关资源
猜你喜欢
相关搜索
资源标签

当前位置:首页 > 农林牧渔 > 林学

copyright@ 2008-2023 冰点文库 网站版权所有

经营许可证编号:鄂ICP备19020893号-2