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

发布于 2024-10-09 03:26:03 字数 1388 浏览 6 评论 0原文

拥有一个 Ruby on Rails 应用程序是否可行,该应用程序:

a) 部署在 Heroku 上,

b) 使用远程 SQL Server 数据库?

我认为我需要在 Heroku 上安装 unixODBC,但我找不到这样做的方法。这可能吗? 或者,有没有其他方法(没有 ODBC?)来完成此任务?

非常感谢您的任何指导或提示。


更新: 有关该主题的一些信息:

1) Heroku 默认情况下预安装了 unixODBC 和 FreeTDS,因此您已经拥有它们。

2) 此外,还可以通过 Heroku 控制台以反引号运行 shell 命令,例如:(

  heroku console 
  `odbcinst`

在 Heroku shell 中运行“odbcinst”命令并显示结果)

3) 您无权访问包所在切片之外的文件系统安装。如果您只需要驱动程序路径,Heroku 支持可以提供它(在我的例子中为 /usr/lib/odbc/libtdsodbc.so )。

4) 您无法在 Heroku shell 中运行 sudo 命令。

目前,要连接到 MS SQL Server,您至少需要附加“freetds.conf”文件。即使使用tinyTDS(tinyTDS gitgub 问题页面中有一个开放票证#2)。来自“wiki.rubyonrails.org SLASH数据库支持SLASH ms-sql”的无DSN连接指令对我不起作用,我想这个连接也需要一些额外的配置。

如果没有 sudo,则无法修改“freetds.conf”。因此,我的结论是,目前还没有办法让MS SQL和Heroku一起工作。

我已设法与 EngineYard 和 activerecord-sqlserver-adapter 建立此连接。

我按照以下说明进行操作: https://github.com/rails-sqlserver /activerecord-sqlserver-adapter/wiki/平台安装---Ubuntu (只有一些文件路径差异,例如“odbc.ini”位于“/etc/uniodbc”中,而不是“/etc”中 - 这很容易解决)。

我使用 EY Unix Packages 功能安装了“unixODBC”和“freetds”软件包,并通过 SSH 手动进行了所有配置。 Sudo 在 EY 中可用(无需密码)。还有 Chef Recepes 功能可以自动执行这些配置(看起来很简单,我明天要尝试一下)。

希望这有帮助。

Is it feasible to have a Ruby on Rails app, which is:

a) deployed on Heroku, and

b) working with a remote SQL Server database?

I take it that I'll need unixODBC installed on Heroku, but I cannot find a way to do so. Is this possible?
Or, is there any other way (without ODBC?) to accomplish this?

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.

2) Also, it is possible to run shell commands via Heroku Console in backticks, e.g.:

  heroku console 
  `odbcinst`

(runs "odbcinst" command in Heroku shell and shows the result)

3) You do not have access to filesystem outside of your slice where the packages are installed. If you only need a driver path, Heroku support can provide it (/usr/lib/odbc/libtdsodbc.so in my case).

4) You cannot run sudo commands in Heroku shell.

At the moment, to connect to MS SQL Server you at least need to append ‘freetds.conf’ file. Even when using tinyTDS (there is an open ticket#2 in tinyTDS gitgub issue page). 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.

‘freetds.conf’ cannot be modified without sudo. Therefore, I conclude that currently there is no way to make MS SQL and Heroku work together.

I’ve managed to set up this connection with EngineYard and 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, e.g. ‘odbc.ini’ is located in ‘/etc/unicodbc’, not in ‘/etc’ - this is easy to work out).

I installed 'unixODBC' and 'freetds' packages using EY Unix Packages feature, and made all configurations manually through SSH. Sudo is available in EY (no password required). There is also Chef Recepes feature to automate those configurations (seems to be pretty easy, I'm going to try it tomorrow).

Hope this is helpful.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

森林散布 2024-10-16 03:26:03

这是可能的。

由于 Heroku 会在您存储库中提供的任何内容上复制/符号链接其自己的 config/database.yml,因此您可能需要采取额外的步骤(例如在 config/environments/Production.rb 中) > 或在 config/initializers/remote_mssql_from_heroku.rb 中)以适当地设置您的应用程序。

