Presto使用指南
更新时间:2024-03-13
概览
Presto是Facebook开发的数据查询引擎,可对海量数据进行快速地交互式分析,支持Hive,关系数据库等多种数据源。由于 BOS 在超低价格、超高性能、高可靠和高吞吐的强大存储优势,越来越多企业选择 BOS 作为大数据的存储媒介。因此,本文将对Presto在 BOS 上的使用方法作一个简要的介绍。
前提条件
参考Hive使用指南一文安装并配置Hive
安装配置
安装版本为349,可参考presto部署一文的过程。其中,如果本机也作为worker,在config.properties中可设置:
Bash
1node-scheduler.include-coordinator=true #需要改为true
在etc/catalog/hive.properties中,配置为:
Bash
1connector.name=hive-hadoop2
2hive.config.resources=/ssd2/hadoop-3.3.2/etc/hadoop/core-site.xml,/ssd2/hadoop-3.3.2/etc/hadoop/hdfs-site.xml #这里的地址一定要正确
3hive.metastore.uri=thrift://127.0.0.1:9083
4hive.allow-drop-table=false
5hive.storage-format=ORC
6hive.metastore-cache-ttl=1s
7hive.metastore-refresh-interval=1s
8hive.metastore-timeout=35m
9hive.max-partitions-per-writers=1000
10hive.cache.enabled=true
11hive.cache.location=/opt/hive-cache
把bos filesystem的jar包复制到plugin/hive-hadoop2/下,之后运行:
Bash
1./bin/launcher start
启动presto-server,
Bash
1./presto-cli --server localhost:8881 --catalog hive --schema default
运行
Bash
1presto:default>use hive;
2 USE
3 presto:hive>select * from hive_test limit 10;
4 a | b
5-------+----------
6 11027 | "11345"
7 10227 | "24281"
8 32535 | "16409"
9 24286 | "24435"
10 2498 | "10969"
11 16662 | "16163"
12 5345 | "26005"
13 21407 | "5365"
14 30608 | "4588"
15 19686 | "11831"
16 (10 rows)
17
18Query 20230601_084130_00004_dzvjb, FINISHED, 1 node
19Splits: 18 total, 18 done (100.00%)
20[Latency: client-side: 0:02, server-side: 0:02] [59.4K rows, 831KB] [28.9K rows/s, 404KB/s]
在以上示例中,我们就通过presto查询到了存储在bos中的数据。
基于S3的presto访问
presto访问存储在BOS中的数据只能是通过hive,但是hive访问BOS中的数据有两种方式,第一种就是通过上述的介绍,基于bos-hdfs;第二种就是直接通过S3协议访问BOS。
hive配置
安装metastore:
Bash
1wget "https://repo1.maven.org/maven2/org/apache/hive/hive-standalone-metastore/3.1.2/hive-standalone-metastore-3.1.2-bin.tar.gz"
2tar -zxvf hive-standalone-metastore-3.1.2-bin.tar.gz
3sudo mv apache-hive-metastore-3.1.2-bin /usr/local/metastore
4sudo chown user:user /usr/local/metastore
下载并使用hive-standalone-metastore,增加必需的jar包:
Bash
1rm /usr/local/metastore/lib/guava-19.0.jar
2cp /usr/local/hadoop/share/hadoop/common/lib/guava-27.0-jre.jar \
3 /usr/local/metastore/lib/
4cp /usr/local/hadoop/share/hadoop/tools/lib/hadoop-aws-3.2.1.jar \
5 /usr/local/metastore/lib/
6cp /usr/local/hadoop/share/hadoop/tools/lib/aws-java-sdk-bundle-1.11.375.jar \
7 /usr/local/metastore/lib/
之后配置/usr/local/metastore/conf/metastore-site.xml
XML
1<property>
2 <name>javax.jdo.option.ConnectionURL</name>
3 <value>jdbc:mysql://localhost/metastore?createDatabaseIfNotExist=true</value>
4</property>
5<property>
6 <name>javax.jdo.option.ConnectionDriverName</name>
7 <value>com.mysql.jdbc.Driver</value>
8</property>
9<property>
10 <name>javax.jdo.option.ConnectionUserName</name>
11 <value>hive</value>
12</property>
13<property>
14 <name>javax.jdo.option.ConnectionPassword</name>
15 <value>hive</value>
16</property>
17<property>
18 <name>hive.metastore.event.db.notification.api.auth</name>
19 <value>false</value>
20</property>
21<property>
22 <name>fs.s3a.access.key</name>
23 <value>S3_ACCESS_KEY</value>
24</property>
25<property>
26 <name>fs.s3a.secret.key</name>
27 <value>S3_SECRET_KEY</value>
28</property>
29<property>
30 <name>fs.s3a.connection.ssl.enabled</name>
31 <value>false</value>
32</property>
33<property>
34 <name>fs.s3a.path.style.access</name>
35 <value>true</value>
36</property>
37<property>
38 <name>fs.s3a.endpoint</name>
39 <value>S3_ENDPOINT</value>
40</property>
fs.s3a.endpoint 是指s3 的endponit,bos的s3 endpoint在BOS S3域名可查.
启动hive metastore:
Bash
1/usr/local/metastore/bin/start-metastore &
presto配置
preto的版本这里不作改变,hive.properties的内容改为:
Bash
1connector.name=hive-hadoop2
2hive.metastore.uri=thrift://localhost:9083
3hive.s3.path-style-access=true
4hive.s3.endpoint=S3_ENDPOINT
5hive.s3.aws-access-key=S3_ACCESS_KEY
6hive.s3.aws-secret-key=S3_SECRET_KEY
7hive.s3.ssl.enabled=false
启动presto
Bash
1/usr/local/trino/bin/launcher start
创建schema
Bash
1CREATE SCHEMA IF NOT EXISTS hive.iris
2WITH (location = 's3a://my-bos-bucket/'); //注意,这里的location就是以s3a开头,如果bucket为my-bos-bucket,则location应为s3a://my-bos-bucket/开头
3#创建表
4CREATE TABLE IF NOT EXISTS hive.iris.iris_parquet (
5 sepal_length DOUBLE,
6 sepal_width DOUBLE,
7 petal_length DOUBLE,
8 petal_width DOUBLE,
9 class VARCHAR
10)
11WITH (
12 external_location = 's3a://my-bos-bucket/iris_parquet',
13 format = 'PARQUET'
14);
15
16SELECT
17 sepal_length,
18 class
19FROM hive.iris.iris_parquet
20LIMIT 10;