【问题标题】:How to add connectors to presto on Amazon EMR如何在 Amazon EMR 上将连接器添加到 presto
【发布时间】:2016-03-17 18:33:30
【问题描述】:

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

要在 S3 上运行查询并将结果保存在 postgres 的表中,我做了以下操作:

  1. 从 AWS 控制台启动了一个 3 节点 EMR 集群。
  2. 手动 SSH 到主节点以在 hive 中创建一个 EXTERNAL 表,查看 S3 存储桶。
  3. 手动 SSH 到 3 个节点中的每一个并添加一个新的目录文件:

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

    以下内容

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

    并编辑了这个文件

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

    添加

    datasources=postgresql,hive
    
  4. 通过在所有 3 个节点上手动运行以下命令来重新启动 presto

    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

标签: amazon-web-services hive emr presto


【解决方案1】:

我相信你可以运行一个简单的 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

【讨论】:

    【解决方案2】:

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

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

    【讨论】:

      【解决方案3】:

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

      或者您可以使用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
      

      【讨论】:

        猜你喜欢
        • 2016-09-11
        • 2018-02-08
        • 2017-06-15
        • 2020-05-10
        • 2019-04-16
        • 1970-01-01
        • 1970-01-01
        • 2019-02-16
        • 1970-01-01
        相关资源
        最近更新 更多