
如果大家正在按照筆者的教程嘗試使用大數(shù)據(jù)組件還是之前有使用過(guò)相關(guān)的組件,大家會(huì)發(fā)現(xiàn)一個(gè)問(wèn)題HIVE在負(fù)責(zé)的查詢下調(diào)用Mapreduce會(huì)很慢,在這個(gè)場(chǎng)景下就涌現(xiàn)出很多查詢引擎來(lái)優(yōu)化,比如大家熟悉的Spark-SQL,Impala,kilin已經(jīng)今天的主角Presto, Presto以速度和極強(qiáng)的擴(kuò)展性取得了勝利,不僅能夠提高對(duì)HIVE數(shù)據(jù)查詢速度還能和異構(gòu)數(shù)據(jù)庫(kù)進(jìn)行關(guān)聯(lián)查詢,比如HIVE和Mysql進(jìn)行關(guān)聯(lián)查詢,那么我們就來(lái)迫不及待的揭開Presto的廬山真面目
附上:
喵了個(gè)咪的博客: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
設(shè)置環(huán)境變量
vim /etc/profile
# presto
export PRESTO=/usr/local/presto-0.184
export PATH=$PRESTO/bin:$PATH
source /etc/profile
配置文件
先進(jìn)入到presto根目錄下 cd /usr/local/presto-0.184
配置節(jié)點(diǎn)信息
vim etc/node.properties
node.environment=production
node.id=ffffffff-ffff-ffff-ffff-ffffffffffff
node.data-dir=/usr/local/presto-0.184/data
配置jvm相關(guān)參數(shù)
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 相關(guān)的配置,每一個(gè) Presto Server 可以通時(shí)作為 coordinator 和 worker 使用。你可以將他們配置在一個(gè)極點(diǎn)上,但是,在一個(gè)大的集群上建議分開配置以提高性能。
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
可選的,作為測(cè)試,你可以在一個(gè)節(jié)點(diǎn)上同時(shí)配置兩者(我們?cè)趩喂?jié)點(diǎn)上使用先選擇這個(gè)配置):
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
參數(shù)說(shuō)明:
- coordinator:Presto 實(shí)例是否以 coordinator 對(duì)外提供服務(wù)
- node-scheduler.include-coordinator:是否允許在 coordinator 上進(jìn)行調(diào)度任務(wù)(單機(jī)測(cè)試配置為true不然沒有節(jié)點(diǎn)可以使用)
- http-server.http.port:HTTP 服務(wù)的端口
- task.max-memory=1GB:每一個(gè)任務(wù)(對(duì)應(yīng)一個(gè)節(jié)點(diǎn)上的一個(gè)查詢計(jì)劃)所能使用的最大內(nèi)存
- discovery-server.enabled:是否使用 Discovery service 發(fā)現(xiàn)集群中的每一個(gè)節(jié)點(diǎn)。
- discovery.uri:Discovery server 的 url
配置日志等級(jí)
vim etc/log.properties
com.facebook.presto=INFO
Catalog配置
如果你想使用 hive 的連接器,則創(chuàng)建 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
關(guān)于hive的連接器有以下幾種可以更具安裝的hive版本信息進(jìn)行選擇
- hive-cdh5
- hive-cdh4
- hive-hadoop1
- hive-hadoop2
啟動(dòng)HIVE metastore 和 hiveserver2
hive --service metastore
hive --service hiveserver2
啟動(dòng)presto
launcher start -- 后臺(tái)運(yùn)行
launcher run --日志運(yùn)行
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
此時(shí)就可以正常的執(zhí)行SQL 了 ,在數(shù)據(jù)量大的查詢情況下速度基本比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]
關(guān)于查詢出來(lái)的數(shù)據(jù)常常要導(dǎo)出數(shù)據(jù),Presto也提供導(dǎo)出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
# 構(gòu)建Aripal
./gradlew clean shadowJar -Dairpal.useLocalNode
創(chuàng)建mysql數(shù)據(jù)庫(kù)
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;
配置文件設(shè)置
cp reference.example.yml reference.yml
vim reference.yml
# HTTP-specific options.
# 最好查詢?cè)O(shè)置的端口是否被占用。
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
數(shù)據(jù)庫(kù)初始化
java -Duser.timezone=UTC -cp build/libs/airpal-*-all.jar com.airbnb.airpal.AirpalApplication db migrate reference.yml
直接啟動(dòng)Airpal:
java -server -Duser.timezone=UTC -cp build/libs/airpal-*-all.jar com.airbnb.airpal.AirpalApplication server reference.yml
通過(guò)訪問(wèn) IP:8081 即可訪問(wèn)進(jìn)在線查詢

4 總結(jié)
Presto的強(qiáng)大之處不止于此,這里只是簡(jiǎn)單演示通過(guò)Presto來(lái)提高對(duì)HIve的查詢效率,還有更多的功能需要探索,可以參考官網(wǎng)的文檔
注:筆者能力有限有說(shuō)的不對(duì)的地方希望大家能夠指出,也希望多多交流!