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.pswp.cn/news/393127.shtml
繁體地址,請注明出處:http://hk.pswp.cn/news/393127.shtml
英文地址,請注明出處:http://en.pswp.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;則使用卷組的默認規則分…