3.1的Rails应用程序部署教程 [英] Rails 3.1 application deployment tutorial

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

问题描述

我在寻找一个服务器上的一个Rails 3.1.1应用程序调配好教程。和好,我实际上意味着完成。我张贴这个问题的原因是,虽然有教程吨那里的网络上(谷歌,博客,电子书,计算器等问题,等...)所有的人似乎要么集中在与部署过程中的问题或作出有关部署环境,不符合我的需要搭配一些假设。

I'm looking for a good deployment tutorial for a Rails 3.1.1 application on a server. And by good I actually mean complete. The reason I'm posting this question is that although there are tons of tutorials out there on the web (google, blogs, books, other stackoverflow questions etc...) all of them seem to focus either on a problem with the deployment process or make some assumptions about the deployment environment that do not match with what I need.

我认识到一个服务器上部署一个Rails应用程序requieres各种不同的程序和需要配置工具的,不知怎么我总是停留在表面上的小事情,让我很沮丧。

I realize that deploying a Rails app on a server requieres a variety of different programs and tools that need to be configured and somehow I always get stuck on apparently "little" things that make me very frustrated.

那么,让我们从一开始就开始。我现在是,我可以通过SSH和域名访问,我们称之为 www.example.com的服务器。服务器运行一个新鲜的Ubuntu 10.04 x64和刚刚安装了一个用户,即根(通过我的根访问与SSH服务器)。
注意!没有了Apache,红宝石,PHP,MySQL和的cPanel或安装任何其他面板,只需最低限度自带的全新安装。

So, let's begin from the start. What I have now is a server that I can access through SSH and a domain name, let's call it www.example.com. The server runs a fresh Ubuntu 10.04 x64 and has just a user installed, namely root (through root I access the server with SSH). Note! There is no Apache, Ruby, PHP, MySQL, cPanel or any other panel installed, just the bare minimum that comes with a fresh installation.

另外,Web服务器将举办一个单一的应用程序和数据库将在同一台计算机上运行。

Also the web server will host a single application and the database will run on the same machine.

这是我的知识部署Rails应用程序的过程中遵循以下方案:

From my knowledge the process of deploying a Rails application follows the following scenarios:


  • 安装Ruby

  • Installing Ruby

我已经用RVM使用多用户安装过程中这样做(只是因为我刚才的root用户,它会自动执行的话)。这似乎罚款aftewards工作,但我确实有一些问题:

I already did this by using RVM using the Multi-User install process (simply because I have just the root user and it does it automatically). This seems to work fine aftewards but I do have some questions:

会更有意义,直接而不是通过RVM安装Ruby(我想,也许在效率方面 - 也确实RVM的scences修改的方式,我有些不明白的.bash_profile文件魔术背后的一点点而这在某种程度上似乎微创...)?

Would it make more sense to install Ruby directly and not through RVM (I'm thinking maybe in terms of efficiency - also RVM does a little bit of magic behind the scences modifying some bash_profile files in ways that I don't understand and this somehow seems invasive...)?

会更有意义,通过RVM安装作为一个单独的用户(可以有出现的任何安全问题)?

Would it make more sense to install as a separate user through RVM (can there any safety problems arise)?


  • 必要的宝石

  • Necessary gems

现在的红宝石安装了什么是最好的初始设置的宝石沿端安装呢?

Now that Ruby is installed what would be the best initial set of gems to install along side it?

我刚装打捆,这样一旦我上传我的应用程序在服务器上,我可以运行捆绑安装的命令将依次安装所需的应用程序的宝石。

I installed just bundler, so that once I upload my application on the server I can run a bundle install command which will install in turn the required app gems.

问题 - 我应该手之前安装导轨宝石?有没有需要安装的任何其他宝石?

Question - Should I install the rails gem before hand? Are there any other gems that need to be installed?


  • Web服务器

  • Web server

这是在那里我得到棘手。我试图使用Apache和MOD乘客进行部署(他们似乎是最流行的)。所以我安装Apache Web服务器和乘客宝石和所有相关的依赖关系(库客运提及)。

This is where it gets tricky for me. I'm trying to use apache and mod-passenger for deployment (they seem to be the most popular). So I installed the apache web server and the passenger gem and all the related dependencies (libraries mentioned by passenger).

