安装Presto
①
下载软件
wget https://repo1.maven.org/maven2/com/facebook/presto/presto-server/0.192/presto-server-0.192.tar.gz
root@bigdata-148024:~# for a in {24,25,26,27,28}; do ssh 10.1.8.$a mkdir -p /data1/presto/data;done
"
for a in {24,25,26,27,28};do ssh 10.1.8.$a "chown presto.presto /data1/presto/" ;done
②
解压及配置
root@bigdata-148024:/opt# tar -xf presto-server-0.192.tar.gz
添加用户adduser presto
root@bigdata-148024:~# for a in {24,25,26,27,28};do ssh 10.1.8.$a " useradd presto" ;done
root@bigdata-148024:/opt# chown presto.presto -R presto-server-0.192
root@bigdata-148024:/opt# su - presto
presto@bigdata-148024:/opt/presto-server-0.192$ mkdir etc
root@bigdata-148024:/opt/presto-server-0.192/etc# cat node.properties
node.environment=presto_cluster
node.id=fa266a13-926d-46cd-b0ed-2ee0f38d5817
node.data-dir=/data1/presto/data
root@bigdata-148024:/opt/presto-server-0.192/etc# cat config.properties
coordinator=true
datasources=jmx,hive
node-scheduler.include-coordinator=true
http-server.http.port=9001
query.max-memory=16GB
query.max-memory-per-node=1GB
discovery-server.enabled=true
discovery.uri=http://10.1.8.24:9001
root@bigdata-148024:/opt/presto-server-0.192/etc# cat jvm.config
-server
-Xmx18G
-XX:+UseConcMarkSweepGC
-XX:+ExplicitGCInvokesConcurrent
-XX:+CMSClassUnloadingEnabled
-XX:+AggressiveOpts
-XX:+HeapDumpOnOutOfMemoryError
-XX:OnOutOfMemoryError=kill -9 %p
-XX:ReservedCodeCacheSize=150M
root@bigdata-148024:/opt/presto-server-0.192/etc# cat log.properties
com.facebook.presto=DEBUG
presto@bigdata-148024:/opt/presto-server-0.192/etc$ mkdir catalog
presto@bigdata-148024:/opt/presto-server-0.192/etc/catalog$ cat jmx.properties
connector.name=jmx
root@bigdata-148024:/opt/presto-server-0.192/etc# cat catalog/hive.properties
connector.name=hive-hadoop2
hive.metastore.uri=thrift://10.1.8.24:9083,thrift://10.1.8.25:9083
hive.config.resources=/etc/hadoop/conf/core-site.xml,/etc/hadoop/conf/hdfs-site.xml
#-DHADOOP_USER_NAME=hdfs
hive.metastore-cache-ttl=0s
hive.metastore-refresh-interval=1s
hive.recursive-directories=true
hive.security=sql-standard
数据目录赋权
for a in {24,25,26,27,28};do ssh 10.1.8.$a "chown presto.presto /data1/presto/data" ;done
③
拷贝到其他机器上
for a in {25,26,27,28}; do scp -r /opt/presto-server-0.192/ 10.1.8.$a:/opt;done
④
worker节点配置黄色的是需要更改的
root@bigdata-148025:/etc/hadoop/conf# cat /opt/presto-server-0.192/etc/config.properties
coordinator=false
datasources=jmx,hive
http-server.http.port=9001
query.max-memory=16GB
query.max-memory-per-node=1GB
discovery-server.enabled=true
discovery.uri=http://10.1.8.24:9001
root@bigdata-148025:/etc/hadoop/conf# cat /opt/presto-server-0.192/etc/node.properties
node.environment=presto_cluster
node.id=fa266a13-926d-46cd-b0ed-2ee0f38d5819
node.data-dir=/data1/presto/data
for a in {25,26,27,28};do ssh 10.1.8.$a "chown presto.presto /opt/presto-server-0.192/" ;done
⑤
启动进程
启动所有机器机器执行
presto@bigdata-148024:/opt/presto-server-0.192/bin$ cd /opt/presto-server-0.192/bin;./launcher start
⑥
查看进程:
ps -aux|grep PrestoServer 或 jps
presto@bigdata-148024:/opt/presto-server-0.192/etc$ ps -aux|grep PrestoServer
presto 49340 3.1 1.7 37957900 1160404 ? Ssl 12:00 4:34 java -cp /opt/presto-server-0.192/lib/* -server -Xmx18G -XX:+UseConcMarkSweepGC -XX:+ExplicitGCInvokesConcurrent -XX:+CMSClassUnloadingEnabled -XX:+AggressiveOpts -XX:+HeapDumpOnOutOfMemoryError -XX:OnOutOfMemoryError=kill -9 %p -XX:ReservedCodeCacheSize=150M -Dlog.output-file=/data1/presto/data/var/log/server.log -Dnode.data-dir=/data1/presto/data -Dnode.id=fa266a13-926d-46cd-b0ed-2ee0f38d5817 -Dnode.environment=presto_cluster -Dlog.enable-console=false -Dlog.levels-file=/opt/presto-server-0.192/etc/log.properties -Dconfig=/opt/presto-server-0.192/etc/config.properties com.facebook.presto.server.PrestoServer
⑦
测试
下载jar包
cd /opt/presto-server-0.192/bin https://repo1.maven.org/maven2/com/facebook/presto/presto-cli/0.192/presto-cli-0.192-executable.jar
拷贝到其他机器上
for i in {24,25,26,27,28} ;do scp -r /opt/presto-server-0.192/bin/presto-cli-0.192-executable.jar
[email protected].$i:/opt/presto-server-0.192/bin/presto ;done
添加权限
for a in {24,25,26,27,28};do ssh 10.1.8.$a "chmod +x /opt/presto-server-0.192/bin/presto" ;done
执行测试
root@bigdata-148024:~# su presto
presto@bigdata-148024:/root$ cd
presto@bigdata-148024:~$ cd /opt/presto-server-0.192/bin/
presto@bigdata-148024:/opt/presto-server-0.192/bin$ ./presto --server 10.1.8.24:9001 --catalog hive --schema default(如果要调度,可加 --debug, 红色标识的项必须与 config.properties 配置文件中的uri 地址一致,配置的IP就用IP,机器名就用机器名)
presto:default> show tables;
Table
-------
(0 rows)
Query 20180702_060459_00002_aky87, FINISHED, 2 nodes
Splits: 18 total, 18 done (100.00%)
0:01 [0 rows, 0B] [0 rows/s, 0B/s]
presto:default>
在 执行 show tables 命令之前,你可以查看 http://10.1.8.24:9001/ 页面:
可以运行 --help 命令查看更多参数,例如你可以在命令行直接运行下面命令:
./presto-cli --server localhost:9001 --catalog hive --schema default --execute "show tables;"
默认情况下,Presto 的查询结果是使用 less 程序分页输出的,你可以通过修改环境变量 PRESTO_PAGER 的值将其改为其他命令,如 more,或者将其置为空以禁止分页输出。
6. 测试 jdbc
使用 jdbc 连接 Presto,需要下载 jdbc 驱动 presto-jdbc-0.192 并将其加到你的应用程序的 classpath 中。
wget https://repo1.maven.org/maven2/com/facebook/presto/presto-jdbc/0.192/presto-jdbc-0.192.jar
支持以下几种 JDBC URL 格式:
jdbc:presto://host:port
jdbc:presto://host:port/catalog
jdbc:presto://host:port/catalog/schema
连接 hive 数据库中 sales 库,示例如下:
jdbc:presto://10.1.8.24:9001/hive/sales