安裝和部署Presto

1. 安裝環境

  • 操做系統:CentOs6.5
  • Hadoop 集羣:CDH5.3
  • JDK 版本:jdk1.8.0_31

爲了測試簡單,我是將 Presto 的 coordinator 和 worker 都部署在 cdh1 節點上,而且該節點上部署了 hive-metastore 服務。下面的安裝和部署過程參考自 http://prestodb.io/docs/current/installation.htmlhtml

2. 安裝 Presto

下載 Presto 的壓縮包,目前最新版本爲 presto-server-0.90,而後解壓爲 presto-server-0.90 。java

wget https://repo1.maven.org/maven2/com/facebook/presto/presto-server/0.90/presto-server-0.90.tar.gz
tar zxvf presto-server-0.90.tar.gz

解壓後的目錄結構爲:node

[$ presto-server-0.90]# tree -L 2
.
├── bin
│   ├── launcher
│   ├── launcher.properties
│   ├── launcher.py
│   └── procname
├── lib
├── NOTICE
├── plugin
│   ├── cassandra
│   ├── example-http
│   ├── hive-cdh4
│   ├── hive-cdh5
│   ├── hive-hadoop1
│   ├── hive-hadoop2
│   ├── kafka
│   ├── ml
│   ├── mysql
│   ├── postgresql
│   ├── raptor
│   └── tpch
└── README.txt

從 plugin 目錄能夠看到全部 Presto 支持的插件有哪些,這裏我主要使用 hive-cdh5 插件,也成爲鏈接器。mysql

3. 配置 Presto

在 presto-server-0.90 目錄建立 etc 目錄,並建立如下文件:web

  • node.properties:每一個節點的環境配置
  • jvm.config:jvm 參數
  • config.properties:配置 Presto Server 參數
  • log.properties:配置日誌等級
  • Catalog Properties:Catalog 的配置

etc/node.properties 示例配置以下:sql

propertiesnode.environment=production
node.id=ffffffff-ffff-ffff-ffff-ffffffffffff
node.data-dir=/var/presto/data

參數說明:數據庫

  • node.environment:環境名稱。一個集羣節點中的全部節點的名稱應該保持一致。
  • node.id:節點惟一標識的名稱。
  • node.data-dir:數據和日誌存放路徑。

etc/jvm.config 示例配置以下:bash

sql-server
-Xmx16G
-XX:+UseConcMarkSweepGC
-XX:+ExplicitGCInvokesConcurrent
-XX:+CMSClassUnloadingEnabled
-XX:+AggressiveOpts
-XX:+HeapDumpOnOutOfMemoryError
-XX:OnOutOfMemoryError=kill -9 %p
-XX:ReservedCodeCacheSize=150M

etc/config.properties 包含 Presto Server 相關的配置,每個 Presto Server 能夠通時做爲 coordinator 和 worker 使用。你能夠將他們配置在一個極點上,可是,在一個大的集羣上建議分開配置以提升性能。less

coordinator 的最小配置:jvm

propertiescoordinator=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 的最小配置:

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

可選的,做爲測試,你能夠在一個節點上同時配置二者:

propertiescoordinator=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 上進行調度任務
  • http-server.http.port:HTTP 服務的端口
  • task.max-memory=1GB:每個任務(對應一個節點上的一個查詢計劃)所能使用的最大內存
  • discovery-server.enabled:是否使用 Discovery service 發現集羣中的每個節點。
  • discovery.uri:Discovery server 的 url

etc/log.properties 能夠設置某一個 java 包的日誌等級:

propertiescom.facebook.presto=INFO

關於 Catalog 的配置,首先須要建立 etc/catalog 目錄,而後根據你想使用的鏈接器來建立對應的配置文件,好比,你想使用 jmx 鏈接器,則建立 jmx.properties:

propertiesconnector.name=jmx

若是你想使用 hive 的鏈接器,則建立 hive.properties:

propertiesconnector.name=hive-cdh5
hive.metastore.uri=thrift://cdh1:9083  #修改成 hive-metastore 服務所在的主機名稱,這裏我是安裝在 cdh1節點
hive.config.resources=/etc/hadoop/conf/core-site.xml,/etc/hadoop/conf/hdfs-site.xml

