简体   繁体   English

RoR应用程序部署在Heroku上并使用SQL Server数据库

[英]RoR app deployed on Heroku and working with SQL Server database

Is it feasible to have a Ruby on Rails app, which is: 拥有Ruby on Rails应用程序是否可行,该应用程序是:

a) deployed on Heroku, and a)部署在Heroku上,以及

b) working with a remote SQL Server database? b)使用远程SQL Server数据库?

I take it that I'll need unixODBC installed on Heroku, but I cannot find a way to do so. 我认为我将需要在Heroku上安装unixODBC,但是我找不到解决方法。 Is this possible? 这可能吗? Or, is there any other way (without ODBC?) to accomplish this? 或者,是否有其他方法(没有ODBC?)来完成此任务?

Thank you very much for any guidance or tip. 非常感谢您的指导或提示。


Updated: Some info on the subject: 更新:有关此主题的一些信息:

1) Heroku pre-installs both unixODBC and FreeTDS by default, so you already have them. 1)Heroku默认预安装了unixODBC和FreeTDS,因此您已经拥有了它们。

2) Also, it is possible to run shell commands via Heroku Console in backticks, eg: 2)另外,可以通过反引号中的Heroku Console运行shell命令,例如:

  heroku console 
  `odbcinst`

(runs "odbcinst" command in Heroku shell and shows the result) (在Heroku Shell中运行“ odbcinst”命令并显示结果)

3) You do not have access to filesystem outside of your slice where the packages are installed. 3)您无权访问安装了软件包的片之外的文件系统。 If you only need a driver path, Heroku support can provide it (/usr/lib/odbc/libtdsodbc.so in my case). 如果仅需要驱动程序路径,Heroku支持人员可以提供它(在我的情况下为/usr/lib/odbc/libtdsodbc.so)。

4) You cannot run sudo commands in Heroku shell. 4)您不能在Heroku shell中运行sudo命令。