现在的问题就出来了。第一件事是与用户有关。如何运行Apache?我的意思是每一个用户下?如果我安装了它,(重新)使用root用户启动它,将它永久root用户下运行?这是一件坏事?如果是的话,我应该创建另一个用户?如果是的话,怎么样?在什么组,我应该把新的用户,他应该有什么样的权利(即他应该有什么样的文件夹访问权限)。如何在这种情况下,启动Apache(在根,该用户下,某处添加一行在配置文件中,等等。)

Now, the problems arise. First thing is user related. How does Apache run? I mean under each user? If I installed it and (re)started it using the root user, will it permanently run under the root user? Is this a bad thing? If yes, should I create another user? If yes, how? In what groups should I put the new user in, what rights should he have (namely what folders should he have access to). How to start the apache in this case (under root, under that user, add a line somewhere in the configuration file, etc.)


  • 网站配置

  • Website configuration

如果把网站配置的东西?是否确定将其投入的apache.conf,或者我应该创建的网站,提供一个新的文件?或者我应该只是重用的默认的文件已经是present呢?如果新用户已经在previous一步被创建,什么样的权利,他应该相对于配置文件有哪些?

Where to put the website configuration stuff? Is it OK to put it into apache.conf, or should I create a new file in sites-available? Or should I simply reuse the default file that is already present there? If a new user has been created at the previous step, what rights should he have in relation to the config files?

另外...其中,最终把Rails应用程序?在哪个文件夹会是最好的?在某处回家?也许在/ var / WWW?我想知道这将如何影响服务的应用程序的Apache进程的权利? (一般来说,我有问题,而服务的应用程序,它抱怨说,它不会对特定的文件夹权限此外,使用新的资产管道 - 我不完全理解 - 正在创建资源文件,他们似乎不继承父文件夹权限...)

Also... where to eventually put the rails application? In what folder would it be best? Somewhere under home? Maybe under /var/www? I want to know how would this affect the rights of the apache process serving the app? (Generally I have problems while serving an app, it complains that it doesn't have rights on a specific folder. Also, using the new asset pipelines - which I don't fully understand - asset files are being created and they seem not to inherit the parent folder rights...)


  • 数据库

  • Database

由于数据库我使用​​MySQL和安装它是pretty简单。我有这方面的问题又是与用户有关。我应该使用数据库的特殊用户?如何MySQL的实际管理用户(他们是内部的,或者是他们的Linux用户还是...?)。应的数据库用户是相同的,从上面的网络用户?或者,它应该是一个不同的?

As database I'm using MySQL and installing it is pretty straightforward. The question that I have here is again user related. Should I use a special user for the database? How does MySQL actually manage users (are they internal, or are they the Linux users or ...?). Should the database user be the same as the "web user" from above? Or should it be a different one?


  • 资产

  • Assets

在这里,我得到真正丢失。我真的有麻烦使得资产管道工程。我检查他的Railscasts插曲,也是轨网站的教程,我似乎从理论上理解的事情,但我现在已经在实践中的问题。

Here I get really lost. I really have troubles making the assets pipeline works. I've checked the railscasts episode and also the rails website tutorial and I do seem to theoretically understand the thing, yet I have problems in practice.

所以这里的问题是 - 什么命令,我应该跑precompile资产? (试图运行耙资产:precompile)。它是确定?我应该在production.rb文件改变?如何产生的资产工作在上面创建的WEBUSER或数据库用户的关系?我个人得到一个问题,这一步即日志文件说,有些CSS文件无法访问(例如我有供应商/资产文件夹下安装jqplot库及其文件不能被访问 - 我应该在这里添加一个清单文件不知何故?)。

So the questions here would be - what commands should I run to precompile the assets? (Trying to run rake assets:precompile). Is it ok? What should I change in the production.rb file? How do the assets generated work in relation with the webuser or database users created above? I am personally getting a problem in this step namely the log files say that some css files are not accessible (for example I have jqplot library installed under the vendor/assets folder and its files cannot be accessed - should I add a manifest file here somehow?).

这将是真正伟大的,如果有人可以点我朝着好的文章或资源,解释这一切的东西。其中我有在问题的主要方面是如何的Apache,客运,红宝石,Rails和MySQL的使用Linux的用户交互。如何正确地设置了Rails应用程序文件夹的权限?如何在资产管道影响此用户权限的东西?

