Presto on Alluxio By Alluxio SDS 單節點搭建

語言: CN / TW / HK

一、總體架構

急性子,想直接實操的,先繞過這個章節,直接看後邊的實操步驟。把環境執行起來再看原理。Presto 的架構如下圖所示,client 的請求,會遞交給 Coordinator 進行處理,而元資料資訊由 HiveMetaStore(HMS) 進行管理。那麼表或分割槽的 location 資訊,也在 HMS 中存放,因此,如果想把表或分割槽的資料放到其它儲存系統裡,則不得不修改HMS的資訊,這增加了 HMS 的維護成本,而且HMS是全域性共享服務,它修改了,其它計算框架就沒有辦法保持訪問原來的路徑了。

Alluxio Structure Data Service(SDS) 提供了一個位於 Presto 和底層 HMS 之間的服務,Presto 的 hive-hadoop2 connector 外掛可以把 Alluxio master 當做 metadata服務,而 Alluxio master 中的 SDS 模組會與底層 HMS 通訊,獲取底層的 metadata,並且做一些處理,返回給 Presto 加工後的結果。Presto 拿到的位置資訊,如果是 alluxio地址,則 Presto 將會從 Alluxio 讀取資料,這樣實現了不修改 HMS 也可以讓 Presto 的訪問轉換到 Alluxio 的目的。

二、搭建過程

本文用以下軟體環境進行搭建。由於 hive、presto、alluxio 都是以 hadoop 相容檔案系統 API 進行檔案系統訪問,因此底層儲存,可以是本地,也可以是 hdfs 。本文重點並不是儲存系統,因此使用 file sheme,以本地儲存為底層儲存。如果想使用 hdfs 進行搭建,可以參考“可選項”章節。

三、配置環境變數

1 export HADOOP_HOME=/softwares/hadoop-2.8.5
2 export JAVA_HOME=/usr/java/jdk1.8.0_291-amd64/
3 export HIVE_CONF_DIR=/softwares/apache-hive-2.3.5-bin/conf
4 export HIVE_AUX_JARS_PATH=/softwares/apache-hive-2.3.5-bin/lib
5 export HIVE_HOME=/softwares/apache-hive-2.3.5-bin

四、搭建過程

搭建 mysql

1 # 使用主機網路,或匯出埠
2 docker run --net=host  -p 3306:3306 --name mysql -e MYSQL_ROOT_PASSWORD=123456 -d mysql:5.7
3 # 建立 hive 使用者,密碼為 hive
4 create database metastore;
5 grant all on metastore.* to [email protected]'%'  identified by 'hive';
6 grant all on metastore.* to [email protected]'localhost'  identified by 'hive';
7 flush privileges;

安裝 Hive 和 mysql connector

1 wget http://archive.apache.org/dist/hive/hive-2.3.5/apache-hive-2.3.5-bin.tar.gz
2 tar -xzvf apache-hive-2.3.5-bin.tar.gz
3 mv apache-hive-2.3.5-bin /softwares/
4 mv mysql-connector-java-5.1.38.jar /softwares/apache-hive-2.3.5-bin/lib

以下是相關的配置檔案設定。

  • conf/hive-env.sh

    1 export METASTORE_PORT=9083

  • hive-site.xml

    1 2 3 javax.jdo.option.ConnectionURL 4 jdbc:mysql://127.0.0.1:3306/metastore?createDatabaseIfNotExist=true&characterEncoding=UTF-8&useSSL=false 5 JDBC connection string used by Hive Metastore 6 7 8 javax.jdo.option.ConnectionDriverName 9 com.mysql.jdbc.Driver 10 JDBC Driver class 11 12 13 javax.jdo.option.ConnectionUserName 14 hive 15 Metastore database user name 16 17 18 javax.jdo.option.ConnectionPassword 19 hive 20 Metastore database password 21 22 23 hive.metastore.uris 24 thrift://127.0.0.1:9084 25 Thrift server hostname and port 26 27

啟動 MetaStore

1 bin/schematool -dbType mysql -initSchema hive hive
2 bin/hive --service metastore -p 9083

hive 建立 schema 和 table

  • /root/testdb/person/person.csv 檔案

    1 mary 18 1000 2 john 19 1001 3 jack 16 1002 4 luna 17 1003

    1 create schema test; 2 create external table test.person(name string, age int, id int) row format delimited fields terminated by ' ' location 'file:///root/testdb/person';

五、搭建Presto

安裝高版本 JAVA

1 # download jdk rpm package
2 yum localinstall jdk-8u291-linux-x64.rpm
3 alternatives --config java

安裝 Presto

1 wget http://repo1.maven.org/maven2/com/facebook/presto/presto-server/0.252/presto-server-0.252.tar.gz
2 tar -xzvf presto-server-0.252.tar.gz
3 mv presto-server-0.252 /softwares/
4 mkdir -p /softwares/presto-server-0.252/etc/catalog
5 # 以下這些配置檔案,都需要建立和配置
6 tree /softwares/presto-server-0.252/etc                  
7  ├── catalog
8  │   ├── hive.properties
9  │   └── jmx.properties
10 ├── config.properties
11 ├── jvm.config
12 ├── log.properties
13 └── node.properties

準備配置檔案

  • node.properties

    1 node.environment=production 2 node.id=node01 3 node.data-dir=/softwares/presto-server-0.252/var/presto/data

  • config.properties

    1 coordinator=true 2 node-scheduler.include-coordinator=true 3 http-server.http.port=8080 4 query.max-memory=2GB 5 query.max-memory-per-node=1GB 6 discovery-server.enabled=true 7 discovery.uri=http://localhost:8080

  • jvm.config

    1 -server 2 -Xmx4G 3 -XX:+UseConcMarkSweepGC 4 -XX:+ExplicitGCInvokesConcurrent 5 -XX:+CMSClassUnloadingEnabled 6 -XX:+AggressiveOpts 7 -XX:+HeapDumpOnOutOfMemoryError 8 -XX:OnOutOfMemoryError=kill -9 %p 9 -XX:ReservedCodeCacheSize=150M

  • log.properties

    1 com.facebook.presto=INF0

  • hive.properties

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

執行 Presto Server

1 bin/launcher start

執行 presto cli

1 wget http://repo1.maven.org/maven2/com/facebook/presto/presto-cli/0.252/presto-cli-0.252-executable.jar
2 chmod +x presto-cli-0.252-executable.jar
3 mv presto-cli-0.252-executable.jar /softwares/presto-server-0.252/
4 ./presto-cli-0.252-executable.jar --catalog hive --schema test
5 show schemas from hive;
6 show tables from hive.test;
7 select * from hive.test.person;
8 select count(*) from person;

六、搭建 Alluxio

安裝 Alluxio[略]

  • alluxio-site.properties

    1 alluxio.master.hostname=localhost

執行 Alluxio[略]

1 bin/alluxio-start.sh master
2 bin/alluxio table attachdb hive thrift://localhost:9083 test

七、重配 Presto 使用 Alluxio SDS

修改 catalog 配置

  • etc/catalog/hive.properties

    1 # connector 還是 hive-hadoop2 是因為 presto 的hive-hadoop2 外掛已經支援了訪問 Alluxio 的功能 2 connector.name=hive-hadoop2 3 hive.metastore=alluxio 4 hive.metastore.alluxio.master.address=localhost:19998

重啟 Presto Server

1 bin/launcher stop
2 bin/launcher start

執行 presto cli

1 ./presto-cli-0.252-executable.jar --catalog hive --schema test
2 show schemas from hive;
3 show tables from hive.test;
4 select * from hive.test.person;
5 select count(*) from person;

觀察執行完 sql,對應的person.csv檔案已經完全被載入到 Alluxio 中了。

八、可選項

搭建 hdfs(如果需要,可以搭建hdfs)

如果希望資料放到 hdfs,則可以搭建 hdfs

1 create schema test_hdfs;
2 create external table test_hdfs.person(name string, age int, id int) row format delimited fields terminated by ' ' location 'hdfs://localhost:9000/root/testdb/person'; 
3 ./presto-cli-0.252-executable.jar --catalog hive --schema test_hdfs
4 show schemas from hive;
5 select * from hive.test_hdfs.person;

九、總 結

利用 Alluxio SDS,底層的 HMS 中的分割槽表的 location 無需修改,也就是 HMS 沒有任何改變,其它計算引擎完全沒有變化。而 Presto 通過 Alluxio SDS 提供的元資料服務,可以進行一些定製化的改造,比如某些分割槽或表不經Alluxio訪問,可以返回 原始的 location 資訊。

十、展 望

Alluxio SDS 在 Presto 和 HMS 之間,搭建了一個 Catalog 代理服務,基於此,Alluxio 理解了資料的格式,因此可以做一些資料格式轉換,比如 csv 轉 parquet,小檔案合併。如果還有其它的需求和好想法,也可以進行改造和開發。此外,可以根據本文,實現一個 All-in-one 的 docker image,讓更多的公司可以體驗到 Alluxio SDS 功能,將會有更多的開發者一起共建這個意義重大的特性。

十一、參 考

想要獲取更多有趣有料的【活動資訊】【技術文章】【大咖觀點】,請關注[Alluxio智庫]