博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
Presto的概念和安装使用
阅读量:3882 次
发布时间:2019-05-23

本文共 5409 字,大约阅读时间需要 18 分钟。

一、概念

  1. Pressto时一个开源的分布式SQL查询引擎数据量支持GB到PB字节,主要用来处理秒级查询的场景
  2. 虽然Pressto可以解析SSQL,但它不是一个标准的数据库,不是MySQL、Oracle的代替品,也不能用来出来在线事务(OLTP)

1.1 Presto架构

  1. Coordinator:决策者 -> 解析成MR
  2. Worker:工作者 -> 跑任务
  3. Connector:不同的数据源 不用的Connector
  4. Catalog:一个数据源叫做Catalog

在这里插入图片描述

1.2 Presto优缺点

  1. 基于内存
  2. 跨数据源联表查询(支持Hive join MySQL的联表查询等)
  3. 缺点:对于连表查询,可能产生大量的临时i数据,因此速度会变慢

在这里插入图片描述

1.3 Presto、Impala性能比较

  1. 具体比较:https://blog.csdn.net/u012551524/article/details/79124532

  2. 测试结论:Impala性能稍领先于Presto,但是Presto在数据源支持上非常丰富,包括Hive、图数据库、传统关系型数据库、Redis等。

二、安装Presto Server

2.1 地址

官网地址:https://prestodb.github.io/

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

2.2 解压Presto Server

tar -zxvf presto-server-0.196.tar.gz -C /opt/module/

在这里插入图片描述

2.3 创建存储数据文件夹

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

mkdir data

在这里插入图片描述

2.4 创建存储配置文件文件夹

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

mkdir etc

在这里插入图片描述

2.5 添加配置文件

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

vim jvm.config-server-Xmx16G-XX:+UseG1GC-XX:G1HeapRegionSize=32M-XX:+UseGCOverheadLimit-XX:+ExplicitGCInvokesConcurrent-XX:+HeapDumpOnOutOfMemoryError-XX:+ExitOnOutOfMemoryError

在这里插入图片描述

2.6 配置数据源

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

[atguigu@hadoop102 etc]$ mkdir catalog[atguigu@hadoop102 catalog]$ vim hive.properties connector.name=hive-hadoop2hive.metastore.uri=thrift://hadoop102:9083

在这里插入图片描述

2.7 分发presto

xsync /opt/module/presto-server-0.196/

在这里插入图片描述

2.8 配置node属性

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

[atguigu@hadoop102 etc]$vim node.propertiesnode.environment=productionnode.id=ffffffff-ffff-ffff-ffff-ffffffffffffnode.data-dir=/opt/module/presto-server-0.196/data[atguigu@hadoop103 etc]$vim node.propertiesnode.environment=productionnode.id=ffffffff-ffff-ffff-ffff-fffffffffffenode.data-dir=/opt/module/presto/data[atguigu@hadoop104 etc]$vim node.propertiesnode.environment=productionnode.id=ffffffff-ffff-ffff-ffff-fffffffffffdnode.data-dir=/opt/module/presto-server-0.196/data

在这里插入图片描述

2.9 配置coordinator

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

hadoop102

[atguigu@hadoop102 etc]$ vim config.propertiescoordinator=truenode-scheduler.include-coordinator=falsehttp-server.http.port=8881query.max-memory=50GBdiscovery-server.enabled=truediscovery.uri=http://hadoop102:8881

hadoop103 和hadoop104

[atguigu@hadoop103 etc]$ vim config.propertiescoordinator=falsehttp-server.http.port=8881query.max-memory=50GBdiscovery.uri=http://hadoop102:8881

在这里插入图片描述

2.10 启动Hive Metastore

  1. 在hadoop102的/opt/module/hive目录下,启动Hive Metastore,用atguigu角色
[atguigu@hadoop102 hive]$nohup bin/hive --service metastore >/dev/null 2>&1 &

在这里插入图片描述

2.11 启动Presto Server

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

前台启动:[atguigu@hadoop102 presto-server-0.196]$ bin/launcher run后台启动:bin/launcher start

在这里插入图片描述

在这里插入图片描述

三、安装Presto Client

3.1 下载

下载Presto的客户端

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

3.2 上传

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

在这里插入图片描述

3.3 修改名称

mv presto-cli-0.196-executable.jar  prestocli

在这里插入图片描述

3.4 增加权限

chmod 777 prestocli

在这里插入图片描述

3.5 启动prestocli

-> ./prestocli --server hadoop102:8881 --catalog hive --schema default

在这里插入图片描述

3.6 命令行操作

Presto的命令行操作,相当于Hive命令行操作。每个表必须要加上schema(关系数据库里面的databses概念)。

show schemas;use gmall;select * from gmall.ods_sku_info limit 100;

在这里插入图片描述

