使用cloud sql代理连接到GCP Cloud SQL

问题描述 投票:2回答:1

我跟着这个guide连接到我的GCP Cloud Postgresql - 我只有一个私有IP。我跑的时候

./cloud_sql_proxy -instances=<Instance connection name>=tcp:5432

我得到以下内容(实际引用被<Instance connection name>取代)

2019/04/01 11:46:45 failed to setup file descriptor limits: failed to set rlimit {&{8500 4096}} for max file descriptors: invalid argument
2019/04/01 11:46:45 Listening on 127.0.0.1:5432 for <Instance connection name>
2019/04/01 11:46:45 Ready for new connections
2019/04/01 11:47:28 New connection for <Instance connection name>
2019/04/01 11:49:38 couldn't connect to <Instance connection name>: dial tcp 172.27.160.3:3307: connect: connection timed out

如果我跑

psql "host=127.0.0.1 sslmode=disable dbname=<db> user=<user> password=<password>"

然后我得到以下内容

psql: FATAL:  password authentication failed for user "prodigy"

如果从与我的云SQL相同的网络上的VM实例运行相同的psql命令,那么连接就可以了。

postgresql google-cloud-platform database-connection
1个回答
0
投票

您的Cloud SQL实例需要位于同一客户端的网络中才能使用其专用IP进行连接。

无法通过Google Cloud Platform网络之外的私有IP连接Cloud SQL(按原样)。在这种情况下,您可以尝试使用Cloud Interconnect [2]将您的内部部署网络扩展到Google的网络,以便您可以尝试连接,看看它是否适合您。

另一方面,在使用Cloud SQL Proxy时,您需要声明正在使用私有IP [3]。如果未指定,代理将默认查找公共IP。

让我知道事情的后续。


[1] https://cloud.google.com/sql/docs/mysql/private-ip

[2] https://cloud.google.com/interconnect/docs/

[3] https://cloud.google.com/sql/docs/postgres/sql-proxy#private-ip

© www.soinside.com 2019 - 2024. All rights reserved.