葵花宝典--即席查询presto和kylin

一、presto

1、简介

presto是一个开源的分布式SQL查询引擎,数据量支持GB到PB字节,只要处理秒级查询的场景。它和mysql和oracle是不同的,不能处理带有事务的数据。基于内存计算,减少了IO,计算更快,支持跨数据源的连接,比如和mysql;它的聚合运算时边读数据边计算,边清理内存,这种处理方式对内存占用不高;但是表连接会产生大量临时数据,处理速度较慢。

2、安装

0)官网地址

https://prestodb.github.io/

1)下载地址

https://repo1.maven.org/maven2/com/facebook/presto/presto-server/0.196/presto-server-0.196.tar.gz

2)将presto-server-0.196.tar.gz导入hadoop102的/opt/software目录下,并解压到/opt/module目录

[atguigu@hadoop102 software]$ tar -zxvf presto-server-0.196.tar.gz -C /opt/module/

3)修改名称为presto

[atguigu@hadoop102 module]$ mv presto-server-0.196/ presto

4)进入到/opt/module/presto目录,并创建存储数据文件夹

[atguigu@hadoop102 presto]$ mkdir data

5)进入到/opt/module/presto目录,并创建存储配置文件文件夹

[atguigu@hadoop102 presto]$ mkdir etc

6)配置在/opt/module/presto/etc目录下添加jvm.config配置文件

[atguigu@hadoop102 etc]$ vim jvm.config

添加如下内容

-server

-Xmx16G

-XX:+UseG1GC

-XX:G1HeapRegionSize=32M

-XX:+UseGCOverheadLimit

-XX:+ExplicitGCInvokesConcurrent

-XX:+HeapDumpOnOutOfMemoryError

-XX:+ExitOnOutOfMemoryError

7)Presto可以支持多个数据源,在Presto里面叫catalog,这里我们配置支持Hive的数据源,配置一个Hive的catalog

[atguigu@hadoop102 etc]$ mkdir catalog

[atguigu@hadoop102 catalog]$ vim hive.properties 

添加如下内容

connector.name=hive-hadoop2

hive.metastore.uri=thrift://hadoop102:9083

8)将hadoop102上的presto分发到hadoop103、hadoop104

[atguigu@hadoop102 module]$ xsync presto

9)分发之后,分别进入hadoop102、hadoop103、hadoop104三台主机的/opt/module/presto/etc的路径。配置node属性,node id每个节点都不一样

[atguigu@hadoop102 etc]$vim node.properties

node.environment=production

node.id=ffffffff-ffff-ffff-ffff-ffffffffffff

node.data-dir=/opt/module/presto/data

 

[atguigu@hadoop103 etc]$vim node.properties

node.environment=production

node.id=ffffffff-ffff-ffff-ffff-fffffffffffe

node.data-dir=/opt/module/presto/data

 

[atguigu@hadoop104 etc]$vim node.properties

node.environment=production

node.id=ffffffff-ffff-ffff-ffff-fffffffffffd

node.data-dir=/opt/module/presto/data

10)Presto是由一个coordinator节点和多个worker节点组成。在hadoop102上配置成coordinator,在hadoop103、hadoop104上配置为worker。

(1)hadoop102上配置coordinator节点

[atguigu@hadoop102 etc]$ vim config.properties

添加内容如下

coordinator=true

node-scheduler.include-coordinator=false

http-server.http.port=8881

query.max-memory=50GB

discovery-server.enabled=true

discovery.uri=http://hadoop102:8881

(2)hadoop103、hadoop104上配置worker节点

[atguigu@hadoop103 etc]$ vim config.properties

添加内容如下

coordinator=false

http-server.http.port=8881

query.max-memory=50GB

discovery.uri=http://hadoop102:8881

 

[atguigu@hadoop104 etc]$ vim config.properties

添加内容如下

coordinator=false

http-server.http.port=8881

query.max-memory=50GB

discovery.uri=http://hadoop102:8881

11)在hadoop102的/opt/module/hive目录下,启动Hive Metastore,用atguigu角色

[atguigu@hadoop102 hive]$

nohup bin/hive --service metastore >/dev/null 2>&1 &

12)分别在hadoop102、hadoop103、hadoop104上启动Presto Server

(1)前台启动Presto,控制台显示日志

[atguigu@hadoop102 presto]$ bin/launcher run

[atguigu@hadoop103 presto]$ bin/launcher run

[atguigu@hadoop104 presto]$ bin/launcher run

(2)后台启动Presto

[atguigu@hadoop102 presto]$ bin/launcher start

[atguigu@hadoop103 presto]$ bin/launcher start

[atguigu@hadoop104 presto]$ bin/launcher start

13)日志查看路径/opt/module/presto/data/var/log

1.2.2 Presto命令行Client安装

1)下载Presto的客户端

https://repo1.maven.org/maven2/com/facebook/presto/presto-cli/0.196/presto-cli-0.196-executable.jar

2)将presto-cli-0.196-executable.jar上传到hadoop102的/opt/module/presto文件夹下

3)修改文件名称

[atguigu@hadoop102 presto]$ mv presto-cli-0.196-executable.jar  prestocli

4)增加执行权限

[atguigu@hadoop102 presto]$ chmod +x prestocli

5)启动prestocli

[atguigu@hadoop102 presto]$ ./prestocli --server hadoop102:8881 --catalog hive --schema default

6)Presto命令行操作

Presto的命令行操作,相当于Hive命令行操作。每个表必须要加上schema。

例如:

select * from schema.table limit 100

1.2.3 Presto可视化Client安装

1)将yanagishima-18.0.zip上传到hadoop102的/opt/module目录

2)解压缩yanagishima

[atguigu@hadoop102 module]$ unzip yanagishima-18.0.zip

cd yanagishima-18.0

3)进入到/opt/module/yanagishima-18.0/conf文件夹,编写yanagishima.properties配置

[atguigu@hadoop102 conf]$ vim yanagishima.properties

添加如下内容

jetty.port=7080

presto.datasources=atguigu-presto

presto.coordinator.server.atguigu-presto=http://hadoop102:8881

catalog.atguigu-presto=hive

schema.atguigu-presto=default

sql.query.engines=presto

4)在/opt/module/yanagishima-18.0路径下启动yanagishima

[atguigu@hadoop102 yanagishima-18.0]$

nohup bin/yanagishima-start.sh >y.log 2>&1 &

5)启动web页面

http://hadoop102:7080

看到界面,进行查询了。

6)查看表结构

3、存储优化

合理设置分区、使用列式存储(推荐使用ORC)、使用压缩(如果要用presto分析的数据采用snappy压缩)

4、sql优化

  • 避免使用*,查询时指定字段
  • 能用分区查询的数据一定要用分区
  • group by的字段把基数大的排在前面
  • order by的时候使用limit避免进行全局的排序
  • 使用join的时候把大表放在前面(类似广播变量),大表于大表连接时采用hash算法

5、注意事项

  • 对事件进行比较时,在前边加timestamp(SELECT t FROM a WHERE t > timestamp '2017-01-01 00:00:00';)
  • 不支持insert overwrite,parquet只支持查询,不支持插入

二、kylin

1、简介

Apache Kylin是一个开源的分布式分析引擎,提供Hadoop/Spark之上的SQL查询接口及多维分析(OLAP)能力以支持超大规模数据,最初由eBay Inc开发并贡献至开源社区。它能在亚秒内查询巨大的Hive表。

1)REST Server

REST Server是一套面向应用程序开发的入口点,旨在实现针对Kylin平台的应用开发工作。 此类应用程序可以提供查询、获取结果、触发cube构建任务、获取元数据以及获取用户权限等等。另外可以通过Restful接口实现SQL查询。

2)查询引擎(Query Engine)

当cube准备就绪后,查询引擎就能够获取并解析用户查询。它随后会与系统中的其它组件进行交互,从而向用户返回对应的结果。 

3)路由器(Routing

在最初设计时曾考虑过将Kylin不能执行的查询引导去Hive中继续执行,但在实践后发现Hive与Kylin的速度差异过大,导致用户无法对查询的速度有一致的期望,很可能大多数查询几秒内就返回结果了,而有些查询则要等几分钟到几十分钟,因此体验非常糟糕。最后这个路由功能在发行版中默认关闭。

4)元数据管理工具(Metadata)

