相关推荐recommended
[喵咪大数据]Presto查询引擎
作者:mmseoamin日期:2024-03-20

[喵咪大数据]Presto查询引擎,第1张

如果大家正在按照笔者的教程尝试使用大数据组件还是之前有使用过相关的组件,大家会发现一个问题HIVE在负责的查询下调用Mapreduce会很慢,在这个场景下就涌现出很多查询引擎来优化,比如大家熟悉的Spark-SQL,Impala,kilin已经今天的主角Presto, Presto以速度和极强的扩展性取得了胜利,不仅能够提高对HIVE数据查询速度还能和异构数据库进行关联查询,比如HIVE和Mysql进行关联查询,那么我们就来迫不及待的揭开Presto的庐山真面目

附上:

喵了个咪的博客:w-blog.cn Presto文档 — Presto 0.100 Documentation

1.安装Presto

ca /app/install
wget https://repo1.maven.org/maven2/com/facebook/presto/presto-server/0.184/presto-server-0.184.tar.gz
tar -zxvf presto-server-0.184.tar.gz
mv presto-server-0.184 /usr/local/presto-0.184

设置环境变量

vim /etc/profile
# presto
export PRESTO=/usr/local/presto-0.184
export PATH=$PRESTO/bin:$PATH
source /etc/profile

配置文件

先进入到presto根目录下 cd /usr/local/presto-0.184

配置节点信息

vim etc/node.properties
node.environment=production
node.id=ffffffff-ffff-ffff-ffff-ffffffffffff
node.data-dir=/usr/local/presto-0.184/data

配置jvm相关参数

vim etc/jvm.config
-server
-Xmx16G
-XX:+UseConcMarkSweepGC
-XX:+ExplicitGCInvokesConcurrent
-XX:+CMSClassUnloadingEnabled       -XX:+AggressiveOpts
-XX:+HeapDumpOnOutOfMemoryError
-XX:OnOutOfMemoryError=kill -9 %p
-XX:ReservedCodeCacheSize=150M

Presto Server 相关的配置,每一个 Presto Server 可以通时作为 coordinator 和 worker 使用。你可以将他们配置在一个极点上,但是,在一个大的集群上建议分开配置以提高性能。

vim etc/config.properties
coordinator=true
node-scheduler.include-coordinator=true
http-server.http.port=8080
discovery-server.enabled=true
discovery.uri=http://hadoop-1:8080

coordinator 的最小配置:

coordinator=true
node-scheduler.include-coordinator=false
http-server.http.port=8080
task.max-memory=1GB
discovery-server.enabled=true
discovery.uri=http://cdh1:8080

worker 的最小配置:

coordinator=false
http-server.http.port=8080
task.max-memory=1GB
discovery.uri=http://cdh1:8080

可选的,作为测试,你可以在一个节点上同时配置两者(我们在单节点上使用先选择这个配置):

coordinator=true
node-scheduler.include-coordinator=true
http-server.http.port=8080
task.max-memory=1GB
discovery-server.enabled=true
discovery.uri=http://cdh1:8080

