简体   繁体   English

如何使用 Google Cloud SQL 配置 sailsjs 数据库连接

[英]How to configure sailsjs DB connection with Google Cloud SQL

I'm running a Sails.js application that uses a Google Cloud Postgresql instance on Google App Engine.我正在运行一个使用 Google App Engine 上的 Google Cloud Postgresql 实例的 Sails.js 应用程序。 I'm getting a connection refused error when I deploy the application.部署应用程序时出现连接被拒绝错误。 This is my sailsjs connection config:这是我的 sailsjs 连接配置:

postgresGoogle: {
      adapter: 'sails-postgresql',
      socketPath: '/cloudsql/' + process.env.INSTANCE_CONNECTION_NAME,
      user: 'xxxxx',
      password: 'xxxxx',
      database: 'postgres'
     }

If I add the host, it throws a timeout error.如果我添加主机,它会抛出超时错误。 Does anyone know the proper way to configure a sailsjs connection with GCP postresql?有谁知道用 GCP postresql 配置 sailsjs 连接的正确方法?

Where exactly is your Sails.js application?您的 Sails.js 应用程序到底在哪里? Is it on App Engine Flex?是否在 App Engine Flex 上? I would recommend deploying to App Engine Flex, as described here and then connect to the PostgreSQL from the Flex environment.我建议按照此处所述部署到 App Engine Flex,然后从 Flex 环境连接到 PostgreSQL。 Otherwise, are you using any of the option steps described in this link for connection?否则,您是否使用此链接中描述的任何选项步骤进行连接?

Solved解决了

As of 16 December 2022...截至 2022 年 12 月 16 日...

I finally got Sails.js to work today with GCP SQL.我今天终于让 Sails.js 与 GCP SQL 一起工作。 If you follow the tutorials from Google you have either Unix Sockets or TCP options to try -- and sadly neither work with out of the box sails-postgres.如果您按照 Google 的教程进行操作,您可以尝试 Unix 套接字或 TCP 选项——遗憾的是,这两种方法都无法使用开箱即用的 sails-postgres。

My workaround was to connect via a VPC connector with a dedicated IP address.我的解决方法是通过具有专用 IP 地址的 VPC 连接器进行连接。 This way I can connect to Cloud SQL using a regular Postgres connection string, directly to the DB.这样我就可以使用常规的 Postgres 连接字符串连接到 Cloud SQL,直接连接到数据库。

https://cloud.google.com/appengine/docs/legacy/standard/python/outbound-ip-addresses https://cloud.google.com/appengine/docs/legacy/standard/python/outbound-ip-addresses

Then I whitelisted the new dedicated IP in Cloud SQL security settings, and forced SSL to require valid SSL certificates.然后我在 Cloud SQL 安全设置中将新的专用 IP 列入白名单,并强制 SSL 需要有效的 SSL 证书。

It may not be best practice for now per Google's docs, but it works.根据 Google 的文档,目前这可能不是最佳实践,但它确实有效。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何增加 Google Cloud SQL Postgres 数据库的连接限制? - How to increase the connection limit for the Google Cloud SQL Postgres database? 云 sql 连接中的 Google 身份验证错误 - Error from Google Authentication in cloud sql connection 谷歌云 SQL 第二代 -> “连接中断” - Google Cloud SQL Second generation -> "Aborted connection" GAE - 如何在 quarkus java11 应用程序中配置从 Google App Engine 访问 Cloud SQL? - GAE - How to configure access to Cloud SQL from Google App Engine in quarkus java11 app? terraform 谷歌云运行添加云 sql 连接 - terraform google cloud run add cloud sql connection 在 DataPrep 中,如何在没有公共 ip 的情况下在谷歌云平台上创建与 sql 实例的连接? - In DataPrep, How to create connection with instance of sql without public ip on google cloud platform? 使用CloudRun和Google SQL,cloud run会自动使用连接池吗? - Using CloudRun and Google SQL, will cloud run automatically use connection pooling? 谷歌云 SQL + Go Gin 连接超时 200 并发 - Google Cloud SQL + Go Gin connection timeout with 200 concurrent 如何在不重启数据库实例的情况下截断 Google Cloud SQL 中的 MySQL performance_schema? - How to truncate the MySQL performance_schema in Google Cloud SQL without restarting DB instance? 如何为 AWS 负载均衡器配置 Google Cloud DNS - How to configure Google Cloud DNS for an AWS Load balancer
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM