aws v2.2.exe_如何在AWS Elastic Beanstalk上部署Rails 5.2 PostgreSQL应用

aws v2.2.exe

by Evrim Persembe

通过埃夫里姆·佩塞姆贝

如何在AWS Elastic Beanstalk上部署Rails 5.2 PostgreSQL应用 (How to deploy a Rails 5.2 PostgreSQL app on AWS Elastic Beanstalk)

It’s official, using Heroku for all my Rails projects so far has spoiled me rotten. After receiving some AWS credits thanks to a pitch competition, I decided to deploy my latest project on Elastic Beanstalk (AWS’ Heroku competitor). All I have to say is that I miss Heroku.

官方的说法 ,到目前为止,在我所有的Rails项目中使用Heroku都使我很烂。 在一次激烈的竞争中获得了一些AWS积分后,我决定在Elastic Beanstalk ( AWS的Heroku竞争对手)上部署我的最新项目。 我只想说我想念Heroku。

Alas, if you are in a similar situation, here are step-by-step instructions to deploying your Rails 5.2 / PostgreSQL app on Elastic Beanstalk.

las,如果您的情况类似,这里是在Elastic Beanstalk上部署Rails 5.2 / PostgreSQL应用程序的分步说明。

安装Elastic Beanstalk CLI (Installing the Elastic Beanstalk CLI)

We will use the terminal in this tutorial. Let’s begin with installing the “Elastic Beanstalk Command Line Interface.” Here is how to do it on macOS using Homebrew:

我们将在本教程中使用终端。 让我们从安装“ Elastic Beanstalk命令行界面”开始。 这是使用Homebrew在macOS上执行操作的方法:

brew install awsebcli

If you are using another platform, googling “how to install awsebcli on [your platform]” should lead you in the right direction.

如果您使用的是其他平台,则搜索“如何在[您的平台]上安装awsebcli”可以引导您朝正确的方向发展。

初始化Elastic Beanstalk (Initializing Elastic Beanstalk)

I will assume that you already have an Amazon Web Services account, if not go ahead and create one. Now, go into the directory of your project, and initialize Elastic Beanstalk:

我将假设您已经有一个Amazon Web Services帐户,如果没有,请继续创建一个。 现在,进入项目目录,并初始化Elastic Beanstalk:

cd my_projecteb init

Then the EB CLI will ask you a few questions to initialize the Elastic Beanstalk application. The initialization part is straightforward. If you get stuck anywhere you can check out the “Configure the EB CLI” page from the documentation.

然后,EB CLI将询问您一些问题来初始化Elastic Beanstalk应用程序。 初始化部分很简单。 如果您卡在任何地方,都可以从文档中查看“配置EB CLI”页面。

创造新环境 (Creating a new environment)

As you already know, your application can have many environments (think of them as different configurations). For example, you might have a “production” environment. This is the environment that you use for the user-facing version of your app. But you might want to have another environment named “staging.” This is where you try new versions of your app, before pushing it to the production environment.

如您所知,您的应用程序可以具有许多环境(将它们视为不同的配置)。 例如,您可能有一个“生产”环境。 这是您用于应用程序的面向用户版本的环境。 但是您可能想要另一个名为“ staging”的环境。 在将应用推送到生产环境之前,您可以在这里尝试新版本的应用。

We can create an environment using the command below:

我们可以使用以下命令创建环境:

eb create production

部署到Elastic Beanstalk (Deploying to Elastic Beanstalk)

Assuming you are using Git, commit your changes before deploying your application. The EB CLI deploys your last commit. If you deploy before committing, you will deploy an earlier version of your app.

假设您正在使用Git,请在部署应用程序之前提交更改。 EB CLI会部署您的最后一次提交。 如果在提交之前进行部署,则将部署应用程序的早期版本。

After committing your changes, deploy using the following:

提交更改后,请使用以下内容进行部署:

eb deploy

So far so good, now we need to set a few things before our app actually starts working.

到目前为止,到目前为止,我们需要在应用程序实际开始工作之前进行一些设置。

设置主密钥 (Setting up the master key)

You can use the CLI for this purpose as well, but I prefer using the web panel for this. Here is how:

您也可以为此使用CLI,但是我更喜欢使用Web面板。 方法如下:

  1. Go to AWS, choose “Services -> Elastic Beanstalk,” then click on your environment.

    转到AWS,选择“服务-> Elastic Beanstalk”,然后单击您的环境。
  2. Open the “Configuration” tab, and click “Modify” under the box titled “Software.”

    打开“配置”选项卡,然后在标题为“软件”的框下单击“修改”。
  3. Under “Environment properties,” add a new key named RAILS_MASTER_KEY. Set its value to the content of your “master.key” file. You can find this file in the “config” directory of your Rails app.

    在“环境属性”下,添加一个名为RAILS_MASTER_KEY的新密钥。 将其值设置为“ master.key”文件的内容。 您可以在Rails应用程序的“ config”目录中找到此文件。

  4. Click on the “Apply” button at the bottom of the page.

    单击页面底部的“应用”按钮。

设置PostgreSQL数据库 (Setting up a PostgreSQL database)

Elastic Beanstalk provides an easy way to set up a database, which you can reach through “Configuration -> Database.” I prefer not to use that because if you need to rebuild your Elastic Beanstalk environment, your database will be deleted. So, we will set up the database separate from our Elastic Beanstalk environment.

Elastic Beanstalk提供了一种建立数据库的简便方法,您可以通过“配置->数据库”来访问它。 我不想使用它,因为如果您需要重建Elastic Beanstalk环境,则数据库将被删除。 因此,我们将与Elastic Beanstalk环境分开设置数据库。

在RDS上创建PostgreSQL数据库 (Creating a PostgreSQL database on RDS)

  1. Go to AWS, choose “Services -> RDS.”

    转到AWS,选择“服务-> RDS”。
  2. Choose “Create database.”

    选择“创建数据库”。
  3. Choose “PostgreSQL,” and click “Next.”

    选择“ PostgreSQL”,然后单击“下一步”。
  4. Select your use case, “Production” or “Dev/Test,” and click “Next.”

    选择您的用例“生产”或“开发/测试”,然后单击“下一步”。
  5. Here, you can try different options, and see what the estimated monthly costs are. Settle with something that is within your budget. You can start with a db.t2.micro instance, no multi-AZ deployment and a general purpose SSD.

    在这里,您可以尝试其他选项,并查看估计的每月费用。 用您预算范围内的东西解决。 您可以从db.t2.micro实例开始,无需多db.t2.micro区部署和通用SSD。

  6. Choose an instance identifier, this is sort of a “namespace.”

    选择一个实例标识符,这就是一种“命名空间”。
  7. Choose a username and password, keep these handy for now, click “Next.”

    选择一个用户名和密码,暂时保留它们,单击“下一步”。
  8. On the “Configure advanced settings” section, the important thing is the security groups. Select “Choose existing VPC security groups,” and select the security group that looks like “…-AWSEBSecurityGroup-…”

    在“配置高级设置”部分,重要的是安全组。 选择“选择现有的VPC安全组”,然后选择类似于“ ...- AWSEBSecurityGroup -...”的安全组。
  9. Pick a database name, such as my_app_production.

    选择一个数据库名称,例如my_app_production

  10. Click on “Create database,” this will take a while.

    点击“创建数据库”,这将需要一段时间。

允许访问数据库 (Allowing access to the database)

In the meantime, let’s add Postgres access to your security group:

同时,让我们向您的安全组添加Postgres访问权限:

  1. Go to AWS, choose “Services -> EC2.”

    转到AWS,选择“服务-> EC2”。
  2. Click on “Security Groups” on the left panel.

    单击左侧面板上的“安全组”。
  3. Choose the security group from the previous section.

    从上一节中选择安全组。
  4. Go to the “Inbound” tab, and click on “Edit.”

    转到“入站”选项卡,然后单击“编辑”。
  5. Click on “Add Rule.” For “Type,” choose “PostgreSQL,” and for “Source” type in the ID of the security group that you are adding this rule to. It should be right above the “Inbound” tab and should look like sg-*.

    点击“添加规则”。 对于“类型”,选择“ PostgreSQL”,对于“源”,输入要添加此规则的安全组的ID。 它应该在“入站”选项卡的正上方,并且应该看起来像sg-*

  6. Click “Save.”

    点击“保存”。

设置生产数据库配置 (Setting up the production database configuration)

Now, in your Rails directory, open config/database.yml. Change it as such:

现在,在您的Rails目录中,打开config/database.yml 。 这样更改:

# ...
production:  <<: *default  database: <%= ENV['RDS_DB_NAME'] %>  username: <%= ENV['RDS_USERNAME'] %>  password: <%= ENV['RDS_PASSWORD'] %>  host: <%= ENV['RDS_HOSTNAME'] %>  port: <%= ENV['RDS_PORT'] %>

将相关环境变量添加到Elastic Beanstalk (Adding relevant environment variables to Elastic Beanstalk)

We told Rails to get the information for the production database using the above environment variables. Now we need to make sure that our Elastic Beanstalk environment includes these variables:

我们告诉Rails使用上述环境变量来获取生产数据库的信息。 现在,我们需要确保我们的Elastic Beanstalk环境包含以下变量:

  1. Go to AWS, choose “Services -> Elastic Beanstalk,” then click on your environment.

    转到AWS,选择“服务-> Elastic Beanstalk”,然后单击您的环境。
  2. Open the “Configuration” tab, and click “Modify” under the box titled “Software.”

    打开“配置”选项卡,然后在标题为“软件”的框下单击“修改”。
  3. Under “Environment properties,” add the following key-value pairs:

    在“环境属性”下,添加以下键值对:
  4. RDS_DB_NAME: Database name you picked when setting up your database.

    RDS_DB_NAME :设置数据库时选择的数据库名称。

  5. RDS_USERNAME: Username you picked when setting up your database.

    RDS_USERNAME :设置数据库时选择的用户名。

  6. RDS_PASSWORD: Password you picked when setting up your database.

    RDS_PASSWORD :设置数据库时选择的密码。

  7. RDS_HOSTNAME: Go to “Services -> RDS,” and you can find this information under the “Connect” section of your database instance information page. It is called “Endpoint.”

    RDS_HOSTNAME :转到“服务-> RDS”,您可以在数据库实例信息页面的“连接”部分下找到此信息。 它称为“端点”。

  8. RDS_PORT: Set this to 5432.

    RDS_PORT :将此设置为5432。

  9. Click on the “Apply” button at the bottom of the page.

    单击页面底部的“应用”按钮。

After this, commit your Rails app directory again, and run eb deploy. You might want to wait a few minutes before doing this because Elastic Beanstalk does some stuff in the background after updating environment variables.

之后,再次提交您的Rails应用程序目录,然后运行eb deploy 。 您可能需要等待几分钟,因为执行更新环境变量后,Elastic Beanstalk在后台执行了一些操作。

After these steps, your Rails app “should” be running.

完成这些步骤后,“应”运行Rails应用程序。

还是行不通? (Still not working?)

If there are any issues, you can go to your EB environment on the AWS web panel, click on “Logs,” and choose “Request Logs -> Last 100 Lines” to see the logs. But before doing that, I’d recommend trying to run your Rails app using the production environment on your local machine by using the command rails s RAILS_ENV=production.

如果有任何问题,您可以在AWS Web面板上转到EB环境,单击“日志”,然后选择“请求日志->最后100行”以查看日志。 但是,在此之前,我建议您尝试使用本地nd rails s RAILS_ENV=product ion在本地计算机上的生产环境中运行Rails应用程序。

I’ll be the first to admit that I’m not the most experienced person when it comes to deployment. As I said, I always used Heroku in the past, and I probably will use it for my future projects as well. These steps worked for me after a few days of scratching my head trying to set up my Rails app on Elastic Beanstalk, so I wanted to share these in hopes of saving time for people who are in the same situation I was. So, take this all with a grain of salt, and good luck!

我将是第一个承认我在部署方面不是最有经验的人。 就像我说的那样,我过去一直使用Heroku,将来我也可能会使用它。 经过几天的努力,尝试在Elastic Beanstalk上设置我的Rails应用程序之后,这些步骤对我有用。因此,我想与大家分享这些信息,以期为处于同样状况的人们节省时间。 因此,带上一粒盐和好运来带走这一切!

If you like this article, follow me on Twitter or sign up to my newsletter to get notified when I write new articles. I write about software and startups.

如果您喜欢这篇文章,请在Twitter上关注我或注册我的新闻通讯,以在我撰写新文章时得到通知。 我写有关软件和创业公司的文章。