参数说明:

  • coordinator:Presto 实例是否以 coordinator 对外提供服务
  • node-scheduler.include-coordinator:是否允许在 coordinator 上进行调度任务(单机测试配置为true不然没有节点可以使用)
  • http-server.http.port:HTTP 服务的端口
  • task.max-memory=1GB:每一个任务(对应一个节点上的一个查询计划)所能使用的最大内存
  • discovery-server.enabled:是否使用 Discovery service 发现集群中的每一个节点。
  • discovery.uri:Discovery server 的 url

    配置日志等级

    vim etc/log.properties
    com.facebook.presto=INFO
    

    Catalog配置

    如果你想使用 hive 的连接器,则创建 hive.properties:

    mkdir etc/catalog
    vim etc/catalog/hive.properties
    connector.name=hive-hadoop2
    hive.metastore.uri=thrift://hadoop-1:9083
    hive.config.resources=/usr/local/hadoop-2.7.3/etc/hadoop/core-site.xml,/usr/local/hadoop-2.7.3/etc/hadoop/hdfs-site.xml
    

    关于hive的连接器有以下几种可以更具安装的hive版本信息进行选择

    • hive-cdh5
    • hive-cdh4
    • hive-hadoop1
    • hive-hadoop2

      启动HIVE metastore 和 hiveserver2

      hive --service metastore
      hive --service hiveserver2
      

      启动presto

      launcher start  -- 后台运行
      launcher run   --日志运行
      launcher stop  --停止
      

      2.使用presto-cli查询

      cd /usr/local/presto-0.184/bin/
      wget https://repo1.maven.org/maven2/com/facebook/presto/presto-cli/0.184/presto-cli-0.184-executable.jar
      mv presto-cli-0.184-executable.jar presto-cli
      chmod -R 777 presto-cli
      presto-cli --server hadoop-1:8080 --catalog hive --schema default
      

      此时就可以正常的执行SQL 了 ,在数据量大的查询情况下速度基本比Hive快了5-6倍

      presto:default> show tables;
           Table      
      ----------------
       employee       
      (11 rows)
      Query 20170919_031227_00002_mmfcn, FINISHED, 1 node
      Splits: 18 total, 18 done (100.00%)
      0:00 [11 rows, 327B] [35 rows/s, 1.03KB/s]
      

      关于查询出来的数据常常要导出数据,Presto也提供导出CSV文件的方式

      presto-cli --server hadoop-1:8080 --catalog hive --schema default --execute "select msn,count(*) from apilog where apiname = 'Classify.categoryAppList' group by msn;"  --output-format CSV_HEADER > Classify.csv
      

      3. 在线管理工具Airpal

      cd /usr/local/
      git clone https://github.com/airbnb/airpal.git
      cd airpal
      # 构建Aripal
      ./gradlew clean shadowJar -Dairpal.useLocalNode
      

      创建mysql数据库

      mysql -u root -p
      mysql> CREATE DATABASE airpal;
      mysql> USE airpal;
      mysql> CREATE USER 'airpal'@'localhost' IDENTIFIED BY 'airpal';
      mysql> GRANT ALL ON airpal.* TO 'airpal'@'localhost' IDENTIFIED BY 'airpal';
      mysql> GRANT ALL ON airpal.* TO 'airpal'@'%' IDENTIFIED BY 'airpal';
      mysql> FLUSH PRIVILEGES;
      mysql> quit;
      

      配置文件设置

      cp reference.example.yml reference.yml   
      vim reference.yml
          # HTTP-specific options.
          # 最好查询设置的端口是否被占用。
          server:
          applicationConnectors:
              - type: http
              port: 8081
              idleTimeout: 10 seconds
          adminConnectors:
              - type: http
              port: 8082
          shiro:
          iniConfigs: ["classpath:shiro_allow_all.ini"]
          dataSourceFactory:
          driverClass: com.mysql.jdbc.Driver
          user: airpal
          password: passwd
          url: jdbc:mysql://localhost:3306/airpal
          flywayFactory:
          locations: ["classpath:db.migration.common", "classpath:db.migration.mysql"]
          # The URL to the Presto coordinator.
          prestoCoordinator: http://prestoCoor:9098
      

      数据库初始化

      java -Duser.timezone=UTC -cp build/libs/airpal-*-all.jar com.airbnb.airpal.AirpalApplication db migrate reference.yml
      

      直接启动Airpal:

      java -server -Duser.timezone=UTC -cp build/libs/airpal-*-all.jar com.airbnb.airpal.AirpalApplication server reference.yml
      

      通过访问 IP:8081 即可访问进在线查询

      [喵咪大数据]Presto查询引擎,第2张

      4 总结

      Presto的强大之处不止于此,这里只是简单演示通过Presto来提高对HIve的查询效率,还有更多的功能需要探索,可以参考官网的文档

      注:笔者能力有限有说的不对的地方希望大家能够指出,也希望多多交流!

      作者:文振熙

      原文地址:https://my.oschina.net/wenzhenxi/blog/1610917