【问题标题】:connect to Redshift via an intermediate server通过中间服务器连接到 Redshift
【发布时间】:2016-09-16 20:34:57
【问题描述】:

我正在开发一个连接到 Redshift 数据库的 Java 应用程序,以运行无法在我们的硬件上运行的大量查询。该应用程序还消耗我们数据中心中的各种内部非 AWS 资源(例如,我们的 NAS、Oracle、MySQL 等上的文件......)。

很遗憾,由于某些网络路由限制,应用程序无法直接连接到 Redshift。我可以通过 SSH 手动将我们的生产 Redshift 集群连接到属于我们 VPC 的中间 EC2 实例 - 我希望以编程方式执行此操作。

在我的测试环境中,没有相同的路由限制,我可以使用这样的数据源进行连接:

@Bean(name="dataSourceRedshift")
public DataSource dataSourceRedshift() throws SQLException {
    SimpleDriverDataSource dataSource = new SimpleDriverDataSource();
    dataSource.setDriver(new com.amazon.redshift.jdbc41.Driver());
    dataSource.setUrl("jdbc:postgresql://" + redshiftHost + ":" + redshiftPort + "/" + redshiftDatabase);
    dataSource.setUsername(redshiftUser);
    dataSource.setPassword(redshiftPass);
    return dataSource;
}

在我们无法直接连接到 Redshift 的生产环境中,有没有办法调整数据源 bean(上图)以通过 EC2 实例设置 SSH 隧道?如果没有,“跳跃”的最佳方式是什么?

【问题讨论】:

    标签: java amazon-web-services ssh amazon-ec2 amazon-redshift


    【解决方案1】:

    我偶然发现了一种非常简单的方法来创建通过 SSH 进行隧道传输的数据源(由 Lucas Theisen 提供:https://github.com/lucastheisen/jsch-extension):

    @Bean(name="dataSourceRedshift")
    public DataSource dataSourceRedshift() throws SQLException, JSchException {
        SimpleDriverDataSource dataSource = new SimpleDriverDataSource();
        dataSource.setDriver(new com.amazon.redshift.jdbc41.Driver());
        dataSource.setUrl("jdbc:postgresql://" + redshiftHost + ":" + redshiftPort + "/" + redshiftDatabase);
        dataSource.setUsername(redshiftUser);
        dataSource.setPassword(redshiftPass);
    
        DefaultSessionFactory defaultSessionFactory = new DefaultSessionFactory();
    
        TunneledDataSourceWrapper tunneledDataSource = new TunneledDataSourceWrapper(
                new TunnelConnectionManager(
                        defaultSessionFactory,
                        redshiftTunnel ),
                dataSource );
    
        return tunneledDataSource;
    }
    

    redshiftTunnel 字符串在哪里:

    awoolford@localhost->awoolford@{{ ec2 instance in our VPC }}|127.0.0.1:5439:{{ redshift endpoint }}:5439
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-05-09
      • 1970-01-01
      • 1970-01-01
      • 2020-10-22
      • 2011-05-21
      • 2014-04-05
      相关资源
      最近更新 更多