Rails的部署环境的Windows [英] Rails Deployment Environment on Windows

查看:172
本文介绍了Rails的部署环境的Windows的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有没有在所有部署基于Ruby的1.9.3和Rails 3.2.6与Apache在Windows计算机上的Ruby on Rails应用程序的好办法?我花了几个小时冲刷论坛,但所有的职位似乎是太旧,不能Ruby和Rails的最新版本的工作。杂种不再是正在开发中,不断引起Rails的崩溃,薄只有简陋的Windows支持我的电脑上使Ruby运行时,以在一个不寻常的方式自行终止,乘客仅支持Linux的...我有点迷失在这一点上。

Is there any good way at all to deploy a Ruby on Rails app built on Ruby 1.9.3 and Rails 3.2.6 with Apache on a Windows machine? I've spent hours scouring the forums, but all of the posts seem to be too old to work with the newest versions of Ruby and Rails. Mongrel is no longer under development and constantly causes Rails to crash, thin has only rudimentary Windows support and on my computer causes the Ruby runtime to "terminate itself in an unusual way", Passenger is Linux-only... I'm kinda lost at this point.

有没有稳定,为服务建立在与Apache最新的框架在Windows Rails应用充分证明的解决方案?

Is there any stable, well-documented solution for serving Rails apps built on the newest frameworks with Apache on Windows?

更新

我终于结束了工作了我自己的解决方案。检查出来下面向上最新指南Rails开发在Windows上。

I finally ended up working out my own solution. Check it out below for an up-to-date guide to Rails deployment on Windows.

推荐答案

更新:我刚回到我的地方部署这一过程中的公司。 11个月后离开完全无人维护,而该产品是在使用中,应用程序和服务器环境中仍能正常工作完美:)

UPDATE: I just returned to the company where I deployed with this process. After 11 months left completely unmaintained while the product was in use, the app and server environment are still functioning flawlessly :)

好吧,它看起来像我的最后的理解了它。请注意,我要部署在公司内部网上用户的一个小水池,所以我的解决方案可能无法适用于每个人。我使用的是优秀的 Bitnami RubyStack ,其中包含一个集成的Apache / Rails的/ MySQL的安装。从那里,我做了以下(Rails的3.2.6和1.9.3的Ruby工作):

Ok, it looks like I finally figured it out. Note that I am deploying to a small pool of users on a company intranet, so my solution may not work for everyone. I am using the excellent Bitnami RubyStack, which contains an integrated Apache/Rails/MySQL installation. From there I did the following (worked for Rails 3.2.6 and Ruby 1.9.3):


  1. 关闭所有的Apache和Rails(使用WEBrick /超薄/杂种/独角兽)服务器。退出您的网站,如果你有开放它的任何开发版本。清除浏览器缓存。

  1. Shut down all Apache and Rails (WEBrick/Thin/Mongrel/Unicorn) servers. Exit out of your site if you have any development versions of it open. Clear your browser cache.

如果你还没有,迁移数据库到生产模式。从RubyStack命令行,cd到应用程序的目录,然后运行捆绑EXEC耙分贝:迁移DB:架构:负载RAILS_ENV =生产。警告:DB:模式:负荷将删除你的生产数据库中的所有数据

If you haven't already, migrate your database to production mode. From the RubyStack command line, cd to your app's directory, then run bundle exec rake db:migrate db:schema:load RAILS_ENV="production". WARNING: db:schema:load will delete all data in your production database.

precompile您的资产:捆绑EXEC耙资产:precompile 。请注意,这可以采取的非常的很长一段时间取决于你的资产。

Precompile your assets: bundle exec rake assets:precompile. Note that this can take a very long time depending on your assets.

在你的的httpd.conf (对于我来说,C:\\ RubyStack-3.2.5-0 \\ Apache2的\\的conf \\ httpd.conf文件)

In your httpd.conf (for me it's C:\RubyStack-3.2.5-0\apache2\conf\httpd.conf)

请确保必需的模块没有被注释掉:

Make sure necessary modules aren't commented out:

LoadModule expires_module modules/mod_expires.so
LoadModule headers_module modules/mod_headers.so
LoadModule proxy_module modules/mod_proxy.so
LoadModule proxy_balancer_module modules/mod_proxy_balancer.so
LoadModule proxy_http_module modules/mod_proxy_http.so
LoadModule rewrite_module modules/mod_rewrite.so

然后某处粘贴以下code中的文件,与 APP_NAME 为您的Rails应用程序和 *的文件夹名称:82 是Apache正在听(通过命令听与LT所指的任何端口号;端口号>

Then paste the following code somewhere in the file, with app_name being the folder name of your Rails app and *:82 being any port number that Apache is listening to (signified by the command Listen <port_number>:

<VirtualHost *:82>

  # Your server's web or IP address goes here.
  # You can leave at localhost if deploying to
  # company intranet or some such thing.
  ServerName localhost

  # Customize the next two lines with your app's public directory
  DocumentRoot "C:/RubyStack-3.2.5-0/projects/app_name/public"
  <Directory "C:/RubyStack-3.2.5-0/projects/app_name/public">
    Allow from all
    Options -MultiViews
  </Directory>

  RewriteEngine On

  # Redirect all non-static requests to Rails server,
  # but serve static assets via Apache
  RewriteCond %{DOCUMENT_ROOT}/%{REQUEST_FILENAME} !-f
  RewriteRule ^/(.*)$ balancer://app_balancers%{REQUEST_URI} [P,QSA,L]

  # Serves dynamic rails assets from multiple servers
  # to improve performance. A Rails server such as
  # thin or WEBrick must be running on at least one of
  # these ports in order for Apache to serve your site
  <Proxy balancer://app_balancers>
    BalancerMember http://localhost:3001/
    BalancerMember http://localhost:3002/
  </Proxy>

  # Support for far-futures expires header
  <LocationMatch "^/assets/.*$">
    Header unset ETag
    FileETag None
    # RFC says only cache for 1 year
    ExpiresActive On
    ExpiresDefault "access plus 1 year"
  </LocationMatch>
</VirtualHost>


  • 为每个您的应用程序将使用Rails的服务器中的一个Windows批处理文件(* .bat)的形式。一定要在生产模式上的端口在你的平衡运行它们。例如,对于您的第一台服务器:

  • Create one Windows Batch file (*.bat) for each of the Rails servers that your app will be using. Be sure to run them in production mode on the ports in your balancer. For instance, for your first server:

    @echo off
    cd D:\your_app_folder
    rails s -e production -p 3001
    


  • 请注意:接下来的几个步骤是必要的,因为Rails的服务器需要作为服务运行,否则将被关闭,如果没有用户登录到服务器。这也让它们自动故障后重新启动。但是,Windows不能运行批处理文件作为服务,所以我们必须将它们转换为Windows EXE文件。但标准的Windows EXE文件不能被用作服务,因为它们不到的OnStart和调用OnStop方法作出响应。 SO,终于得到我们的服务器作为Windows服务运行,我们必须使用非吸吮服务经理为我们的Windows的EXE一个前端。

  • NOTE: The next few steps are necessary because the Rails servers need to run as services, or they will be shut down if there is no user logged in to the server. This also allows them to automatically restart upon failure. However, Windows cannot run Batch files as services, so we have to convert them to Windows EXEs. But standard Windows EXEs cannot be used as services because they don’t respond to the OnStart and OnStop methods. SO, to finally get our servers to run as Windows services, we have to use the Non-Sucking Service Manager as a frontend for our Windows EXEs.

    下载BAT为EXE转换器(只是谷歌的一个),并从您的批处理文件使EXE文件。确保你得到转换器有一个选项隐藏命令窗口在运行时(该选项通常被称为可见性或类似的东西。)

    Download a BAT to EXE converter (just google for one) and make EXEs from your batch files. Make sure the converter you get has an option to hide the command windows when it runs (that option is usually called "Visibility" or something like that.)

    下载非吸吮服务管理(nssm.exe)。把它放在某个地方的永久和文件夹添加到您的路径。

    Download the Non-Sucking Service Manager (nssm.exe). Put it somewhere permanent and add that folder to your path.

    启动命令提示符。键入 NSSM安装&LT;服务名&GT; ,其中&LT;服务名&GT; 是任何你想要的称为你的服务。系统将提示您输入的路径要作为服务运行的应用;选择您在第7步创建的Windows EXE文件,然后点击安装,留下命令行选项空白。

    Start a command prompt. Type nssm install <servicename>, where <servicename> is whatever you want your service to be called. You will be prompted to enter the path to the application you wish to run as a service; choose the Windows EXEs you created in step 7, then click install, leaving commandline options blank.

    重复步骤6-8全在你平衡器的端口,为每一个Rails的服务器不同的服​​务。

    Repeat steps 6-8 for all of the ports in your balancer, creating a different service for every Rails server.

    启动所有刚刚创建的服务(开始菜单 - >管理工具 - >服务)。这些服务应该立即开始,但你必须给Rails的服务器至少30秒钟来初始化。

    Start all of the Services you just created (Start Menu –> Administrative Tools –> Services). The services should start immediately, but you must give the Rails servers at least 30 seconds to initialize.

    启动Apache。如果没有启动,请检查你所有必要的模块(在步骤4的第一部分列出)。

    Start Apache. If it doesn't start, check to see if you included all the necessary modules (listed in first part of step 4).

    导航到本地主机:82 ,替换你的端口号为82,如果你自定义它。你应该可以看到你的网站寻找,因为它的发展做了完全一样的。

    Navigate to localhost:82, substituting your port number for 82 if you customized it. You should see your site looking exactly the same as it did in development.

    请让我知道,如果这是太长适合计算器。我刚刚花了相当多的时间解决这个问题挣扎,想通这是时候有人写了Windows上的最新指南,Rails开发(如果存在的话,我还没有看到它)。祝你好运,让我知道如果任何人有问题,或增强这一!

    Please let me know if this is too long to be appropriate for StackOverflow. I have just spent quite a lot of time struggling with this problem and figured it was high time someone wrote a up to date guide to Rails deployment on Windows (if there is one, I haven't seen it yet). Good luck, let me know if anyone has problems or enhancements for this!

    这篇关于Rails的部署环境的Windows的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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