If you are looking for a Rails developer, I’m currently available for remote work. Feel free to get in touch with me at hi{at}evrim.io.

如果您正在寻找Rails开发人员,那么我现在可以进行远程工作。 欢迎访问hi {at} evrim.io与我联系。

Originally published at evrim.io on November 28, 2018.

最初于2018年11月28日发布在evrim.io上。

翻译自: https://www.freecodecamp.org/news/how-to-deploy-a-rails-5-2-postgresql-app-on-aws-elastic-beanstalk-34e5cec3a984/

aws v2.2.exe

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/news/393127.shtml

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

学习中遇到的c++问题,持续更新

原文请訪问我的博客&#xff1a;http://xiaoshig.sinaapp.com/ 向上取整 使用ceil函数。ceil(x)返回的是大于x的最小整数。如&#xff1a; ceil(2.5) 3 ceil(-2.5) -2 sort排序头文件#include <algorithm> 数组初始化总结 整型数组初始化&#xff1a;//仅仅能赋值0…

创建邮箱过程中的问题及解决办法

转自白手起家博客 http://bbs.chinaunix.net/forum.php?modviewthread&tid770141 说明一下&#xff1a;Q代表安装过程中遇到的问题&#xff0c;或者是日志中出现的现象。A&#xff1a;代表解决方法。 Q&#xff1a; Jan 13 11:26:29 mail authdaemond: failed to connect …

php的addslashes,PHP addslashes()用法及代码示例

addslashes()函数是PHP中的内置函数&#xff0c;它返回预定义字符前带有反斜杠的字符串。该参数中不包含任何指定的字符。预定义的字符是&#xff1a;单引号(’)双引号(“)反斜杠(\)NULL注意&#xff1a;addslashes()函数不同于addcslashes()函数接受要在其之前添加斜杠的指定字…

如何在React Native中使用Redux Saga监视网络更改

by Pritish Vaidya通过Pritish Vaidya 如何在React Native中使用Redux Saga监视网络更改 (How to monitor network changes using Redux Saga in React Native) 为什么要使用Redux Saga监视网络更改&#xff1f; (Why should I use Redux Saga to monitor Network Changes?) …

leetcode214. 最短回文串(kmp)

给定一个字符串 s&#xff0c;你可以通过在字符串前面添加字符将其转换为回文串。找到并返回可以用这种方式转换的最短回文串。 示例 1: 输入: “aacecaaa” 输出: “aaacecaaa” 代码 class Solution {public int getShortestPalindrome(String s) {//求next数组的最后一…

跟我一起屏蔽百度搜索页面右侧的内容

苦恼百度搜索热点等冗杂信息很久了&#xff0c;然后今天下定决心解决这个问题了。 第一步&#xff1a;搜索&#xff0c;并安装插件Adblock Plus 第二步&#xff1a;使用拦截器 1.打开拦截器 2.具体使用 点击这一块 添加 转载于:https://www.cnblogs.com/smart-girl/p/11058774.…

JavaScript语法详解(三)

