如何在 Windows 上部署 Rails 3 应用程序?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/5268794/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How do I deploy a Rails 3 applications on Windows?
提问by gamov
I've been searching for a way to reliably deploy a Rails 3 application on Windows. I'm quite shocked that it seems like there isn't currently any way to do this. The Apache + few Mongrel services solution don't work currently because Mongrel cannot run in daemon mode therefore I can't install it as a mongrel_service.
我一直在寻找一种在 Windows 上可靠地部署 Rails 3 应用程序的方法。我很震惊,目前似乎没有任何方法可以做到这一点。Apache + 少量 Mongrel 服务解决方案目前不起作用,因为 Mongrel 无法在守护进程模式下运行,因此我无法将其安装为 mongrel_service。
The requirements I guess should be:
我猜的要求应该是:
- A web server compatible with Rails 3.
- Must be able to run as a Windows service, daemonized.
- Must be able to restart automatically in case something goes wrong.
- Must be production quality: no memory leaks, etc.
- Should be able to scale, and accept multiple requests concurrently.
- Less hacks possible.
- 与 Rails 3 兼容的 Web 服务器。
- 必须能够作为守护进程的 Windows 服务运行。
- 如果出现问题,必须能够自动重新启动。
- 必须是生产质量:没有内存泄漏等。
- 应该能够扩展并同时接受多个请求。
- 更少的黑客可能。
I found out these things:
我发现了这些事情:
- Mongrel is not production ready for Rails 3 (1.2.0pre), I experience memory leaks quite fast from a console window. The app just exits.
- Mongrel doesn't run in daemon mode (
-d
) with Rails 3. - Therefore Mongrel cannot be installed as a service.
- Phusion Passenger is not available on Windows (would be the best solution).
- Mongrel 还没有为 Rails 3 (1.2.0pre) 做好生产准备,我在控制台窗口中遇到内存泄漏非常快。该应用程序刚刚退出。
- 在
-d
Rails 3 中,Mongrel 不以守护进程模式 ( )运行。 - 因此 Mongrel 不能作为服务安装。
- Phusion 乘客在 Windows 上不可用(将是最好的解决方案)。
These are the possible solutions I came up with:
这些是我想出的可能的解决方案:
- Get a Linux box, install Apache + Phusion Passenger and roll.
- Using thin, however, the author says the thin process is not 'guarded'.
- Using Ngnix, however, the author says he just ran a default app, not a full run app.
- Using Ngnix. I think this solution suffers the same problem as above.
- Using a virtualization of Linux, but I must solve problems like auto-start, etc.
- Run on JRuby within Tomcat.
- 获取一个 Linux 机器,安装 Apache + Phusion Passenger 并滚动。
- 但是,使用 Thin时,作者表示,thin 过程不受“保护”。
- 然而,使用 Ngnix,作者说他只是运行了一个默认应用程序,而不是一个完整运行的应用程序。
- 使用 Ngnix。我认为这个解决方案遇到了与上述相同的问题。
- 使用 Linux 的虚拟化,但我必须解决自动启动等问题。
- 在 Tomcat 中的 JRuby 上运行。
This might be a handy tool: http://projectkenai.com/projects/winsw
这可能是一个方便的工具:http: //projectkenai.com/projects/winsw
I hope we can find a real solution to this issue.
我希望我们能找到解决这个问题的真正方法。
Update:
更新:
I agree that JRuby + a j2ee container is the best bet. Some problems must be resolved like gems with extensions, etc. There are lots of valuable ideas here: http://rails-nutshell.labs.oreilly.com/ch14.html#production_r259035_id35801805
我同意 JRuby + j2ee 容器是最好的选择。有些问题必须解决,例如带有扩展名的 gems 等。这里有很多有价值的想法:http: //rails-nutshell.labs.oreilly.com/ch14.html#production_r259035_id35801805
采纳答案by ChrisOnRails
This is the setup I currently have running:
这是我目前正在运行的设置:
- Windows server 2008
- Apache 2.2
- Thin Server
- Ruby 1.9.2
- Rails 3.0.9
- 视窗服务器 2008
- 阿帕奇 2.2
- 瘦服务器
- 红宝石 1.9.2
- 导轨 3.0.9
Installation of these aspects is covered by this great tutorial "How to install and configure Ruby on Rails with Windows Server 2008 EE". I ignored the LDAP and ActiveDirectory bit, but there is a nice workaround discussed there for installing Thin server since gem 'thin'
will normally break on Windows.
这篇很棒的教程“如何使用 Windows Server 2008 EE 安装和配置 Ruby on Rails”涵盖了这些方面的安装。我忽略了 LDAP 和 ActiveDirectory 位,但是那里讨论了一个很好的解决方法来安装瘦服务器,因为gem 'thin'
通常会在 Windows 上中断。
For production I set up MySQL Server 5.5 to host my database. The mysql2 adapter is required for Rails 3 but is not yet supported in my Windows environment. The mysql adapter will also throw an error on Rails 3, but as a workaround you can get it to work by installing an older version of libmysql.dll. You just need to drop it into your Ruby192/bin directory.
对于生产,我设置了 MySQL Server 5.5 来托管我的数据库。Rails 3 需要 mysql2 适配器,但在我的 Windows 环境中尚不支持。mysql 适配器也会在 Rails 3 上引发错误,但作为一种解决方法,您可以通过安装旧版本的libmysql.dll来使其工作。你只需要把它放到你的 Ruby192/bin 目录中。
Once the proper mysql adapter and server is installed you'll need to create the database:
一旦安装了正确的 mysql 适配器和服务器,您将需要创建数据库:
>> mysql -u root -p
[enter root pw]
create database production;
quit;
(You may need to add your MySQL installation to your path if 'mysql' cannot be found.)
(如果找不到“mysql”,您可能需要将您的 MySQL 安装添加到您的路径中。)
Finally, set the database config found at your_rails_app/config/database:
最后,设置在 your_rails_app/config/database 中找到的数据库配置:
# MySQL Production Database
production:
adapter: mysql
database: production
pool: 5
timeout: 5000
encoding: utf8
password: [your_root_password]
host: localhost
The rest, including the proxy setup and running as a Windows service, is covered at "How to install and configure Ruby on Rails with Windows Server 2008 EE". To make sure your basic Thin setup is running correctly:
“如何使用 Windows Server 2008 EE 安装和配置 Ruby on Rails”中介绍了其余部分,包括代理设置和作为 Windows 服务运行。要确保您的基本 Thin 设置正常运行:
thin start -p 3000 -e production
This should start your server on port 3000 in production mode using the MySQL database. The only thing missing here is load balancing, which I'm hoping to find an answer to soon!
这应该使用 MySQL 数据库在生产模式下在端口 3000 上启动您的服务器。这里唯一缺少的是负载平衡,我希望尽快找到答案!
回答by MattC
Personally, I think the JRuby + Tomcat avenue is going to be your best bet, just because Tomcat is vetted on Windows and it along with JRuby are pretty stable. My first thought was Passenger as well, and it's sad that it's still not ported.
就我个人而言,我认为 JRuby + Tomcat 大道将是您最好的选择,因为 Tomcat 在 Windows 上经过,并且它与 JRuby 一起非常稳定。我的第一个想法也是Passenger,遗憾的是它还没有移植。
回答by Sarah Duffy
EngineYard is easy enough to deploy a rails app from a windows enviornment just install ey gem and change one or two things in your gemfile.lock a good link is https://support.cloud.engineyard.com/entries/20996706-Deploy-from-Windows
EngineYard 很容易从 Windows 环境部署 rails 应用程序,只需安装 ey gem 并更改 gemfile.lock 中的一两件事,一个好的链接是https://support.cloud.engineyard.com/entries/20996706-Deploy-从-Windows
they give you 500 free hours as well when getting started
他们在开始时也给你 500 小时的免费时间