我将从项目 A(自定义 VPC)中的实例与项目 B(默认 VPC)中的 CloudSQL Postgres 连接。文档说我需要对这两个 VPC 建立对等关系。对等状态处于“Active”状态。在项目 A 中,我还有 cloudsql_auth_proxy。一旦我执行cloudsql_auth_proxy,我得到这个:
root@cloudsql-auth-proxy:~# ./cloud_sql_proxy -instances=projectB:us-west1:postgres=tcp:0.0.0.0:5432
2022/12/29 16:46:59 current FDs rlimit set to 1048576, wanted limit is 8500. Nothing to do here.
2022/12/29 16:47:01 Listening on 0.0.0.0:5432 for -instances=projectB:us-west1:postgres=tcp:0.0.0.0:5432
2022/12/29 16:47:01 Ready for new connections
2022/12/29 16:47:01 Generated RSA key in 244.541948ms
当我尝试像这样连接到cloudsql_proxy时 psql -h xxx.xxx.xxx.xxx -p 5432 -U proxyuser -d postgres 它挂起。
cloudsql_auth_proxy 的输出如下所示:
2022/12/29 16:48:00 New connection for "-instances=projectB:us-west1:postgres"
2022/12/29 16:48:00 refreshing ephemeral certificate for instance -instances=projectB:us-west1:postgres
2022/12/29 16:48:00 Scheduling refresh of ephemeral certificate in 55m0s
: dial tcp 10.35.144.3:3307: connect: connection timed out
对此有什么想法吗?
您需要在项目 B VPC 中部署 Socks5 代理,以提供 VPC 之间的网络路径。但丁是一个受欢迎的选择。
一旦您运行了 Socks5 代理,您就可以启动指向它的代理。
请参阅 https://github.com/GoogleCloudPlatform/cloud-sql-proxy#running-behind-a-socks5-proxy。
如果您正在查看 2023 年的跨 VPC CloudSQL 流量,请查看 CoudSQL 的 PSC - 仅适用于 Mysql 和 Postgres
https://cloud.google.com/blog/products/databases/private-service-connect-with-managed-databases
我想您可能也将其发布到了 GCP subreddit 上! :P
用一些图表来扩展 @enocom 的答案。
参考 Dante 配置以从袜子代理中删除身份验证。不要在产品中这样做 - 只是为了简单测试;)
/etc/danted.conf
logoutput: syslog
clientmethod: none
socksmethod: none
# The listening network interface or address.
internal: 0.0.0.0 port=1080
# The proxying network interface or address.
external: ens4
client pass {
from: 0.0.0.0/0 to: 0.0.0.0/0
}
socks pass {
from: 0.0.0.0/0 to: 0.0.0.0/0
}