如何通过Google App Engine Flex将Google Cloud SQL连接到僵尸网络核心应用程序? [英] How to connect Google Cloud SQL via Google App engine Flex to botnet core app?

查看:97
本文介绍了如何通过Google App Engine Flex将Google Cloud SQL连接到僵尸网络核心应用程序?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个使用PostgreSQL DB的.NET Core 2.2应用程序. 现在,我想将其部署在Google Cloud App Engine Flex和Google Cloud SQL PostgreSQL上.

I have a .NET Core 2.2 app using a PostgreSQL DB. Now I want to deploy it on Google Cloud App Engine Flex and Google Cloud SQL PostgreSQL.

我尝试了官方方式找到了,在这里我发现您必须使用$ gcloud beta app deploy而不是$ gcloud app deploy

I tried the official way and found this, where I found that you have to use $ gcloud beta app deploy instead of $ gcloud app deploy

我的app.yaml配置文件:

My app.yaml configuration file:

env: flex
runtime: aspnetcore
beta_settings:
  cloud_sql_instances: "<SQL-NAME>=tcp:<PORT>"

问题是我收到此错误:

尝试连接 主机= 127.0.0.1;端口= XXX;用户名= XXX;密码= XXX;数据库= XXX; 应用程序启动异常:System.Net.Sockets.SocketException (111):连接被拒绝

Trying to connect to Host=127.0.0.1;Port=XXX;Username=XXX;Password=XXX;Database=XXX; Application startup exception: System.Net.Sockets.SocketException (111): Connection refused

我是否必须在.NET Core 2.2中包含特殊的库才能支持Google App Engine?

Do I have to include special libraries into .NET Core 2.2 to support Google App Engine?

推荐答案

您不需要在.NET Core 2.2中包含任何特殊的库,而不必包含

You don't need to include any special libraries in .NET Core 2.2 rather than those that are already included in the Quckstart that you have shared above, unless of course you are using any additional libraries in your code.

我尝试了快速入门,并部署了连接到CloudSQL PostgreSQL数据库的.NET GAE应用.

I have tried the quickstart and deployed my .NET GAE app that connects to CloudSQL PostgreSQL database.

看看您的app.yaml配置文件,我发现它存在问题.同样根据错误消息,我认为您的appsettings.json文件中也存在问题.

Taking a look at your app.yaml configuration file I can see that there is an issue with it. Also based on the error message you are getting I assume that you are having an issue in your appsettings.json file as well.

基于您共享的GitHub的快速入门,部署时的配置应为:

Based on the quickstart of GitHub that you shared, the configuration when deploying should be:

app.yaml

runtime: aspnetcore
env: flex

beta_settings:
    cloud_sql_instances: "[PROJECT_ID]:[INSTANCE_REGION]:[INSTANCE_NAME]=tcp:[TCP_PORT_NUMPER]"

  • PostgreSQL的TCP端口号: 5432
  • MySQL的TCP端口号: 3306
  • 要找到 tcp 之前的实例连接名称,可以转到Cloud Console > SQL > [YOU_INSTANCE_NAME],然后可以在Instance connection name下找到整个字符串
    • TCP Port number for PostgreSQL: 5432
    • TCP Port number for MySQL: 3306
    • To find the Instance connection name which is the part before tcp, you can go to Cloud Console > SQL > [YOU_INSTANCE_NAME] and you can find the entire string under Instance connection name
    • appsettings.json

      {
        "CloudSQL" : {
          "Database" : "PostgreSQL",  // Set to "PostgreSQL" when using a PostgreSQL database.
            // [START gae_flex_mysql_settings]
          "ConnectionString": "Uid=[USER_ID];Pwd=[PASSWORD];Host=cloudsql;Database=[DATABASE_NAME]"
            // [END gae_flex_mysql_settings]
        }
      }
      

      • 数据库应为PostgreSQL,也应由注释指定
      • ConnectionString 应该使用用于设置数据库的自己的数据填充
      • 主机部分在部署时应为cloudsql,在本地运行时应为127.0.0.1.
        • Database should be PostgreSQL as also specified by the comment
        • ConnectionString should be filled with your own data that you used to setup the database
        • The Host part should be cloudsql when you are deploying and 127.0.0.1 when running locally.
        • 127.0.0.1指示数据库正在本地运行,而cloudsql字符串指示数据库应使用连接字符串名称.基于该错误,我假设您使用127.0.0.1在本地进行测试,但是在部署时忘记将其更改回原来的状态.

          127.0.0.1 indicates that the database is running locally and the cloudsql string indicates that it should use the connection string name. Based on the error, I assume that you used the 127.0.0.1 to test locally but then forgot to change it back when you were deploying.

          这篇关于如何通过Google App Engine Flex将Google Cloud SQL连接到僵尸网络核心应用程序?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