然而,您将面临挑战,从 Heroku 到 MSSQL 数据库的流量将穿越公共互联网。默认情况下,此流量不会被加密。世界上的每个人都可能能够监控您的 Heroku 应用程序和数据库之间的流量,甚至可以出于良性或恶意目的更改正在传输的流量,而您却无法检测到它。 MS SQL 提供通过 SSL 连接的功能。此功能需要在 MSSQL 服务器中进行显式配置,因此您必须能够访问和修改该配置。此外,此配置要求您的客户端库是最新的并且能够通过 SSL 与 MSSQL 进行通信。请注意,MSSQL 服务器将强制您的服务器证书列出与服务器的 FQDN(至少是服务器知道的 FQDN)完全匹配或通配符匹配的通用名称或主题备用名称,并且客户端使用服务器的 FQDN与证书上的名称之一完全匹配或通配符匹配。

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 (e.g. in config/environments/production.rb or in config/initializers/remote_mssql_from_heroku.rb) to set up your application appropriately.

You will face the challenge, however, that traffic from Heroku to your MSSQL database will traverse the public internet. 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. MS SQL offers the capability to connect over SSL. This capability requires explicit configuration in the MSSQL server, so you must be able to access and modify that configuration. Additionally, this configuration requires that your client library be up-to-date and capable of talking with MSSQL over SSL. 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.

话少情深 2024-10-16 03:26:03

我已成功使用以下文章,该文章使用 Heroku 的较新构建包功能来使用 TinyTDS 并远程连接到 SQL Server 2008 R2。我仍在研究如何加密流量。希望这对其他人有帮助!

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

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. 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#

猫卆 2024-10-16 03:26:03

我们遇到了类似的问题,需要将旧数据从 SQL Server 数据库导入到我们的新应用程序中。数据不是直接表格导入,而是需要经过一些处理和转换。我们为此构建了一个导入层,该层位于私有 gem 中,以免旧数据转换问题污染新应用程序。这种方法还旨在允许增量更新,当我们接近发布时,我们将保持同步记录直到切换时刻。

Heroku 告诉我们,连接到 SQLServer 并不简单,特别是因为它们不支持 FreeTDS。他们的支持人员建议使用我们办公室笔记本电脑上的导入 gem 运行一个实例,并将其配置为连接到他们的数据库(这需要专用数据库,而不是免费的共享数据库)。这听起来对我们来说是最容易接受的方法。

其次,关于@Justice提到的安全性,我们与托管公司讨论了为SQLServer配置SSL,他们指出了这一点的复杂性。他们推荐 VPN 作为更简单的解决方案。由于我们没有办公室端 VPN 硬件,最简单且免费的解决方案被证明是 SSH 隧道。

我们已经设置了从笔记本电脑到 SQLServer Windows 机器的 SSH 隧道。这很简单。我们在 Windows 上安装了 CopSSH(顺便说一下,它附带了一个 Linux shell),并且我们能够简单地设置一个隧道,让笔记本电脑与本地主机进行 SQLServer 连接,即:

ssh -L 1433:本地主机:1433 user@windows_server_name

We're having a similar problem where we're needing to import old data from a SQL Server database into our new app. 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. 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. 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). 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. They recommended VPN as an easier solution. As we don't have office-side VPN hardware, the simplest and free solution proved to be an SSH tunnel.

We've set up an SSH tunnel from the laptop to the SQLServer Windows box. 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, i.e.:

ssh -L 1433:localhost:1433 user@windows_server_name

不顾 2024-10-16 03:26:03

我不知道 Heroku 有 FreeTDS 吗?有人告诉我他们没有。 TinyTDS 如果与 FreeTDS 0.91 一起使用,则 freetds.conf 依赖项为零,并由运行时连接参数驱动。我们正在研究构建一个 Ubuntu 10.4 原生 gem,它将 0.91 与 OpenSSL 静态链接,这样您就可以将其放入 Heroku 中,然后使用它连接到 Azure 和/或您拥有的外部数据库。

I did not know Heroku has FreeTDS on it? 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. 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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文