简体   繁体   English

如何移植转发/代理云 SQL 连接以从 Internet 访问?

[英]How to port forward/proxy Cloud SQL connection to access from the internet?

Is there a way to proxy/ port forward GCP Cloud SQL so that we can connect to it via the internet?有没有办法代理/端口转发 GCP Cloud SQL 以便我们可以通过互联网连接到它?

I don't want to do an SSH port forward via a Virtual Machine.我不想通过虚拟机转发 SSH 端口。 Instead, I'm looking for a way such that we could connect to CloudSQL from a public IP of either a Virtual Machine or a Kubernetes service.相反,我正在寻找一种方法,以便我们可以从虚拟机的公共 IP 或 Kubernetes 服务连接到 CloudSQL。

I don't want to connect directly from the public IP of the CloudSQL instance as it requires us to whitelist the user's IP address.我不想直接从 CloudSQL 实例的公共 IP 连接,因为它要求我们将用户的 IP 地址列入白名单。 We have also tried the Cloud SQL proxy but faced speed and performance issues.我们还尝试了 Cloud SQL 代理,但面临速度和性能问题。

Hence, now I'm looking for a solution to proxy the CloudSQL connection from a VM or Kubernetes service因此,现在我正在寻找一种解决方案来代理来自 VM 或 Kubernetes 服务的 CloudSQL 连接

I have tried using Stunnel to proxy the connection as described in this documentation .我已尝试使用 Stunnel 来代理本文档中描述的连接。

output=/tmp/stunnel.log
CAfile=/tmp/mysql-server-ca.pem
client=yes
pid=/var/run/stunnel.pid
verifyChain=yes
sslVersion=TLSv1.2
[mysqls]
accept=0.0.0.0:3307
connect=private-ip:3306

But, I get an error while connecting to the MySQL server: ERROR 2013 (HY000): Lost connection to MySQL server at 'reading initial communication packet', system error: 104但是,在连接到 MySQL 服务器时出现错误: ERROR 2013 (HY000): Lost connection to MySQL server at 'reading initial communication packet', system error: 104

Edit:编辑:

  1. Stunnel runs on a Virtual Machine on Google Cloud Stunnel 在 Google Cloud 上的虚拟机上运行
  2. Stunnel connects to CloudSQL via Private IP (Both VM and CloudSQL share the same subnet) Stunnel 通过私有 IP 连接到 CloudSQL(VM 和 CloudSQL 共享同一个子网)
  3. MySQL can be connected from the VM using the private IP MySQL 可以使用私有 IP 从 VM 连接

Stunnel Logs:隧道日志:

2022.09.22 10:53:17 LOG5[2]: Service [mysqls] accepted connection from 127.0.0.1:37014
2022.09.22 10:53:17 LOG5[2]: s_connect: connected <mysql-private-ip>:3306
2022.09.22 10:53:17 LOG5[2]: Service [mysqls] connected remote server from 10.128.0.53:53302
2022.09.22 10:53:17 LOG3[2]: SSL_connect: ../ssl/record/ssl3_record.c:331: error:1408F10B:SSL routines:ssl3_get_record:wrong version number
2022.09.22 10:53:17 LOG5[2]: Connection reset: 0 byte(s) sent to TLS, 0 byte(s) sent to socket

