简体   繁体   English

将Google Compute Engine与Google App Engine连接

[英]Connecting Google Compute Engine with Google App Engine

I am trying to connect a Google Compute Engine instance with a MySQL database to Google App Engine using Laravel. 我正在尝试使用Laravel将具有MySQL数据库的Google Compute Engine实例连接到Google App Engine。 I actually have connected my Google App Engine to a Cloud SQL instance, I don't have problem with this, but I need an additional database connection with the database located on Google Compute Engine. 实际上,我已经将Google App Engine连接到Cloud SQL实例,对此没有问题,但是我需要与位于Google Compute Engine上的数据库进行额外的数据库连接。

Google Compute Engine instance is on a different project. Google Compute Engine实例在另一个项目上。 This is my scheme: 这是我的计划:

Project A -> Compute Engine -> Instance -> MySQL database 项目A->计算引擎->实例-> MySQL数据库

Project B -> App Engine -> Laravel 项目B-> App Engine-> Laravel

Project B -> Cloud SQL -> DB-instance -> MySQL database 项目B-> Cloud SQL-> DB-instance-> MySQL数据库

This is my app.yaml file: 这是我的app.yaml文件:

runtime: php
env: flex

runtime_config:
  document_root: public

# Ensure we skip ".env", which is only for local development
skip_files:
  - .env

env_variables:
  # Put production environment variables here.
  APP_LOG: "errorlog"
  APP_KEY: "[KEY]"
  STORAGE_DIR: "/tmp"
  CACHE_DRIVER: "database"
  SESSION_DRIVER: "database"
  APP_DEBUG: "true"

  #CLOUD SQL database connection
  DB_CONNECTION: "[DATABASE_1_NAME]"
  DB_HOST: "[CLOUD_SQL_INSTANCE_NAME]"
  DB_DATABASE: "[DATABASE_1_NAME]"
  DB_USERNAME: "root"
  DB_PASSWORD: "[PASSWORD]"
  DB_SOCKET: "/cloudsql/[PROJECTB]:[REGION]:[CLOUD_SQL_INSTANCE_NAME]"

  # COMPUTE ENGINE database connection
  DB_HOST_2: "[COMPUTE_ENGINE_INSTANCE_NAME]"
  DB_DATABASE_2: "[DATABASE_2_NAME]"
  DB_USERNAME_2: "root"
  DB_PASSWORD_2: "[PASSWORD]"

beta_settings:
    cloud_sql_instances: "[PROJECTB]:[REGION]:[CLOUD_SQL_INSTANCE_NAME]"

I consider you're using Google App Engine Standard environment with PHP. 我认为您正在使用带有PHP的Google App Engine标准环境。 When you connect a GAE Application to a DB hosted on a Google Compute Engine instance, it is treated as a connection to an "external DB". 当您将GAE应用程序连接到Google Compute Engine实例上托管的数据库时,会将其视为到“外部数据库”的连接。 Thus, you need to consider GAE as an external client of your GCE instance. 因此,您需要将GAE视为GCE实例的外部客户端。

Therefore, you must configure your VPC firewall in order to accept connections to the port 3306 from outside and you must specify the external GCE instance IP address as the host of your connection string. 因此,必须配置VPC防火墙以接受从外部到端口3306的连接,并且必须将外部GCE实例IP地址指定为连接字符串的主机。 Be sure that your firewall rule accepts connections from everywhere (IP mask: 0.0.0.0/0). 确保您的防火墙规则接受来自任何地方的连接(IP掩码:0.0.0.0/0)。

Hope this helps you. 希望这对您有所帮助。 Bye 再见

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM