简体   繁体   English

在EC2上部署Rails应用程序

[英]Deploy Rails Application on EC2

For the past week, I've been playing with the Rubber gem and can't seem to get it to work. 在过去的一周里,我一直在玩橡胶宝石,似乎无法让它发挥作用。 I've decided it would be easier just to manually set up my EC2 instance. 我已经决定手动设置我的EC2实例会更容易。 The problem is that I don't know how. 问题是我不知道怎么做。 Google hasn't been much help for a newb either. 谷歌也没有为新手提供太多帮助。 Any suggestions? 有什么建议? It really is appreciated. 真的很感激。

Sure. 当然。

  1. Create a AWS account. 创建AWS账户。

  2. Decided what region you want to be in. Lots of things go into this decision, but worry about it later and just do a cheap one like Oregon or East. 决定你想要进入哪个地区。很多事情都会进入这个决定,但后来又担心它,只做一个像俄勒冈州或东方那样便宜的地方。

  3. Make sure you are in the correct region at the top left. 确保您位于左上角的正确区域。

  4. Then click launch server. 然后单击启动服务器。

  5. At this point you have to pick a AMI. 此时你必须选择一个AMI。 An AMI is basically the template you want to use when you boot your server. AMI基本上是您在启动服务器时要使用的模板。 Amazon gives you some, but there are a ton in the community section. 亚马逊给你一些,但社区部分有一吨。 I am a CentOS guy so I usually search for a CentOS AMI. 我是CentOS的人,所以我经常搜索CentOS AMI。 RightScale makes some good ones so you can search for one of those. RightScale制作了一些好的,所以你可以搜索其中的一个。 Make sure you pick i386 or x64 depending on the size of server you want. 确保根据所需服务器的大小选择i386或x64。 There are two distinct types of AMI's, EBS backed and S3 backed. 有两种不同类型的AMI,EBS支持和S3支持。 Really you should stick with EBS because you have some more freedoms, but there are reasons to use both that are beyond the scope of this answer. 你真的应该坚持使用EBS,因为你有更多的自由,但是有理由同时使用两者都超出了这个答案的范围。 Look for EBS and you probably will be good. 寻找EBS,你可能会很好。 EBS is the block storage. EBS是块存储。 Basically it is attachable harddrives for your instances. 基本上它是可附加的硬盘驱动器为您的实例。 Since everything in the cloud is "virtual" and nothing is thought of in a physical sense, you have to think that way too. 由于云中的所有内容都是“虚拟的”,并且在物理意义上没有任何想法,因此您也必须这样思考。 So if you want more storage, you can attach some EBS volumes later. 因此,如果您想要更多存储空间,可以稍后附加一些EBS卷。 One thing though, S3 backed instances go bye bye when you shut them down. 但有一件事,当你关闭它时,S3支持的实例再见。 The EBS ones will too if you have the delete on termination flag set, but with EBS ones you can "Stop" them as well as "Terminate" them. 如果您设置了终止标记删除标签,那么EBS也将如此,但是对于EBS,您可以“停止”它们以及“终止”它们。

  6. Select the size and availability zone. 选择大小和可用区域。 The zone is important if you are going to be setting up some kind of redundancy. 如果您要设置某种冗余,该区域很重要。 Like if I have a master slave setup with MySQL I would put the master in one zone and the slave in another in case Amazon was having troubles that were isolated to one zone. 就像我有一个MySQL的主从设置一样,我会将主设备放在一个区域,而奴隶放在另一个区域,以防亚马逊遇到与一个区域隔离的麻烦。 But for this general purpose, don't worry about it. 但为了这个一般目的,不要担心。

  7. Advanced Instance Options. 高级实例选项。 Just leave all this alone most likely it is fine. 把这一切都留下来很可能它很好。 Some of the small things here you can set later like termination protection. 你可以在这里设置一些小东西,比如终止保护。

  8. Name it. 说出来。 Whatever. 随你。

  9. Make a SSH key. 制作SSH密钥。 Striaght forward. Striaght向前。 The only way to login to an Amazon server will be with the SSH key you assign it. 登录Amazon服务器的唯一方法是使用您分配的SSH密钥。 There are no user names or passwords. 没有用户名或密码。

  10. Security Groups. 安全组。 This is where you could get tripped up, well here and #5. 这是你可以绊倒的地方,好在这里和#5。 But you should start off with creating a general security group call foo or whatever then adding the ports you want open on it. 但是,您应该从创建一般安全组调用foo或其他任何内容开始,然后添加要在其上打开的端口。 So if you want to ssh into it, which I assume you do, then open 22. If you want to use it for web then open 80 and 8080 or whatever. 因此,如果您想要进入它,我假设您这样做,然后打开22.如果您想将它用于Web,则打开80和8080或其他任何内容。 But be careful. 不过要小心。 I usually change my SSH port later to something random. 我通常稍后将SSH端口更改为随机的。 And instead of putting 0.0.0.0/0 on it, I put my personal ip. 而不是把0.0.0.0/0放在上面,我把我的个人IP。 But if you don't care that much just put 0.0.0.0/0 and open that bad boy to the world. 但是,如果你不在乎那么多,只需要把0.0.0.0/0和那个坏孩子打开这个世界。

Then it will boot. 然后它会启动。 As long as it all went as it was supposed to. 只要这一切都按照预期进行。

Now you can login. 现在你可以登录了。 Just ssh -i thekey.pem thenwholehostname 只是ssh -i thekey.pem thenwholehostname

Hope that helps. 希望有所帮助。

There is this whole free tier you can use. 您可以使用这整个免费套餐。 http://aws.amazon.com/free/ http://aws.amazon.com/free/

Check that out. 检查出。 I would use that while you play with it. 当你玩它时我会用它。

I did all that from memory so I could have been off. 我从记忆中做了所有这些,所以我可能已经离开了。 ;) ;)

chantheman gave a great tutorial if you want to do this manually. 如果你想手动完成这个,chantheman给了一个很棒的教程。 If you are looking for alternatives, you shall consider using a third-party solution like cloud management platforms, which make the setup of an EC2 instance and the deployment of applications easier. 如果您正在寻找替代方案,您应考虑使用第三方解决方案,如云管理平台,这样可以更轻松地设置EC2实例和部署应用程序。 RightScale, which was mentioned earlier as an AMI provider in chantheman's tutorial, is one of them, but you can have a look at enStratus and Scalr as well (disclaimer: I work there). 之前作为chantheman教程中的AMI提供者提到的RightScale就是其中之一,但你也可以看看enStratus和Scalr(免责声明:我在那里工作)。 You'll need to give them your AWS credentials to allow them to make API calls on your behalf. 您需要向他们提供您的AWS凭据,以允许他们代表您进行API调用。

Cloud management softwares will provide some pre-configured AMIs (at Scalr, we call them roles) and offer an application deployment framework (we wrote a blogpost about this http://scalr.net/blog/announcements/deployments/ ). 云管理软件将提供一些预先配置的AMI(在Scalr,我们称之为角色)并提供应用程序部署框架(我们写了一篇关于此http://scalr.net/blog/announcements/deployments/的博客文章)。 You will thus perform step 2-10 more quickly. 因此,您将更快地执行步骤2-10。

If you are tight on budget, RightScale and enStratus have a free account whereas Scalr is open-source and available under the Apache 2 license. 如果您的预算紧张,RightScale和enStratus都有一个免费帐户,而Scalr是开源的,可以在Apache 2许可下使用。

You should also check out Ubuntu Juju deployment options. 您还应该查看Ubuntu Juju部署选项。

Configuring for Amazon Web Services 配置Amazon Web Services

https://juju.ubuntu.com/docs/getting-started.html https://juju.ubuntu.com/docs/getting-started.html

Using Juju to Deploy your Rails Application 使用Juju部署您的Rails应用程序

https://juju.ubuntu.com/docs/howto-rails.html https://juju.ubuntu.com/docs/howto-rails.html

Basic Usage of the Ruby on Rails Charm Ruby on Rails魅力的基本用法

Create a YAML config file with your application's name and its git location 使用应用程序的名称及其git位置创建YAML配置文件

sample-app.yaml

sample-app:
  repo: https://github.com/pavelpachkovskij/sample-rails

Deploy the application and a proxy: 部署应用程序和代理:

juju deploy --config sample-app.yaml rails myapp
juju deploy haproxy
juju add-relation haproxy myapp

Deploy and relate database: 部署和关联数据库:

juju deploy postgresql
juju add-relation postgresql:db myapp

Now you can run migrations: 现在您可以运行迁移:

juju ssh myapp/0 run rake db:migrate
Seed database

juju ssh myapp/0 run rake db:seed

And finally expose the proxy: 最后公开代理:

juju expose haproxy
Find the instance's public URL from

juju status haproxy

Scale horizontally by adding and removing units: 通过添加和删除单位水平缩放:

juju add-unit myapp
juju remove-unit myapp

Or go even larger with juju add-unit -n10 myapp for 10 nodes. 或者使用juju add-unit -n10 myapp进行更大的节点。

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

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