Kylin是一款元数据驱动型应用程序。元数据管理工具是一大关键性组件,用于对保存在Kylin当中的所有元数据进行管理,其中包括最为重要的cube元数据。其它全部组件的正常运作都需以元数据管理工具为基础。 Kylin的元数据存储在hbase中。 

5)任务引擎(Cube Build Engine)

这套引擎的设计目的在于处理所有离线任务,其中包括shell脚本、Java API以及Map Reduce任务等等。任务引擎对Kylin当中的全部任务加以管理与协调,从而确保每一项任务都能得到切实执行并解决其间出现的故障。

2、Kylin特点

Kylin的主要特点包括支持SQL接口、支持超大规模数据集、亚秒级响应、可伸缩性、高吞吐率、BI工具集成等。

1)标准SQL接口:Kylin是以标准的SQL作为对外服务的接口。

2)支持超大数据集:Kylin对于大数据的支撑能力可能是目前所有技术中最为领先的。早在2015年eBay的生产环境中就能支持百亿记录的秒级查询,之后在移动的应用场景中又有了千亿记录秒级查询的案例。

3)亚秒级响应:Kylin拥有优异的查询相应速度,这点得益于预计算,很多复杂的计算,比如连接、聚合,在离线的预计算过程中就已经完成,这大大降低了查询时刻所需的计算量,提高了响应速度。

4)可伸缩性和高吞吐率:单节点Kylin可实现每秒70个查询,还可以搭建Kylin的集群。

5)BI工具集成

Kylin可以与现有的BI工具集成,具体包括如下内容。

ODBC:与Tableau、Excel、PowerBI等工具集成

JDBC:与Saiku、BIRT等Java工具集成

RestAPI:与JavaScript、Web网页集成

Kylin开发团队还贡献了Zepplin的插件,也可以使用Zepplin来访问Kylin服务。

3、安装

安装Kylin前需先部署好Hadoop、Hive、Zookeeper、HBase,并且需要在/etc/profile中配置以下环境变量HADOOP_HOME,HIVE_HOME,HBASE_HOME,记得source使其生效。

1)上传Kylin安装包apache-kylin-3.0.1-bin.tar.gz

2)解压apache-kylin-3.0.1-bin.tar.gz到/opt/module

[atguigu@hadoop102 sorfware]$ tar -zxvf apache-kylin-3.0.1-bin.tar.gz -C /opt/module/

 

[atguigu@hadoop102 module]$ mv /opt/module/apache-kylin-3.0.1-bin /opt/module/kylin

3)兼容问题解决

修改/opt/module/kylin/bin/find-hbase-dependency.sh

[atguigu@hadoop102 sorfware]$ vim /opt/module/kylin/bin/find-hbase-dependency.sh

修改内容如下:

35 arr=(`echo $hbase_classpath | cut -d ":" -f 1- | sed 's/:/ /g'`)

 36 hbase_common_path=

 37 for data in ${arr[@]}

 38 do

 39     result=`echo $data | grep -E 'hbase-(common|shaded\-client)[a-z0-9A-Z\.-]*jar' | grep -v tests`

 40     if [ $result ]

 41     then

 42         hbase_common_path=$data

 43     fi

 44 done

4)启动Kylin

(1)启动Kylin之前,需先启动Hadoop(hdfs,yarn,jobhistoryserver)、Zookeeper、Hbase

(2)启动Kylin

[atguigu@hadoop102 kylin]$ bin/kylin.sh start

启动之后查看各个节点进程:

--------------------- hadoop102 ----------------

3360 JobHistoryServer

31425 HMaster

3282 NodeManager

3026 DataNode

53283 Jps

2886 NameNode

44007 RunJar

2728 QuorumPeerMain

31566 HRegionServer

--------------------- hadoop103 ----------------

5040 HMaster

2864 ResourceManager

9729 Jps

2657 QuorumPeerMain

4946 HRegionServer

2979 NodeManager

2727 DataNode

--------------------- hadoop104 ----------------

4688 HRegionServer

2900 NodeManager

9848 Jps

2636 QuorumPeerMain

2700 DataNode

2815 SecondaryNameNode

http://hadoop102:7070/kylin查看Web页面

 

评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值