本文介绍了带有Cloud SQLError的Google App Enging上的Node.JS:连接ENOENT/cloudsql/的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已成功将我的应用程序部署到Google App Engine.我的数据库已启动并在Cloud SQL上运行.通过在云SQL的授权网络上对开发机的IP进行白化处理,我可以从本地计算机连接到数据库,而不会出现问题.但是,当我部署到生产环境时,会得到:

I've successfully deployed my app to Google App Engine. My database is up and running on Cloud SQL. I'm able to connect to the database no problems from my local machine by whitelisitng my dev machine's IP on the authorised networks in cloud SQL. However when I deploy to Production, I'm getting:

Error: connect ENOENT /cloudsql/<my project id>:asia-south1:<my database instance name>

我的app.yaml文件如下:

My app.yaml file looks like this:

runtime: nodejs
env: flex

manual_scaling:
  instances: 1
resources:
  cpu: 1
  memory_gb: 0.5
  disk_size_gb: 10

env_variables:
  ST_ENV: 'Production' //Used to set the app listening on the below port
  ST_PORT: '8080'
  SQL_USER: '<username>'
  SQL_PASSWORD: '<password>'
  SQL_DATABASE: '<databasename>'
  INSTANCE_CONNECTION_NAME: '/cloudsql/<my project id>:asia-south1:<my database instance name>'

  beta_settings:
  cloud_sql_instances: '<my project id>:asia-south1:<my database instance name>'

我的配置文件如下:

database: {
            connectionLimit: 10,
            // host     : process.env.INSTANCE_CONNECTION_NAME,
            socketPath: process.env.INSTANCE_CONNECTION_NAME,
            user     : process.env.SQL_USER,
            password : process.env.SQL_PASSWORD,
            database : process.env.SQL_DATABASE,
            multipleStatements : true

        }

我正在创建一个连接池(我已经简化了此示例的代码):

And I'm creating a connection pool (I've simplified the code for this example):

var db = config.production.database;
var pool = mysql.createPool(db);

我已经能够通过本地cloud_sql_proxy从本地计算机成功连接.

I've been able to successfully connect from my local machine through the local cloud_sql_proxy.

我尝试使用Cloud SQL实例的IP作为主机,但这给了我以下错误:

I've tried using the IP of the Cloud SQL instance as the host, but that gave me the below error:

Error: connect ECONNREFUSED 127.0.0.1:3306'

我还尝试将主机指定为0.0.0.0和端口3306并得到:

I also tried specifying the host as 0.0.0.0 and port 3306 and got:

Error: connect ECONNREFUSED 0.0.0.0:3306'

同时启用了Cloud SQL和Cloud SQL Admin API:

both the Cloud SQL and the Cloud SQL Admin APIs are enabled:

这就像在推向生产时,应用程序引擎正在尝试使用不存在的代理.有人可以帮忙吗?

It's like when pushing to production the app engine is trying to use a non existent proxy. Can anyone help?

推荐答案

看看从App Engine Flexible上的Node.js运行时进行连接.您可以使用实例连接名称和其他一些环境变量来配置连接.无需提供主机名或在实例上安装SQL代理.尝试连接到Cloud SQL实例的公共IP 无法在App Engine上运行.

Take a look at the specific instructions for connecting from the Node.js runtime on App Engine Flexible. You can configure the connection using the instance connection name and some other environmental variables. It's not necessary to provide a host name or install the SQL proxy on your instance. Attempting to connect to the public IP of the Cloud SQL instance won't work from App Engine.

这篇关于带有Cloud SQLError的Google App Enging上的Node.JS:连接ENOENT/cloudsql/的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-05 16:34