使用Cloud sql代理连接到多个CloudSQL实例? [英] Connecting to multiple CloudSQL instances using Cloud sql proxy?
问题描述
在文档中,我发现了一行关于使用-instances参数。对于多个实例,请使用以逗号分隔的列表。
但不确定如何制作该外观。 https://cloud.google.com/sql/docs/sql-proxy 。
- name:cloudsql-proxy $ b我使用Google Container引擎,并且使用单个CloudSQL实例。 $ b image:b.gcr.io/cloudsql-docker/gce-proxy:1.05
command:[/ cloud_sql_proxy,--dir = / cloudsql,
-instances = starchup- 147119:us-central1:first-db = tcp:3306,
-credential_file = / secrets / cloudsql / credentials.json]
volumeMounts:
- name:cloudsql-oauth-凭证
mountPath:/ secrets / cloudsql
readOnly:true
- name:ssl-certs
mountPath:/ etc / ssl / certs
但是对于多个我已经尝试了 -instances
部分:
-instances = starchup-147119:us-central1:first-db,starchup-147119:us-central1:second-db = tcp:3306
和
-instances = starchup-147119:us-central1:first-db = tcp:3306,starchup-147119:us-central1:second-db = tcp:3306
但它们都会给出各种错误RS; ECONNREFUSED 127.0.0.1:3306
, ER_DBACCESS_DENIED_ERROR
和 ER_ACCESS_DENIED_ERROR
任何帮助都非常感谢!
托管在同一个TCP端口上的数据库。相反,在逗号分隔列表中为每个数据库指定端口:
-instances = project:region:db = tcp:3306 ,project:region:db-2 = tcp:3307
我在这里使用了3306和3307,可以使用任何你想要的端口!确保Container Engine配置的其余部分允许在这些端口上的节点之间进行通信(默认情况下这是真的,我不使用GKE)。
大多数mysql驱动程序默认连接到端口3306,但可以指定另一个端口。您必须安排您的代码连接到您为第二个数据库选择的不同端口。
I'm attempting to use the cloud sql proxy to connect to 2 different cloud sql instances...
In the docs I found a line about Use -instances parameter. For multiple instances, use a comma-separated list.
but not sure how to make that look. https://cloud.google.com/sql/docs/sql-proxy. I'm using Google Container engine, and with a single CloudSQL instance it works great:
- name: cloudsql-proxy
image: b.gcr.io/cloudsql-docker/gce-proxy:1.05
command: ["/cloud_sql_proxy", "--dir=/cloudsql",
"-instances=starchup-147119:us-central1:first-db=tcp:3306",
"-credential_file=/secrets/cloudsql/credentials.json"]
volumeMounts:
- name: cloudsql-oauth-credentials
mountPath: /secrets/cloudsql
readOnly: true
- name: ssl-certs
mountPath: /etc/ssl/certs
But for multiple I've tried the -instances
section as such:
-instances=starchup-147119:us-central1:first-db,starchup-147119:us-central1:second-db=tcp:3306
and
-instances=starchup-147119:us-central1:first-db=tcp:3306,starchup-147119:us-central1:second-db=tcp:3306
but they all give various errors; ECONNREFUSED 127.0.0.1:3306
, ER_DBACCESS_DENIED_ERROR
, and ER_ACCESS_DENIED_ERROR
Any help is much appreciated!
You cannot have two databases hosted on the same TCP port. Instead, specify ports for each database in the comma-separated list:
-instances=project:region:db=tcp:3306,project:region:db-2=tcp:3307
I used 3306 and 3307 here, but you can use any ports you want! Make sure that the rest of your Container Engine config allows for communication between nodes on these ports (maybe that's true by default, I don't use GKE).
Most mysql drivers connect to port 3306 by default but have a way to specify another port. You'll have to arrange for your code to connect to the different port you choose for the second database.
这篇关于使用Cloud sql代理连接到多个CloudSQL实例?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!