Presto的安装与配置,进行大数据集上的交互式查询

person ~~情~非~    watch_later 2024-07-20 17:35:46
visibility 179    class 大数据,Presto    bookmark 专栏

Presto的安装与配置,进行大数据集上的交互式查询

什么是Presto

Presto是一个分布式SQL查询引擎,用于对各种数据源进行交互式分析查询。它最初由Facebook开发,旨在提供快速、低延迟的查询性能。Presto可以连接到多个数据源,包括HDFS、Hive、Cassandra、MySQL、PostgreSQL等。

Presto的关键特性

  1. 高性能:优化的查询引擎,支持高效的数据扫描和处理。
  2. 多数据源支持:能够同时查询多个不同的数据源。
  3. 扩展性:分布式架构,易于扩展。
  4. ANSI SQL兼容:支持大部分ANSI SQL语法。

Presto的安装与配置

环境准备

  • 操作系统:建议使用Linux(如Ubuntu、CentOS等)。
  • Java:需要安装Java 8或更高版本。

安装Presto

  1. 下载Presto

    从Presto的GitHub页面下载最新版本:https://prestosql.io/download.html

    wget https://repo1.maven.org/maven2/io/prestosql/presto-server/348/presto-server-348.tar.gz
    
  2. 解压Presto

    tar -xzf presto-server-348.tar.gz
    mv presto-server-348 /usr/local/presto
    
  3. 安装Presto CLI

    Presto CLI用于执行SQL查询。

    wget https://repo1.maven.org/maven2/io/prestosql/presto-cli/348/presto-cli-348-executable.jar
    mv presto-cli-348-executable.jar /usr/local/presto/presto-cli
    chmod +x /usr/local/presto/presto-cli
    

配置Presto

  1. 创建配置目录

    mkdir -p /usr/local/presto/etc
    
  2. 配置节点属性

    编辑/usr/local/presto/etc/node.properties文件:

    node.environment=production
    node.id=ffffffff-ffff-ffff-ffff-ffffffffffff
    node.data-dir=/usr/local/presto/data
    
  3. 配置JVM属性

    编辑/usr/local/presto/etc/jvm.config文件:

    -server
    -Xmx16G
    -XX:-UseBiasedLocking
    -XX:+UseG1GC
    -XX:G1HeapRegionSize=32M
    -XX:+UseGCOverheadLimit
    -XX:+ExplicitGCInvokesConcurrent
    -XX:+HeapDumpOnOutOfMemoryError
    -XX:+ExitOnOutOfMemoryError
    
  4. 配置节点角色

    编辑/usr/local/presto/etc/config.properties文件:

    coordinator=true
    node-scheduler.include-coordinator=true
    http-server.http.port=8080
    query.max-memory=5GB
    query.max-memory-per-node=1GB
    discovery-server.enabled=true
    discovery.uri=http://localhost:8080
    
  5. 配置日志属性

    编辑/usr/local/presto/etc/log.properties文件:

    com.facebook.presto=INFO
    
  6. 配置连接器

    创建Hive连接器配置文件/usr/local/presto/etc/catalog/hive.properties

    connector.name=hive-hadoop2
    hive.metastore.uri=thrift://localhost:9083
    

启动Presto

  1. 启动Presto服务器

    /usr/local/presto/bin/launcher start
    
  2. 检查Presto服务器状态

    /usr/local/presto/bin/launcher status
    
  3. 访问Presto UI

    打开浏览器,访问http://localhost:8080,进入Presto的Web UI。

使用Presto进行交互式查询

连接Presto CLI

  1. 启动Presto CLI

    /usr/local/presto/presto-cli --server localhost:8080 --catalog hive --schema default
    
  2. 执行SQL查询

    在Presto CLI中执行SQL查询,例如:

    SELECT * FROM my_table LIMIT 10;
    

配置Presto连接多个数据源

配置MySQL连接器

  1. 创建MySQL连接器配置文件

    编辑/usr/local/presto/etc/catalog/mysql.properties

    connector.name=mysql
    connection-url=jdbc:mysql://localhost:3306
    connection-user=root
    connection-password=your_password
    
  2. 重启Presto服务器

    /usr/local/presto/bin/launcher restart
    
  3. 在Presto CLI中查询MySQL数据

    SELECT * FROM mysql.information_schema.tables LIMIT 10;
    

高级配置和优化

配置内存和并行度

  1. 修改config.properties文件中的内存配置

    query.max-memory=10GB
    query.max-memory-per-node=2GB
    
  2. 设置并行度

    task.max-worker-threads=16
    

使用Ranger进行权限管理

  1. 安装Apache Ranger

    安装并配置Apache Ranger,用于集中管理Presto的访问控制。

  2. 配置Ranger插件

    在Presto配置目录中,编辑Ranger插件配置文件,启用权限管理。

总结

通过掌握Presto的基本概念、安装与配置方法,以及如何使用Presto进行交互式查询,你可以构建一个高效的分布式查询平台。Presto的多数据源支持和高性能查询能力,使其成为大数据分析的理想工具。

评论区
评论列表
menu