【问题标题】:Cannot connect to Cloud SQL with Java SocketFactory Library无法使用 Java SocketFactory 库连接到 Cloud SQL
【发布时间】:2019-04-17 19:08:39
【问题描述】:

这是我在 Cloud SQL 谷歌小组讨论论坛上提出的重复问题:https://groups.google.com/forum/#!topic/google-cloud-sql-discuss/qYmjvfH0MdI

我正在使用 Cloud Dataflow 在我的个人帐户中使用 Cloud SQL 作为接收器来运行一些管道。管道执行后,我想连接到 Cloud SQL 以运行删除语句。我无法使用 JdbcIO 运行删除(仅选择和插入)。即使我可以使用 JdbcIO 连接到 Cloud SQL,我也无法使用普通 Jdbc 连接到它。

下面是我用来连接我的实例的代码

static void cleanUpPipeline() {
    String jdbcUrl = String.format(
            "jdbc:postgresql://google/%s?cloudSqlInstance=%s"
                + "&socketFactory=com.google.cloud.sql.postgres.SocketFactory",
            "xxxxxx",
            "xxxxxx");

    try {
        Class.forName("org.postgresql.Driver");
        Connection connection = DriverManager.getConnection(jdbcUrl, "xxxxxx", "xxxxxx");
    } catch (SQLException | ClassNotFoundException e) {
        e.printStackTrace();
    }
}

我的 pom.xml 有以下依赖:

<dependency>
    <groupId>com.google.cloud.sql</groupId>
    <artifactId>postgres-socket-factory</artifactId>
    <version>1.0.11</version>
</dependency>

<dependency>
    <groupId>org.postgresql</groupId>
    <artifactId>postgresql</artifactId>
    <version>42.2.5</version>
</dependency>

我收到的错误是:

INFO:通过 ssl 套接字连接到 Cloud SQL 实例 [xxxxxxxxx]。十一月 2018 年 2 月 13 日下午 2:53:49 com.google.cloud.sql.core.SslSocketFactory 获取实例

INFO:第一个 Cloud SQL 连接,生成 RSA 密钥对。 11 月 13 日, 2018 下午 2:53:51 com.google.cloud.sql.core.SslSocketFactory 获取InstanceSslInfo

INFO:正在获取 Cloud SQL 实例 [xxxxxx] 的临时证书。 2018 年 11 月 13 日下午 2:53:54 com.google.cloud.sql.core.SslSocketFactory createAndConfigureSocket

INFO:在 IP [xxxxxxx] 上连接到 Cloud SQL 实例 [xxxxxxxx] org.postgresql.util.PSQLException:连接到 google:5432 被拒绝。 检查主机名和端口是否正确以及 postmaster 正在接受 TCP/IP 连接。

我相信我正在这里做所有事情。谁能帮我?

【问题讨论】:

    标签: google-cloud-platform google-cloud-sql


    【解决方案1】:

    最后,这是一个防火墙问题。我无法从防火墙内部访问端口 3307,这是 Cloud SQL 代理使用的端口。我相信 Java SocketFactory 库也需要使用该端口。

    【讨论】:

      猜你喜欢
      • 2017-04-11
      • 2018-08-04
      • 2019-05-10
      • 2020-01-27
      • 2014-01-28
      • 2022-01-24
      • 2013-11-14
      • 2019-11-10
      相关资源
      最近更新 更多