一、JavaScript循环语句 1.for循环、for/in 12345678910111213141516<!DOCTYPE html><html lang"en"> <head><meta charset"UTF-8"> <title>Title</title> </head><body><script> var array [1,2,…

鼠标拖拽吸附效果

JavaScript鼠标拖动自动吸附实例 学了几天的JavaScript&#xff0c;自己动手做了一个简单的鼠标拖动的实例&#xff0c;拖动过程中科自动检测与目标容器的距离&#xff0c;在一定的距离范围内可以自动将被拖动的元素加入到目标容器中&#xff0c;希望对开始学习javascript的童鞋…

php修改mysql数据库中的表格,如何修改mysql数据库表?

修改mysql数据库表的方法&#xff1a;使用“ALTER TABLE”语句&#xff0c;可以改变原有表的结构&#xff0c;例如增加字段或删减字段、修改原有字段数据类型、重新命名字段或表、修改表字符集等&#xff1b;语法“ALTER TABLE [修改选项]”。修改数据表的前提是数据库中已经存…

微软最新GDI漏洞MS08-052安全解决方案

微软最新GDI漏洞MS08-052安全解决方案 Simeon微软于九月九日凌晨爆出有史以来最大的安全漏洞MS08-052&#xff0c;通过该漏洞&#xff0c;攻击者可以将木马藏于图片中&#xff0c;网民无论是通过浏览器浏览、还是用各种看图软件打开、或者在即时聊天窗口、电子邮件、Office文档…

DEM轨迹后处理

方法一&#xff1a;直接在paraview中显示 首先在输出颗粒信息的时候保存global ID&#xff1a;然后在paraview中导入vtp数据&#xff08;不要导入pvd&#xff09;&#xff0c;并使用Temporal Particle To Pathlines这个filter&#xff08;可以直接ctrlspace调出搜索框搜索&…

Oracle的JDBC Url的几种方式

1.普通SID方式jdbc:oracle:thin:username/passwordx.x.x.1:1521:SID2.普通ServerName方式 jdbc:Oracle:thin:username/password//x.x.x.1:1522/ABCD3.RAC方式jdbc:oracle:thin:(DESCRIPTION(ADDRESS_LIST(ADDRESS(PROTOCOLTCP)(HOSTx.x.x.1)(PORT1521))(ADDRESS(PROTOCOLTCP)(H…

leetcode945. 使数组唯一的最小增量(排序)

给定整数数组 A&#xff0c;每次 move 操作将会选择任意 A[i]&#xff0c;并将其递增 1。 返回使 A 中的每个值都是唯一的最少操作次数。 示例 1: 输入&#xff1a;[1,2,2] 输出&#xff1a;1 解释&#xff1a;经过一次 move 操作&#xff0c;数组将变为 [1, 2, 3]。 代码 …

数据科学 python_如何使用Python为数据科学建立肌肉记忆

数据科学 pythonby Zhen Liu刘震 首先&#xff1a;数据预处理 (Up first: data preprocessing) Do you feel frustrated by breaking your data analytics flow when searching for syntax? Why do you still not remember it after looking up it for the third time?? It…

oracle 管道通信,oracle管道化表函数

转自&#xff1a;http://pengfeng.javaeye.com/blog/260360在我所做过和参与的大多数项目中,都会有用户提出的复杂的一些统计报表之内的功能要求,根据统计的复杂程度、效率及JAVA程序调用的方便性方面考虑,主要总结出以下几种方案&#xff1a; 1、SQL语句 该方案只能实现一些相…

ebtables之BROUTING和PREROUTING的redirect的区别

ebtables和iptables实用工具都使用了Netfilter框架&#xff0c;这是它们一致的一方面&#xff0c;然而对于这两者还真有一些需要联动的地方。很多人不明白ebtales的broute表的redirect和nat表PREROUTING的redirect的区别&#xff0c;其实只要记住两点即可&#xff0c;那就是对于…

LVS的四种模式的实现

LVS 是四层负载均衡&#xff0c;也就是说建立在 OSI 模型的第四层——传输层之上&#xff0c;传输层上有我们熟悉的 TCP/UDP&#xff0c;LVS 支持 TCP/UDP 的负载均衡。LVS 的转发主要通过修改 IP 地址&#xff08;NAT 模式&#xff0c;分为源地址修改 SNAT 和目标地址修改 DNA…

MyISAM与InnoDB两者之间区别与选择,详细总结,性能对比

1、MyISAM&#xff1a;默认表类型&#xff0c;它是基于传统的ISAM类型&#xff0c;ISAM是Indexed Sequential Access Method (有索引的顺序访问方法) 的缩写&#xff0c;它是存储记录和文件的标准方法。不是事务安全的&#xff0c;而且不支持外键&#xff0c;如果执行大量的sel…

leetcode557. 反转字符串中的单词 III

给定一个字符串&#xff0c;你需要反转字符串中每个单词的字符顺序&#xff0c;同时仍保留空格和单词的初始顺序。 示例&#xff1a; 输入&#xff1a;“Let’s take LeetCode contest” 输出&#xff1a;“s’teL ekat edoCteeL tsetnoc” 代码 class Solution {public St…

linux命令数据盘分多个区,pvmove命令 – 移动物理盘区

pvmove命令的作用是可以将源物理卷上的物理盘区移动到一个或多个其他的目标物理卷。使用pvmove命令时可以指定一个源日志或卷。在这种情况下&#xff0c;只有逻辑卷使用的区才会被移动到目标物理卷上的空闲或指定的区。如果没有指定的物理卷&#xff0c;则使用卷组的默认规则分…