如何将Google Compute Engine实例池连接到同一项目中的Cloud SQL DB? [英] How to connect from a pool of Google Compute Engine instances to Cloud SQL DB in the same project?

查看:89
本文介绍了如何将Google Compute Engine实例池连接到同一项目中的Cloud SQL DB?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果我有一个Compute Engine实例池(位于具有静态IP的负载平衡器后面),并且我想从这些实例上的Java应用程序连接到同一项目中的Cloud Sql数据库,那么关于如何实现1)这些负载均衡器中的实例没有静态的外部IP,所以我无法授权通过IP地址访问云SQL。

>

2)com.mysql.jdbc.GoogleDriver在Compute Engine上不可用,因为它在App Engine上。



<如果我尝试使用股票MySql JDBC驱动程序,它不理解连接字符串,如:

  JDBC:谷歌:MySQL的:// __ INSTANCE_NAME __ / __ DB_NAME __>用户= __用户__&放大器;放大器;密码= __ password__; 

并且没有说找不到适合jdbc的驱动程序:google:mysql:// __ instance_name __ / __ db_name __>?user = __ user __& amp; amp; password = __ password__

我无法相信我无法轻松地将Compute Engine实例连接到同一Google Cloud项目的Cloud SQL数据库。



是我使用 https://cloud.google.com/sql/docs/compute-engine-access ?这似乎是大量的工作要自动完成的实例,将来到池中,并随时离开!



有人可以抛出一些亮光吗?

p>

谢谢。

解决方案

最后能够从动态IP GCE实例通过Google Cloud Sql代理转移到Google Cloud SQL数据库。由于存在变体(same-project-app-to-db,different-project-app-to-db),并且我还想为任何可能需要它的人保留一些App-engine-to-Cloud-SQL连接信息,写了一些关于它的文章,并将其放在 https://roshandawrani.wordpress.com/2016/09/22/connecting-from-gce-gae-java-to-google-cloud-sql/ 。希望可以将链接留在详细信息中,而不是再次复制这里的所有内容。干杯。


If I have a pool of Compute Engine instances (behind a load-balancer with a static IP), and I want to connect from Java apps on these instances to a Cloud Sql database in the same project, what's the way to about it?

1) These instances in the load balancer don't have static external IPs, so I can't authorize access to Cloud SQL by IP addresses.

2) "com.mysql.jdbc.GoogleDriver" is not available on Compute Engine, as it is on App Engine.

3) If I try to use the stock MySql JDBC driver, it doesn't understand a connection string like:

"jdbc:google:mysql://__instance_name__/__db_name__>?user=__user__&amp;password=__password__";

and fails saying "No suitable driver found for jdbc:google:mysql://__instance_name__/__db_name__>?user=__user__&amp;password=__password__"

I can't believe I can't easily connect from Compute Engine instances to a Cloud SQL database of the same Google Cloud project.

Is my only option to use "Connecting using the Cloud SQL Proxy" approach as described on https://cloud.google.com/sql/docs/compute-engine-access? That seems significant amount of work to be done automatically on instances that will come to the pool and go away at will!

Could someone please throw some light on it?

Thanks.

解决方案

Finally able to connect from dynamic-IP GCE instances to Google Cloud SQL database through the Google Cloud Sql proxy. Since there were variants (same-project-app-to-db, different-project-app-to-db) and I also wanted to keep some App-engine-to-Cloud-SQL connection information nearby for anyone who may need it, made a little write-up about it and put it at https://roshandawrani.wordpress.com/2016/09/22/connecting-from-gce-gae-java-to-google-cloud-sql/. Hope it's ok to leave the link here to the detailed information instead of reproducing everything here again. Cheers.

这篇关于如何将Google Compute Engine实例池连接到同一项目中的Cloud SQL DB?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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