系統環境:hadoop + hive已經配置完成
1、下載presto:https://repo1.maven.org/maven2/com/facebook/presto/presto-server/0.167/presto-server-0.167.tar.gz
2、解壓安裝
# tar -zxvf presto-server-0.167.tar.gz -C /usr/local/
/usr/local/presto-server-0.167則為安裝目錄,另外Presto還需要數據目錄,數據目錄最好不要在安裝目錄里面,方便后面Presto的版本升級。
3、配置presto
在安裝目錄里創建etc目錄。這目錄會有以下配置(自己創建):
結點屬性(Node Properties):每個結點的環境配置
JVM配置(JVM Config):Java虛擬機的命令行選項
配置屬性(Config Properties):Persto server的配置
Catelog屬性(Catalog Properties):配置Connector(數據源)
(1)結點屬性(Node Properties)
結點屬性文件etc/node.properties,包含每個結點的配置。一個結點是一個Presto實例。這文件一般是在Presto第一次安裝時創建的。以下是最小配置:
node.environment=production
node.id=ffffffff-ffff-ffff-ffff-ffffffffffff
node.data-dir=/var/presto/data
解釋:
node.environment: 環境名字,Presto集群中的結點的環境名字都必須是一樣的。
node.id: 唯一標識,每個結點的標識都必須是為一的。就算重啟或升級Presto都必須還保持原來的標識。
node.data-dir: 數據目錄,Presto用它來保存log和其他數據
eg:
node.environment=production
node.id=master-presto-coordinator
node.data-dir=/usr/local/presto-server-0.167/data #data需要自己手動創建
(2)JVM配置(JVM Config)
JVM配置文件etc/jvm.config,包含啟動Java虛擬機時的命令行選項。格式是每一行是一個命令行選項。此文件數據是由shell解析,所以選項中包含空格或特殊字符會被忽略。
以下是參考配置:
-server
-Xmx16G
-XX:+UseG1GC
-XX:G1HeapRegionSize=32M
-XX:+UseGCOverheadLimit
-XX:+ExplicitGCInvokesConcurrent
-XX:+HeapDumpOnOutOfMemoryError
-XX:+ExitOnOutOfMemoryError
備注:以上參數都是官網參數,實際環境需要調整
(3)配置屬性(Config Properties)
配置屬性文件etc/config.properties,包含Presto server的配置。Presto server可以同時為coordinator和worker,但一個大集群里最好就是只指定一台機器為coordinator。
以下是coordinator的最小配置:
coordinator=true
node-scheduler.include-coordinator=false
http-server.http.port=8080
query.max-memory=50GB
query.max-memory-per-node=1GB
discovery-server.enabled=true
discovery.uri=http://example.net:8080
以下是worker的最小配置:
coordinator=false
http-server.http.port=8080
query.max-memory=50GB
query.max-memory-per-node=1GB
discovery.uri=http://example.net:8080
如果適用於測試目的,需要將一台機器同時配置為coordinator和worker,則使用以下配置:
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://example.net:8080
解釋:
coordinator: 是否運行該實例為coordinator(接受client的查詢和管理查詢執行)。
node-scheduler.include-coordinator:coordinator是否也作為work。對於大型集群來說,在coordinator里做worker的工作會影響查詢性能。
http-server.http.port:指定HTTP端口。Presto使用HTTP來與外部和內部進行交流。
query.max-memory: 查詢能用到的最大總內存
query.max-memory-per-node: 查詢能用到的最大單結點內存
discovery-server.enabled: Presto使用Discovery服務去找到集群中的所有結點。每個Presto實例在啟動時都會在Discovery服務里注冊。這樣可以簡化部署,不需要額外的服務,Presto的coordinator內置一個Discovery服務。也是使用HTTP端口。
discovery.uri: Discovery服務的URI。將example.net:8080替換為coordinator的host和端口。這個URI不能以斜杠結尾,這個錯誤需特別注意,不然會報404錯誤。
另外還有以下屬性:
jmx.rmiregistry.port: 指定JMX RMI的注冊。JMX client可以連接此端口
jmx.rmiserver.port: 指定JXM RMI的服務器。可通過JMX監聽。
eg:server配置
coordinator=true
node-scheduler.include-coordinator=false
datasources=jmx,hive
http-server.http.port=8880
query.max-memory=1GB
query.max-memory-per-node=512MB
discovery-server.enabled=true
discovery.uri=http://172.20.1.1:8880
client配置
coordinator=false
http-server.http.port=8880
query.max-memory=1GB
query.max-memory-per-node=512MB
discovery-server.enabled = true
discovery.uri=http://172.20.1.1:8880
(4)日志級別
創建文件log.properties
填入內容:
com.facebook.presto=INFO
備注:日志級別有四種,DEBUG, INFO, WARN and ERROR
(5)連接設置
這里只說一下hive的,其實官網寫的很清楚,如果有用到其他的,可以點一下官網連接:https://prestodb.io/docs/current/connector.html
hive connector配置如下:
a、創建存放鏈接配置文件的文件夾,在之前etc目錄下創建catalog
b、放入一個jmx的配置文件,jmx.properties,配置內容:connector.name=jmx (通過jmx管理connector)
c、配置一個hive connector的配制文件,hive.properties,內容如下:
在etc目錄下創建catalog目錄
# mkdir catalog
# cd catalog
# touch hive.properties
connector.name=hive-hadoop2 #取個連接名
hive.metastore.uri=thrift://172.20.1.1:9083 #配置metastore連接
hive.config.resources=/usr/local/hadoop-2.9.1/conf/core-site.xml,/usr/local/hadoop-2.9.1/conf/hdfs-site.xml #指明hadoop的配置文件,主要是設計hdfs
hive.allow-drop-table=true #給刪表權限
其他配置如下可參考官網:https://prestodb.io/docs/current/connector/hive.html https://prestodb.io/docs/current/connector/hive-security.html
eg:
(6)
這些都配置好后,就要啟動presto,步驟如下:
a、在bin目錄下啟動服務:bin/launcher start bin/launcher start
b、命令行啟動:下載啟動jar包:presto-cli-0.191-executable.jar,下載鏈接為: https://repo1.maven.org/maven2/com/facebook/presto/presto-cli/0.191/presto-cli-0.191-executable.jar
c、下載下來后改個名字為presto,放在bin目錄下,然后給個執行權限:chmod +x presto ,
d、連接hive,並啟動:./presto --server localhost:8080 --catalog hive --schema default
e、如果要關閉presto服務,執行:bin/launcher stop
借鑒:https://blog.csdn.net/u012551524/article/details/79013194