To access a Cloud SQL from a Compute Engine VM try the following, you can use either the Cloud SQL Auth proxy (with public or private IP), or connect directly using a private IP address要从 Compute Engine VM 访问 Cloud SQL,请尝试以下操作,您可以使用 Cloud SQL 身份验证代理(使用公共或私有 IP),或使用私有 ZA12A3079E14CED46E69BA52B8 地址直接连接

  • From the client machine or Compute Engine VM instance, use What's my IP to see the IP address of the client machine.在客户端计算机或 Compute Engine 虚拟机实例中,使用 What's my IP 查看客户端计算机的 IP 地址。
  • Copy that IP address.复制该 IP 地址。 In the Google Cloud console, go to the Cloud SQL Instances page.在 Google Cloud 控制台中,go 到 Cloud SQL 实例页面。
  • Go to Cloud SQL Instances Go 到云 SQL 实例
  • To open the Overview page of an instance, click the instance name.要打开实例的概览页面,请单击实例名称。 Select Connections from the SQL navigation menu. Select 来自 SQL 导航菜单的连接。
  • In the Authorized networks section, click Add network and enter the IP address of the machine where the client is installed.在授权网络部分,单击添加网络,然后输入安装客户端的机器的 IP 地址。 Note: The IP address of the instance and the MySQL client IP address you authorize must be the same IP version: either IPv4 or IPv6注意:您授权的实例的IP地址与MySQL客户端IP地址必须相同IP地址必须是相同的ZA12A3079E14CEDB21AZ9或IPvA3079E14CEDB21AZ6版本
  • Click Done.单击完成。 Then click Save at the bottom of the page to save your changes.然后单击页面底部的保存以保存您的更改。 Connect to your instance, either with SSL or without SSL.使用 SSL 或不使用 SSL 连接到您的实例。

To access a Cloud SQL instance from an application running in Google Kubernetes Engine , you can use either the Cloud SQL Auth proxy (with public or private IP), or connect directly using a private IP address. To access a Cloud SQL instance from an application running in Google Kubernetes Engine , you can use either the Cloud SQL Auth proxy (with public or private IP), or connect directly using a private IP address. To connect to Cloud SQL you must have:要连接到 Cloud SQL,您必须具备:

  • A GKE cluster, with the kubectl command-line tool installed and configured to communicate with the cluster.一个 GKE 集群,安装并配置了 kubectl 命令行工具以与集群通信。 For help getting started with GKE, see the Quickstart .如需 GKE 入门帮助,请参阅快速入门
  • Check the document for steps on how to configure without SSL查看文档了解如何在没有 SSL 的情况下进行配置的步骤
  • For Public IP-configured instances, a public-facing IPv4 address may be enabled, allowing users outside the GCP project and VPC network to connect to the instance.对于配置了公共 IP 的实例,可以启用面向公众的 IPv4 地址,从而允许 GCP 项目和 VPC 网络之外的用户连接到实例。

Check the similar example here.在此处查看类似的示例

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

相关问题 运行错误:.\cloud_sql_proxy.exe 用于云 sql 连接 - Error running: .\cloud_sql_proxy.exe for cloud sql connection 云 SQL 代理连接偶尔超时 - Cloud SQL Proxy connection timesout occasionaly 使用 Cloud SQL Auth 代理连接 cloudsql 实例时出错 - Error while connection cloudsql instance using Cloud SQL Auth proxy 如何从 Google Colab 访问 Cloud SQL - How to access Cloud SQL from Google Colab 有没有办法通过 docker 容器内的代理访问谷歌云 SQL - Is there a way to access google cloud SQL via proxy inside docker container 云 sql 连接中的 Google 身份验证错误 - Error from Google Authentication in cloud sql connection 无法使用 Cloud SQL 代理从 Google Compute Engine 连接到 Google Cloud SQL - Can't connect to Google Cloud SQL from Google Compute Engine with Cloud SQL Proxy 从 GKE pod 查询 Node.js 中的 Google 云 SQL 实例,云 sql 代理作为边车运行 - Query a Google cloud SQL instance in Node.js from a GKE pod with cloud sql proxy running as sidecar 云 SQL 代理错误 - 尝试以其访问权限禁止的方式访问套接字 - Cloud SQL Proxy error - An attempt was made to access a socket in a way forbidden by its access permissions GAE - 如何在 quarkus java11 应用程序中配置从 Google App Engine 访问 Cloud SQL? - GAE - How to configure access to Cloud SQL from Google App Engine in quarkus java11 app?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM