[英]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.