四、Presto可视化Client安装

4.1 上传

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

在这里插入图片描述

4.2 解压

unzip yanagishima-18.0.zip

在这里插入图片描述

4.3 编写配置文件

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

jetty.port=7080presto.datasources=atguigu-prestopresto.coordinator.server.atguigu-presto=http://hadoop102:8881catalog.atguigu-presto=hiveschema.atguigu-presto=defaultsql.query.engines=presto

在这里插入图片描述

4.4 启动

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

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

在这里插入图片描述

4.5 查看

启动web页面:http://hadoop102:7080

在这里插入图片描述

4.6 使用

select * from hive.gmall.ads_back_count limit 100

在这里插入图片描述

五、优化

5.1 合理设置分区

与Hive类似,Presto会根据元数据信息读取分区数据,合理的分区能减少Presto数据读取量,提升查询性能。

5.2 使用列式存储

Presto对ORC文件读取做了特定优化,因此在Hive中创建Presto使用的表时,建议采用ORC格式存储。相对于Parquet,Presto对ORC支持更好。

5.3 使用压缩

数据压缩可以减少节点间数据传输对IO带宽压力,对于即席查询需要快速解压,建议采用Snappy压缩。

5.4 只选择使用的字段

由于采用列式存储,选择需要的字段可加快字段的读取、减少数据量。避免采用*读取所有字段。

5.5 过滤条件必须加上分区字段

对于有分区的表,where语句中优先使用分区字段进行过滤。acct_day是分区字段,visit_time是具体访问时间。

[GOOD]: SELECT time, user, host FROM tbl where acct_day=20171101[BAD]:  SELECT * FROM tbl where visit_time=20171101

5.6 Group By语句优化

合理安排Group by语句中字段顺序对性能有一定提升。将Group By语句中字段按照每个字段distinct数据多少进行降序排列。

[GOOD]: SELECT GROUP BY uid, gender[BAD]:  SELECT GROUP BY gender, uid

5.7 Order by时使用Limit

Order by需要扫描数据到单个worker节点进行排序,导致单个worker需要大量内存。如果是查询Top N或者Bottom N,使用limit可减少排序计算和内存压力。

[GOOD]: SELECT * FROM tbl ORDER BY time LIMIT 100[BAD]:  SELECT * FROM tbl ORDER BY time

5.8 使用Join语句时将大表放在左边

Presto中join的默认算法是broadcast join,即将join左边的表分割到多个worker,然后将join右边的表数据整个复制一份发送到每个worker进行计算。如果右边的表数据量太大,则可能会报内存溢出错误。

[GOOD] SELECT ... FROM large_table l join small_table s on l.id = s.id[BAD] SELECT ... FROM small_table s join large_table l on l.id = s.id

六、注意事项

6.1 字段名引用

避免和关键字冲突:MySQL对字段加反引号`、Presto对字段加双引号分割

当然,如果字段名称不是关键字,可以不加这个双引号。

6.2 时间函数

对于Timestamp,需要进行比较的时候,需要添加Timestamp关键字,而MySQL中对Timestamp可以直接进行比较。

/*MySQL的写法*/SELECT t FROM a WHERE t > '2017-01-01 00:00:00'; /*Presto中的写法*/SELECT t FROM a WHERE t > timestamp '2017-01-01 00:00:00';

6.3 不支持INSERT OVERWRITE语法

Presto中不支持insert overwrite语法,只能先delete,然后insert into。

6.4 PARQUET格式

Presto目前支持Parquet格式,支持查询,但不支持insert。

七、Life

原谅敌人要比原谅朋友容易。——狄尔治夫人在这里插入图片描述

你可能感兴趣的文章
SAP HANA CREATE USER
查看>>
SAP HANA index type
查看>>
SAP HANA SQL GROUP BY / ORDER BY / OVER / CASE
查看>>
gethostbyname和gethostbyaddr的用法
查看>>
IPv6和IPv4之间的通信机制和方法
查看>>
用syslog记录UNIX日志
查看>>
syslog(),openlog(),closelog()
查看>>
Ubuntu安装后的一些配置
查看>>
ubuntu9.10 tftp服务设置(这个绝对好使)
查看>>
关于UNIXDOMAIN协议的接收发送者验证
查看>>
I/O操作上设置超时之alarm闹钟法
查看>>
查看返回接收到UDP数据包的宿地址结构--(适用于LINUX和BSD系统)
查看>>
如何开启_GNU_SOURCE宏
查看>>
从网上搜索到的一些关于pcap源代码,入门级的
查看>>
Linux—— Posix IPC
查看>>
在ubuntu下安装ACE编译环境
查看>>
公司HR面试经常问的问题及回答思路
查看>>
ACE之反应堆学习(一)
查看>>
apache配置
查看>>
快速精通FRAME
查看>>