更多關於鏈接器的說明,請參考 Connectors

4. 運行 Presto

你可使用下面命令後臺啓動:

bin/launcher start

也能夠前臺啓動,觀察輸出日誌:

bin/launcher run

另外,你也能夠經過下面命令中止:

bin/launcher stop

更多命令,你能夠經過 --help 參數來查看。

bash[root@cdh1 presto-server-0.90]# bin/launcher --help
Usage: launcher [options] command

Commands: run, start, stop, restart, kill, status

Options:
  -h, --help            show this help message and exit
  -v, --verbose         Run verbosely
  --launcher-config=FILE
                        Defaults to INSTALL_PATH/bin/launcher.properties
  --node-config=FILE    Defaults to INSTALL_PATH/etc/node.properties
  --jvm-config=FILE     Defaults to INSTALL_PATH/etc/jvm.config
  --config=FILE         Defaults to INSTALL_PATH/etc/config.properties
  --log-levels-file=FILE
                        Defaults to INSTALL_PATH/etc/log.properties
  --data-dir=DIR        Defaults to INSTALL_PATH
  --pid-file=FILE       Defaults to DATA_DIR/var/run/launcher.pid
  --launcher-log-file=FILE
                        Defaults to DATA_DIR/var/log/launcher.log (only in daemon mode)
  --server-log-file=FILE
                        Defaults to DATA_DIR/var/log/server.log (only in daemon mode)
  -D NAME=VALUE         Set a Java system property

啓動以後,你能夠觀察 /var/presto/data/ 目錄:

[root@cdh1 /var/presto/data/]# tree
.
├── etc -> /opt/presto-server-0.90/etc
├── plugin -> /opt/presto-server-0.90/plugin
└── var
    ├── log
    │   ├── http-request.log
    │   ├── launcher.log
    │   └── server.log
    └── run
        └── launcher.pid

5 directories, 4 files

在 /var/presto/data/var/log 目錄能夠查看日誌:

  • launcher.log:啓動日誌
  • server.log:Presto Server 輸出日誌
  • http-request.log:HTTP 請求日誌

5. 測試 Presto CLI

下載 presto-cli-0.90-executable.jar 並將其重命名爲 presto-cli(你也能夠重命名爲 presto),而後添加執行權限。

運行下面命令進行測試:

bash[root@cdh1 bin]# ./presto-cli --server localhost:8080 --catalog hive --schema default
presto:default> show tables;
 Table
-------
(0 rows)

Query 20150126_062137_00012_qgwvy, FINISHED, 1 node
Splits: 2 total, 2 done (100.00%)
0:00 [0 rows, 0B] [0 rows/s, 0B/s]

在 執行 show tables 命令以前,你能夠查看 http://cdh1:8080/ 頁面:

而後在執行該命令以後再觀察頁面變化。單擊第一行記錄,會跳轉到明細頁面:

能夠運行 --help 命令查看更多參數,例如你能夠在命令行直接運行下面命令:

./presto-cli --server localhost:8080 --catalog hive --schema default --execute "show tables;"

默認狀況下,Presto 的查詢結果是使用 less 程序分頁輸出的,你能夠經過修改環境變量 PRESTO_PAGER 的值將其改成其餘命令,如 more,或者將其置爲空以禁止分頁輸出。

6. 測試 jdbc

使用 jdbc 鏈接 Presto,須要下載 jdbc 驅動 presto-jdbc-0.90 並將其加到你的應用程序的 classpath 中。

支持如下幾種 JDBC URL 格式:

jdbc:presto://host:port
jdbc:presto://host:port/catalog
jdbc:presto://host:port/catalog/schema

鏈接 hive 數據庫中 sales 庫,示例以下:

jdbc:presto://cdh1:8080/hive/sales

7. 總結

本文主要記錄 Presto 的安裝部署過程,並使用 hive-cdh5 鏈接器進行簡單測試。下一步,須要基於一些生產數據作一些功能測試以及和 impala 作一些對比測試。

相關文章
相關標籤/搜索