在文件存储HDFS上使用Presto
本文档主要介绍如何在文件存储HDFS上搭建及使用Presto。
背景信息
Presto是一个开源的分布式SQL查询引擎,适用于交互式分析查询,数据量支持GB到PB字节。Presto支持在线数据查询,包括Hive、Cassandra、关系数据库以及专有数据存储。
说明 在本文档中Presto是通过连接Hive的元数据服务来读取文件存储HDFS上的数据,在文件存储HDFS上使用Presto时需要额外配置一些依赖包,详细操作步骤请参见配置Presto。
准备工作
在文件存储HDFS上搭建和使用Presto,需要先完成以下准备工作。
配置Presto
您可以参见以下步骤配置Presto,Presto官方配置文档请参见Deploying Presto。
- 解压Presto压缩包到指定文件夹。
tar -zxvf presto-server-0.227.tar.gz -C /usr/local/
- 在Presto解压目录下创建etc目录。
mkdir /usr/local/presto-server-0.227/etc
- 配置Node Properties。
- 创建etc/node.properties文件。
vim /usr/local/presto-server-0.227/etc/node.properties
- 在etc/node.properties文件中添加如下内容。
node.environment=production node.id=ffffffff-ffff-ffff-ffff-ffffffffffff node.data-dir=/var/presto/data
- 创建etc/node.properties文件。
- 配置JVM Config。
- 创建etc/jvm.config文件。
vim /usr/local/presto-server-0.227/etc/jvm.config
- 在etc/jvm.config文件中添加如下内容。
-server -Xmx8G -XX:+UseG1GC -XX:G1HeapRegionSize=32M -XX:+UseGCOverheadLimit -XX:+ExplicitGCInvokesConcurrent -XX:+HeapDumpOnOutOfMemoryError -XX:+ExitOnOutOfMemoryError
- 创建etc/jvm.config文件。
- 配置Config Properties。
在本文档中将coordinator和worker配置在同一台机器上,您可以参见Presto官方文档将coordinator和worker配置到不同的机器。
- 创建etc/config.properties文件。
vim /usr/local/presto-server-0.227/etc/config.properties
- 在etc/config.properties中添加如下内容。
coordinator=true node-scheduler.include-coordinator=true http-server.http.port=8080 query.max-memory=5GB query.max-memory-per-node=1GB query.max-total-memory-per-node=2GB discovery-server.enabled=true discovery.uri=http://xx.xx.xx.xx:8080 #xx.xx.xx.xx为当前机器的IP地址
- 创建etc/config.properties文件。
- 配置日志级别。
- 创建etc/log.properties文件。
vim /usr/local/presto-server-0.227/etc/log.properties
- 在etc/log.properties文件中添加如下内容。
com.facebook.presto=INFO
- 创建etc/log.properties文件。
- 配置Catalog Properties。
- 创建etc/catalog文件夹。
mkdir /usr/local/presto-server-0.227/etc/catalog
- 创建etc/catalog/hive.properties文件。
vim /usr/local/presto-server-0.227/etc/catalog/hive.properties
- 在etc/catalog/hive.properties文件中添加如下内容。
connector.name=hive-hadoop2 hive.metastore.uri=thrift://xxxx:9083 #xxxx为启动hive元数据服务的IP地址 hive.config.resources=/usr/local/hadoop-2.7.6/etc/hadoop/core-site.xml #配置为您的Hadoop集群中core-site.xml文件的地址
- 创建etc/catalog文件夹。
- 编译并替换jar包。
Presto中以maven-shade-plugin的方式引入了Hadoop,使用relocation的方式对引入的Hadoop jar包地址进行重命名,因为文件存储HDFS的sdk与Hadoop共用了protobuf-xxx.jar包,在Presto通过hive metastore读取文件存储HDFS上的数据时,文件存储HDFS的sdk会获取不到Presto进行重命名地址的protobuf-xxx.jar包。为了避免兼容性问题,文件存储HDFS的sdk需要作为Presto的Hadoop的依赖项,并对Presto中引入的Hadoop的jar包hadoop-apache2-xxx.jar进行重新编译。
- 查看您安装的Presto中的presto-hadoop-apache2版本。
在0.227版本的presto中对应的presto-hadoop-apache2版本为hadoop-apache2-2.7.4-5。
find /usr/local/presto-server-0.227/ -name hadoop-apache2*
- 下载presto-hadoop-apache2对应版本的源码,下载地址:官方链接。
git clone https://github.com/prestodb/presto-hadoop-apache2.git
- 打开源码中的/root/presto-hadoop-apache2-2.7.4-5/pom.xml文件。
vim /root/presto-hadoop-apache2-2.7.4-5/pom.xml
- 在/root/presto-hadoop-apache2-2.7.4-5/pom.xml文件中添加文件存储HDFS sdk的依赖项。本文档中使用的sdk的版本为 1.0.3。
<dependency> <groupId>com.aliyun.dfs</groupId> <artifactId>aliyun-sdk-dfs</artifactId> <version>1.0.3</version> </dependency>
- 编译presto-hadoop-apache2。
cd /root/presto-hadoop-apache2-2.7.4-5
mvn clean package -DskipTests
- 查看生成的hadoop-apache2-2.7.4-5.jar。
cd ~/presto-hadoop-apache2-2.7.4-5/target
ll -h
- 删除旧的hadoop-apache2-2.7.4-5.jar依赖包。
rm -f /usr/local/presto-server-0.227/plugin/raptor/hadoop-apache2-2.7.4-5.jar /usr/local/presto-server-0.227/plugin/accumulo/hadoop-apache2-2.7.4-5.jar /usr/local/presto-server-0.227/plugin/hive-hadoop2/hadoop-apache2-2.7.4-5.jar
- 将新的hadoop-apache2-2.7.4-5.jar依赖包拷贝到对应的目录下。
cp ~/presto-hadoop-apache2-2.7.4-5/target/hadoop-apache2-2.7.4-5.jar /usr/local/presto-server-0.227/plugin/raptor/
cp ~/presto-hadoop-apache2-2.7.4-5/target/hadoop-apache2-2.7.4-5.jar /usr/local/presto-server-0.227/plugin/accumulo/
cp ~/presto-hadoop-apache2-2.7.4-5/target/hadoop-apache2-2.7.4-5.jar /usr/local/presto-server-0.227/plugin/hive-hadoop2/
- 查看您安装的Presto中的presto-hadoop-apache2版本。
- 将presto-cli-xxx-executable.jar复制到Presto安装的bin目录下重命名并赋予可执行权限。
cp ~/presto-cli-0.227-executable.jar /usr/local/presto-server-0.227/bin/
mv /usr/local/presto-server-0.227/bin/presto-cli-0.227-executable.jar /usr/local/presto-server-0.227/bin/presto
chmod +x /usr/local/presto-server-0.227/bin/presto
验证Presto
- 启动Hive的元数据服务。
/usr/local/apache-hive-1.2.1-bin/bin/hive --service metastore
- 创建测试数据并加载到Hive中。
- 创建测试数据。
echo -e "test1\ntest2\ntest1\ntest2\ntest3\ntest4\ntest4\ntest5" > ~/test.txt
- 将测试数据上传到文件存储HDFS上。
hadoop fs -put ~/test.txt /presto
- 使用默认的数据创建test_data并加载数据。
hive> create external table test_data(word string) row format delimited fields terminated by '\n' stored as textfile location '/presto';
- 查看数据是否加载成功。
hive> select * from test_data;
如果显示如下类似信息,则表示数据加载成功。
- 创建测试数据。
- 使用Presto通过Hive读取文件存储HDFS上的数据并进行计算。
- 启动presto server。
/usr/local/presto-server-0.227/bin/launcher start
- 使用presto连接Hive。
/usr/local/presto-server-0.227/bin/presto --server localhost:8080 --catalog hive --schema default
- 读取文件存储HDFS上的数据。
presto:default> select * from test_data;
- 进行word count计算。
presto:default> select word, count(*) from test_data group by word;
- 启动presto server。
版权声明
本文仅代表作者观点,不代表本站立场。
本文系作者授权发表,未经许可,不得转载。
评论