At the moment, to connect to MS SQL Server you at least need to append 'freetds.conf' file. 目前,要连接到MS SQL Server,您至少需要附加“ freetds.conf”文件。 Even when using tinyTDS (there is an open ticket#2 in tinyTDS gitgub issue page). 即使使用tinyTDS(tinyTDS gitgub问题页面中有一个开放的票证#2)。 DSN-less connection instructions from "wiki.rubyonrails.org SLASH database-support SLASH ms-sql" didn't work for me, I guess this connection requires some extra-configuration either. “ wiki.rubyonrails.org SLASH数据库支持SLASH ms-sql”中的无DSN连接说明对我不起作用,我想此连接也需要一些额外的配置。

'freetds.conf' cannot be modified without sudo. 没有sudo不能修改'freetds.conf'。 Therefore, I conclude that currently there is no way to make MS SQL and Heroku work together. 因此,我得出结论,目前尚无办法使MS SQL和Heroku一起工作。

I've managed to set up this connection with EngineYard and activerecord-sqlserver-adapter. 我设法通过EngineYard和activerecord-sqlserver-adapter建立了此连接。

I followed these instructions: https://github.com/rails-sqlserver/activerecord-sqlserver-adapter/wiki/Platform-Installation---Ubuntu (there are only some filepath differences, eg 'odbc.ini' is located in '/etc/unicodbc', not in '/etc' - this is easy to work out). 我遵循了以下说明: https : //github.com/rails-sqlserver/activerecord-sqlserver-adapter/wiki/Platform-Installation---Ubuntu (只有一些文件路径差异,例如“ odbc.ini”位于“ / etc / unicodbc”,而不是在“ / etc”中-这很容易解决)。

I installed 'unixODBC' and 'freetds' packages using EY Unix Packages feature, and made all configurations manually through SSH. 我使用EY Unix软件包功能安装了“ unixODBC”和“ freetds”软件包,并通过SSH手动进行了所有配置。 Sudo is available in EY (no password required). EY中提供了Sudo(无需密码)。 There is also Chef Recepes feature to automate those configurations (seems to be pretty easy, I'm going to try it tomorrow). 还提供了Chef Recepes功能来自动执行这些配置(似乎很简单,我明天将尝试使用它)。

Hope this is helpful. 希望这会有所帮助。

It is possible. 有可能的。

Because Heroku copies/symlinks its own config/database.yml over whatever you supply in your repository, you may need to take additional steps (eg in config/environments/production.rb or in config/initializers/remote_mssql_from_heroku.rb ) to set up your application appropriately. 由于Heroku在存储库中提供的内容上复制/符号链接自己的config/database.yml ,因此可能需要采取其他步骤(例如,在config/environments/production.rbconfig/initializers/remote_mssql_from_heroku.rb )进行设置您的应用程序适当。

You will face the challenge, however, that traffic from Heroku to your MSSQL database will traverse the public internet. 但是,您将面临挑战,即从Heroku到您的MSSQL数据库的流量将穿越公共互联网。 By default, this traffic will not be encrypted. 默认情况下,此流量不会被加密。 Potentially everyone in the world will be able to monitor your traffic between your Heroku application and your database, and even alter the traffic in-flight, whether for benign or malicious purpose, without you being able to detect it. 潜在地,世界上的每个人都将能够监视Heroku应用程序与数据库之间的流量,甚至在进行中更改流量(无论出于良性还是恶意目的),而您都无法检测到它。 MS SQL offers the capability to connect over SSL. MS SQL提供了通过SSL连接的功能。 This capability requires explicit configuration in the MSSQL server, so you must be able to access and modify that configuration. 此功能需要在MSSQL服务器中进行显式配置,因此您必须能够访问和修改该配置。 Additionally, this configuration requires that your client library be up-to-date and capable of talking with MSSQL over SSL. 此外,此配置要求您的客户端库是最新的,并且能够通过SSL与MSSQL进行通信。 Note that MSSQL server will enforce that your server certificate list a Common Name or Subject Alternative Name exactly matching or wildcard-matching the server's FQDN (at least, the FQDN that the server knows about), and that the client use an FQDN for the server exactly matching or wildcard-matching one of the names on the certificate. 请注意,MSSQL服务器将强制您的服务器证书列出与服务器的FQDN(至少是服务器所知道的FQDN)完全匹配或与通配符匹配的公用名或主题备用名称,并且客户端应使用服务器的FQDN与证书上的名称之一完全匹配或通配符匹配。

I've successfully used the following article which uses Heroku's newer buildpack feature to use TinyTDS and connect remotely to SQL Server 2008 R2. 我已经成功使用了以下文章,该文章使用Heroku的较新的buildpack功能来使用TinyTDS并远程连接到SQL Server 2008 R2。 I'm still investigating how I could encrypt traffic. 我仍在研究如何加密流量。 Hope this helps others! 希望这对别人有帮助!

http://blog.firmhouse.com/connecting-to-sql-server-from-heroku-with-freetds-here-is-how-on-cedar# http://blog.firmhouse.com/connecting-to-sql-server-from-heroku-with-freetds-here-is-how-on-cedar#

I did not know Heroku has FreeTDS on it? 我不知道Heroku上有FreeTDS吗? I was told they did not. 有人告诉我他们没有。 TinyTDS if used with FreeTDS 0.91 can have a zero freetds.conf dependency and be driving by runtime connection args. 如果将TinyTDS与FreeTDS 0.91一起使用,则freetds.conf的相关性为零,并由运行时连接args驱动。 We are looking into building an Ubuntu 10.4 native gem that statically links 0.91 with OpenSSL so you can just drop it into Heroku and us it to connect to Azure and/or you own outside DB. 我们正在考虑构建一个将0.91与OpenSSL静态链接的Ubuntu 10.4本机gem,因此您可以将其拖放到Heroku中,然后将其连接到Azure和/或您拥有外部DB。

We're having a similar problem where we're needing to import old data from a SQL Server database into our new app. 我们遇到了类似的问题,需要从SQL Server数据库将旧数据导入到我们的新应用中。 The data isn't a straight table import, but needs to undergo some processing and conversions. 数据不是直接表导入,但需要进行一些处理和转换。 We've built an import layer for this which lives in a private gem, so as to not pollute the new app with the old data conversion issues. 我们为此建立了一个导入层,该导入层位于一个私有gem中,以免污染旧数据转换问题的新应用。 This approach is also designed to permit incremental updates, as we get closer to launch we'll keep syncing records up to the moment of switch-over. 这种方法还旨在允许增量更新,因为随着我们越来越接近启动,我们将一直保持记录同步,直到切换之时为止。

Heroku told us that it's not trivial to connect to SQLServer, in particular as they don't support FreeTDS. Heroku告诉我们,连接到SQLServer并非易事,特别是因为它们不支持FreeTDS。 Their support staff recommended to run an instance with the import gem from a laptop in our office and configure it to connect to their database (which requires a dedicated DB, not the free shared one). 他们的支持人员建议使用我们办公室中一台笔记本电脑上的导入gem运行一个实例,并将其配置为连接到他们的数据库(这需要专用的DB,而不是免费的共享数据库)。 This sounded like the most palatable approach to us. 这听起来像是我们最可口的方法。

Secondly, regarding security that was mentioned by @Justice, we discussed configuring SSL for SQLServer with the hosting company and they pointed out the complexities of this. 其次,关于@Justice提到的安全性,我们与托管公司讨论了为SQLServer配置SSL的问题,他们指出了这一点的复杂性。 They recommended VPN as an easier solution. 他们建议使用VPN作为更简单的解决方案。 As we don't have office-side VPN hardware, the simplest and free solution proved to be an SSH tunnel. 由于我们没有办公室端VPN硬件,因此最简单,免费的解决方案就是SSH隧道。

We've set up an SSH tunnel from the laptop to the SQLServer Windows box. 我们已经建立了从笔记本电脑到SQLServer Windows框的SSH隧道。 That was straightforward. 那很简单。 We had CopSSH installed on Windows (which comes with a Linux shell, by the way) and we were able to simply set up a tunnel, having the laptop talk to localhost for its SQLServer connection, ie: 我们在Windows上安装了CopSSH(顺便说一下,它带有Linux shell),并且我们能够简单地建立一个隧道,使笔记本电脑与localhost进行SQLServer连接,即:

ssh -L 1433:localhost:1433 user@windows_server_name

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

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