It would be really great if someone could point me towards a nice article, or resource that explains all this stuff. The main area which I'm having problems in is how does Apache, Passenger, Ruby, Rails and MySQL interact with a Linux user. How to properly set up the permissions for the Rails app folder? How does the assets pipeline affect this user permission stuff?

感谢您

推荐答案

下面是我的Rails部署方式:

Here's my way of deploying Rails:


  • 安装Ruby

  • Installing Ruby

,因为它是非常棘手得到它结合像cron作业的东西正常运行,我不会用RVM。可行的(带包装为例),但有点麻烦。如果不需要该计算机上的其他Ruby版本,只是从源代码自行安装。

I would not use RVM because it's very tricky to get it running properly in combination with stuff like cron jobs. Doable (with wrappers for example), but a bit of a hassle. If you don't need other Ruby versions on that machine, just install it from source yourself.


  • 宝石

  • Gems

只是让捆扎机工作,它的魔力。记得用标志安装 - 没有测试开发--deployment 。我不会做,前面虽然。只要确保你有打捆。

Just let Bundler work its magic. Remember to install with the flags --without test development --deployment. I wouldn't do that up front though. Just make sure you have bundler.


  • Web服务器

  • Web server

使用客运(与Apache或Nginx的)是一个很好的和容易的选择。当您从易安装Apache,它会在一个特殊的用户运行。

Using Passenger (with either Apache or Nginx) is a fine and easy choice. When you install Apache from apt, it will run in a special user.

Apache是​​Ubuntu的正确自动配置。这将开始重启。

Apache is configured correctly automatically on Ubuntu. It will start on reboot.


  • 网站配置

  • Website configuration

所有的配置在/ etc / apache2的。将在/ etc / apache2的/你的虚拟主机配置站点可用,并使用 a2ensite 来启用它。

All configuration be in /etc/apache2. Place your virtual host configuration in /etc/apache2/sites-available and use a2ensite to enable it.

把你的应用程序中的 /无功/网络,因为这是在Ubuntu的默认位置。我通常做一个部署的用户。

Put your app in /var/www, since that is the default location in Ubuntu. I usually make a deploy user.

请确保用户可以通过将您的应用程序的 www数据组访问应用程序。

Make sure that user can access your application by assigning your app to the www-data group.


  • 数据库

  • Database

MySQL有其自己的用户的系统。以root身份登录的用户,并创建SQL新用户: GRANT ALL ONapplication_production'* TO'部署'IDENTIFIED BY'某些密码';

MySQL has its own user system. Log in as root user and create a new user with SQL: GRANT ALL ON 'application_production'.* TO 'deploy' IDENTIFIED BY 'some password';


  • 资产

  • Assets

资产应作为用户拥有的应用程序产生。你应该添加任何CSS和JavaScript文件production.rb。例如:

Assets should be generated as the user owning the application. You should add any css and javascript files to production.rb. For example:

config.assets.precompile += %w(backend.css)


  • 结论

    • Conclusion
    • 它有助于使用像 Capistrano的一个部署工具。当您运行 capify ,取消在 Capfile 适当的行来获得资产编译。这里是我的:

      It helps to use a deploy tool like Capistrano. When you run capify, uncomment the appropriate line in the Capfile to get assets compilation. Here's mine:

      ENV['RAILS_ENV'] = 'production'
      load 'deploy' if respond_to?(:namespace) # cap2 differentiator
      load 'deploy/assets'
      load 'config/deploy'
      require 'capistrano/ext/multistage'
      require "bundler/capistrano"
      require 'capistrano_colors'
      

      这是多么我通常安装我的Rails应用。我希望这将让你去。最近我写了整合厨师与Capistrano的-solo,叫的capistrano-chef-solo 。这是非常α,可能会有点太复杂,如果你只是部署出发,但它可能会帮助你。

      This is just how I normally install my rails apps. I hope this will get you going. Recently I've written a gem for integrating Chef-solo with Capistrano, called capistrano-chef-solo. It's very alpha and might be a bit too complicated if you're just starting with deployment, but it might help you.

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

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