如何在Amazon EMR上为presto添加连接器

4

我已经建立了一个安装有Hive/Presto的小型EMR集群,我想查询S3上的文件,并将它们导入到RDS上的Postgres。

为了在S3上运行查询并将结果保存到Postgres表中,我已经完成了以下步骤:

  1. Started a 3 node EMR cluster from the AWS console.
  2. Manually SSH into the Master node to create an EXTERNAL table in hive, looking at an S3 bucket.
  3. Manually SSH into each of the 3 nodes and add a new catalog file:

    /etc/presto/conf.dist/catalog/postgres.properties 
    

    with the following contents

    connector.name=postgresql
    connection-url=jdbc:postgresql://ip-to-postgres:5432/database
    connection-user=<user>
    connection-password=<pass>
    

    and edited this file

    /etc/presto/conf.dist/config.properties
    

    adding

    datasources=postgresql,hive
    
  4. Restart presto by running the following manually on all 3 nodes

    sudo restart presto-server
    

这种设定似乎很有效。

在我的应用中,会动态创建多个数据库。看来需要为每个数据库进行配置/目录更改,并重新启动服务器才能看到新的配置更改。

是否有一种适当的方式(使用boto或其他方法)让我的应用程序更新配置,包括:

  1. 在所有节点的/etc/presto/conf.dist/catalog/中为每个新数据库添加一个新的目录文件
  2. 在所有节点的/etc/presto/conf.dist/config.properties中添加一个新条目
  3. 在整个集群中优雅地重启presto(最好在其变为空闲时进行,但这不是主要关注点)

如果我的答案对您有帮助,请将其标记为“正确答案”i.stack.imgur.com/QpogP.png。 - mostafazh
3个回答

2

我相信您可以运行一个简单的bash脚本来实现您想要的功能。除了使用--configurations参数创建一个新的集群并提供所需的配置之外,没有其他方法。您可以从主节点运行下面的脚本。

#!/bin/sh

# "cluster_nodes.txt" with private IP address of each node.
aws emr list-instances --cluster-id <cluster-id> --instance-states RUNNING | grep PrivateIpAddress | sed 's/"PrivateIpAddress"://' | sed 's/\"//g' | awk '{gsub(/^[ \t]+|[ \t]+$/,""); print;}' > cluster_nodes.txt

# For each IP connect with ssh and configure.
while IFS='' read -r line || [[ -n "$line" ]]; do
    echo "Connecting $line"
    scp -i <PEM file> postgres.properties hadoop@$line:/tmp;
    ssh -i <PEM file> hadoop@$line "sudo mv /tmp/postgres.properties /etc/presto/conf/catalog;sudo chown presto:presto /etc/presto/conf/catalog/postgres.properties;sudo chmod 644 /etc/presto/conf/catalog/postgres.properties; sudo restart presto-server";
done < cluster_nodes.txt

谢谢您的回答!这个东西竟然没有被记录在任何地方,太疯狂了。 - Joe Harris

0
您可以通过管理控制台提供以下配置:

Create Cluster EMR Console

或者您可以使用 awscli 将这些配置传递如下:

#!/bin/bash

JSON=`cat <<JSON
[
  { "Classification": "presto-connector-postgresql",
    "Properties": {
      "connection-url": "jdbc:postgresql://ip-to-postgres:5432/database",
      "connection-user": "<user>",
      "connection-password": "<password>"
    },
    "Configurations": []
  }
]
JSON`

aws emr create-cluster --configurations "$JSON" # ... reset of params

0

在集群提供期间: 您可以在提供期间提供配置详细信息。

请参阅Presto Connector Configuration,了解如何在提供集群期间自动添加此配置。


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接