作者:范斌;Alluxio开创成员、开源社区副总裁
To 初学者:
本教程将领导初学者在本地服务器上通过搭建Presto和Hive Metastore来查问S3上的数据。
Presto是用于打算和执行查问的SQL引擎,S3为表分区文件提供存储服务,而Hive Metastore是为Presto拜访表模式和地位信息提供catalog服务。
本教程将展现如何一步一步装置并配置Presto和Hive MetaStore,从而查问存储在私有S3 bucket中的数据。
第一步:下载和启动Hive MetaStore
本教程中咱们下载并应用 [apache-hive-2.3.7-bin.tar.gz],点击下载并解压Hive的二进制压缩包。
$ cd /path/to/tutorial/root$ wget https://downloads.apache.org/hive/hive-2.3.7/apache-hive-2.3.7-bin.tar.gz$ tar -zxf apache-hive-2.3.7-bin.tar.gz$ cd apache-hive-2.3.7-bin
咱们只须要启动Hive Metastore来为Presto提供诸如表模式和分区地位等的catalog信息。
如果你是第一次启动Hive Metastore,请筹备好相应的配置文件和环境,同时初始化(initialize)一个新的Metastore。
$ export HIVE_HOME=`pwd`$ cp conf/hive-default.xml.template conf/hive-site.xml$ mkdir -p hcatalog/var/log/$ bin/schematool -dbType derby -initSchema
须要配置Hive来拜访S3,能够在conf/hive-env.sh中增加以下几行。同时,Hive须要相应的jar包来拜访带有“s3a://”地址的文件,还须要AWS凭证来拜访S3 bucket(包含私有S3 bucket)。
export HIVE_AUX_JARS_PATH=${HADOOP_HOME}/share/hadoop/tools/lib/aws-java-sdk-core-1.10.6.jar:${HADOOP_HOME}/share/hadoop/tools/lib/aws-java-sdk-s3-1.10.6.jar:${HADOOP_HOME}/share/hadoop/tools/lib/hadoop-aws-2.8.4.jarexport AWS_ACCESS_KEY_ID=<Your AWS Access Key>export AWS_SECRET_ACCESS_KEY=<Your AWS Secret Key>
如果你的Hadoop安装包中没有上述jar包,你也能够从maven central下载:
<aws-java-sdk-core-1.10.6.jar>、<aws-java-sdk-s3-1.10.6.jar>、<hadoop-aws-2.8.4.jar>
启动Hive Metastore,它将在后盾运行并监听端口9083(默认端口)。
$ hcatalog/sbin/hcat_server.sh startStarted metastore server init, testing if initialized correctly...Metastore initialized successfully on port[9083].
为了验证MetaStore是否在运行,请在 hcatalog/var/log/门路下查看Hive Metastore日志。
第二步:下载并启动Presto服务器
在本教程中咱们以[0.237.1版本]服务器为例,点击链接,关上Presto服务器装置页面,下载并解压通过预编译的(pre-build),服务器压缩包。
$ cd /path/to/tutorial/root$ wget https://repo1.maven.org/maven2/com/facebook/presto/presto-server/0.237.1/presto-server-0.237.1.tar.gz$ tar -zxf presto-server-0.237.1.tar.gz$ cd presto-server-0.237.1
创立一个蕴含根本Presto配置的配置文件: etc/config.properties。
coordinator=truenode-scheduler.include-coordinator=truehttp-server.http.port=8080discovery-server.enabled=truediscovery.uri=http://localhost:8080
创立 etc/jvm.config来实现以下JVM配置。
-server-Xmx16G-XX:+UseG1GC-XX:G1HeapRegionSize=32M-XX:+UseGCOverheadLimit-XX:+ExplicitGCInvokesConcurrent-XX:+HeapDumpOnOutOfMemoryError-XX:+ExitOnOutOfMemoryError
创立 etc/node.properties,应蕴含上面几行内容:
node.environment=productionnode.id=ffffffff-ffff-ffff-ffff-ffffffffffffnode.data-dir=/tmp/presto/data
最初,在etc/catalog/hive.properties中配置Presto Hive连接器,指向刚刚启动的Hive Metastore服务。此外,这里还须要再次输出AWS凭证,实现后,Presto即可从S3读取输出文件。
connector.name=hive-hadoop2hive.metastore.uri=thrift://localhost:9083hive.s3.aws-access-key=<Your AWS Access Key>hive.s3.aws-secret-key=<Your AWS Secret Key>
在后盾启动Presto服务器:
$ ./bin/launcher start
为了验证Presto服务器是否在运行,从浏览器中拜访链接http://localhost:8080 ,并在网页用户界面(UI)上查看服务器状态。
第三步:启动Presto CLI(Presto 命令行工具)
并运行查问命令,从服务器上下载Presto命令行工具,它是一个独自的二进制文件Presto CLI
$ cd /path/to/tutorial/root$ wget https://repo1.maven.org/maven2/com/facebook/presto/presto-cli/0.237.1/presto-cli-0.237.1-executable.jar$ mv presto-cli-0.237.1-executable.jar presto$ chmod +x presto
连贯到上一步中曾经启动的Presto服务器。
$ ./presto --server localhost:8080 --catalog hive --debug
应用默认模式
`presto> use default;USE`
基于S3中的文件在默认模式下创立一个新表,这些信息将被发送到Hive MetaStore。
presto:default> CREATE TABLE reason ( r_reason_sk integer, r_reason_id varchar, r_reason_desc varchar) WITH ( external_location = 's3a://apc999/presto-tutorial/example-reason', format = 'PARQUET');CREATE TABLE
扫描创立的新表:
presto:default> SELECT * FROM reason limit 3; r_reason_sk | r_reason_id | r_reason_desc -------------+------------------+------------------------ 1 | AAAAAAAABAAAAAAA | Package was damaged 2 | AAAAAAAACAAAAAAA | Stopped working 3 | AAAAAAAADAAAAAAA | Did not get it on time (3 rows)Query 20200703_074406_00011_8vq8w, FINISHED, 1 nodehttp://localhost:8080/ui/query.html?20200703_074406_00011_8vq8wSplits: 18 total, 18 done (100.00%)CPU Time: 0.5s total, 6 rows/s, 2.06KB/s, 27% activePer Node: 0.1 parallelism, 0 rows/s, 279B/sParallelism: 0.1Peak User Memory: 0BPeak Total Memory: 219BPeak Task Total Memory: 219B0:04 [3 rows, 1002B] [0 rows/s, 279B/s]
第四步:进行服务器
$ cd /path/to/tutorial/root$ presto-server-0.237.1/bin/launcher stop$ apache-hive-2.3.7-bin/hcatalog/sbin/hcat_server.sh stop
总结:
在本教程中,咱们演示了如何通过搭建Presto和Hive Metastore来对存储在私有S3 bucket中的数据进行SQL查问,心愿对你有所帮忙。