博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
node aws 内存溢出_如何将Node.js应用程序部署到AWS Elastic Beanstalk
阅读量:2523 次
发布时间:2019-05-11

本文共 11581 字,大约阅读时间需要 38 分钟。

node aws 内存溢出

It took me the better part of a month to figure out how to setup an Amazon Web Services (AWS) account, configure a Node.js app for deploying, and then actually deploy it.

我花了一个月的大部分时间来弄清楚如何设置一个Amazon Web Services(AWS)帐户,配置要部署的Node.js应用程序,然后进行实际部署。

A lot of that was trying to decipher Amazon’s documentation. Hopefully this guide will get you on the road to deploying from local to live without too much of a headache.

其中很多是试图破译亚马逊的文档。 希望本指南能帮助您从本地部署到生活,而不会太头疼。

I am located in Los Angeles, so when you’re setting up your configuration the defaults may not be exactly the same.

我位于洛杉矶,因此在设置配置时,默认值可能并不完全相同。

先决条件 (Prerequisites)

  1. Basic command line knowledge

    基本命令行知识

    I’m sure you can do this without the command line, but it’s way easier to use the CLI

    我确定您可以在不使用命令行的情况下执行此操作,但是使用CLI会更容易

  2. An AWS account

    一个AWS账户
  3. The Elastic Beanstalk Command Line Interface (EB CLI)

    Elastic Beanstalk命令行界面(EB CLI)

    Instructions on installation below

    下面的安装说明

  4. Basic knowledge of Git

    Git基础知识

设置一个AWS账户 (Setting up an AWS Account)

The first thing you have to do is setup an AWS account. If you already have an account, make sure you have an IAM user that has API keys and the appropriate access.

您要做的第一件事是设置一个AWS账户。 如果您已经有一个帐户,请确保您拥有一个具有API密钥和适当访问权限的IAM用户。

创建一个帐户 (Create an Account)

Pretty straightforward. Create an account. The signup process should walk you through everything pretty easily. When you first setup an AWS account, you’ll get root access. However, it’s security best practices to create a separate user that you will use to login regularly.

非常简单。 创建一个帐户。 注册过程将使您轻松完成所有操作。 首次设置AWS帐户时,您将获得root访问权限。 但是,安全性最佳做法是创建一个将用于定期登录的单独用户。

设置您的IAM (Setup your IAM)

NOTE: I am not an expert with AWS Identity and Access Management (IAM). The actions I took were for my own personal use case and may not be suitable for your needs. Review the permissions thoroughly before giving users access.

注意:我不是AWS Identity and Access Management(IAM)的专家。 我采取的措施仅适用于我自己的个人用例,可能不适合您的需求。 在授予用户访问权限之前,请彻底检查权限。

AWS publishes best practices regularly, get one from 2016 .

AWS定期发布最佳实践,请从获得2016年的最佳实践。

设置一个小组 (Setup a group)

Before you setup a user for you to login with, create a group that will manage permissions. In my case I setup a SuperAdmin group that I was going to put myself into so I could have access to everything.

在设置用于登录的用户之前,请创建一个将管理权限的组。 在我的情况下,我建立了一个SuperAdmin组,该组将使我自己进入,以便可以访问所有内容。

For this group, since it’s basically to login and have access to everything myself, I chose AdministratorAccess as the permission.

对于该组,由于基本上是要登录并可以自己访问所有内容,因此我选择AdministratorAccess作为权限。

For more info on IAM Groups, go .

有关IAM组的更多信息,请转到 。

设置IAM用户 (Setup an IAM User)

Setting up a user is pretty simple, but if you get stuck, checkout the for AWS. They have a lot of useful videos.

设置用户非常简单,但是如果遇到麻烦,请签出AWS的 。 他们有很多有用的视频。

Just remember to:

请记住:

  1. Give them access key permissions

    授予他们访问密钥权限

    (see picture below)

    (见下图)

  2. Assign them to the appropriate IAM group

    将它们分配给适当的IAM组

Once you’ve got your own user setup, log out of the root and log back in as your new IAM user.

设置好自己的用户后,请退出root用户,然后以新的IAM用户身份重新登录。

设置本地环境 (Setting up the Local Environment)

Now that we have our account keys ready, let’s get started with the deployment.

现在我们已经准备好了帐户密钥,让我们开始进行部署。

什么是Elastic Beanstalk? (What is Elastic Beanstalk?)

Elastic Beanstalk (EB) is a fairly straightforward way of setting up scalable applications. It uses Amazon Elastic Compute Cloud (EC2) instances, Amazon Simple Storage Service (S3) buckets, and load balancers to manage your application architecture for you.

Elastic Beanstalk(EB)是设置可伸缩应用程序的一种非常简单的方法。 它使用Amazon Elastic Compute Cloud(EC2)实例,Amazon Simple Storage Service(S3)存储桶和负载均衡器为您管理应用程序架构。

If you need to scale up quickly because of network demand, it’ll do so. It’s also really amazing at pushing updates because it can do “rolling updates”, which allow the application to stay online while you update. Neat.

如果您由于网络需求而需要Swift扩大规模,则可以这样做。 推送更新也真的很棒,因为它可以执行“滚动更新”,这使应用程序在更新时保持在线状态。 整齐。

如何避免Elastic Beanstalk花费您一吨钱 (How to keep Elastic Beanstalk from costing you a ton)

This only applies to new users that still qualify for the free plan:

这仅适用于仍符合免费计划资格的新用户:

  1. You get 750 hours of t2.micro EC2 time per month. This will give you enough to run a single server full time.

    您每月可获得750小时的t2.micro EC2时间。 这将使您有足够的时间全职运行单个服务器。

    However, if you add one more sever, you're gonna pay for it.

    但是,如果再添​​加一台服务器,则需要付费。

  2. You could switch over all your server logic to Lambda functions, but that is a topic for another day (and also there are a few drawback)s.

    您可以将所有服务器逻辑切换到Lambda函数,但这是另一天的话题(并且还有一些缺点)。

    If you’re interested, check out this

    如果您有兴趣,请查看此

    .

不过要花多少钱? (How much is going to cost though?)

Good question. Here’s a sample of my bill. This is with the Node.js application running that I’m writing this article about (EB, Cloudfront, S3 Buckets).

好问题。 这是我账单的一个例子。 这是与我正在撰写有关(EB,Cloudfront,S3 Buckets)的本文的Node.js应用程序一起运行的。

If you’re wondering how much it will cost after the free plan is up, check .

如果你想知道有多少后的免费计划了它的成本,检查 。

在您的应用程序中创建EB环境 (Creating an EB Environment within your application)

This is not a Node.js tutorial, as that is outside the scope of this article. But if you need an application to screw around with, check out the . It’ll give you a “Hello World,” at least. It’s what I used as the init for my project.

这不是Node.js教程,因为这不在本文讨论范围之内。 但是,如果您需要一个应用程序来解决问题,请查看 。 至少会给您一个“ Hello World”。 这就是我用作项目init的内容。

Moving forward, it’s assumed you already have a Node.js application that runs locally without issue.

继续前进,假设您已经有一个Node.js应用程序,可以在本地运行而不会出现问题。

设置EB CLI (Setting up the EB CLI)

First thing is to get the AWS/EB CLI running, which just consists of installing a couple of tools and setting up the configuration.

首先是要运行AWS / EB CLI,该过程仅包括安装几个工具并设置配置。

The AWS docs do a better job of explaining it than I ever could, so check them out .

AWS文档在解释方面做得比以往任何时候都更好,因此请在 。

Note: If you ever have issues with the API Keys, you can verify/change them by editing the config file.

注意:如果API密钥有问题,可以通过编辑配置文件来验证/更改它们。

open ~/.aws/config

初始部署 (Initial deployment)

Now we’ve got all our tools in line, what next?

现在我们有了所有工具,接下来该怎么办?

eb init

When you run this command it’s going to ask you a ton of questions:

当您运行此命令时,它将问您很多问题:

  1. You’ll be asked to choose a region.

    系统会要求您选择一个地区。

    Default is us-west-2 : US West (Oregon)

    默认值为us-west-2:美国西部(俄勒冈州)

  2. It’ll ask you which application to use or create a new one.

    它将询问您要使用哪个应用程序或创建一个新应用程序。

    The first option should be to create a new one.

    第一个选择应该是创建一个新的。

  3. It’ll ask you if you want to use AWS CodeCommit.

    它将询问您是否要使用AWS CodeCommit。

    I have no experience with this, but I am just using GitHub, so I said no.

    我对此没有经验,但是我只是在使用GitHub,所以我说不。

设置环境变量 (Setup your Env variables)

This was probably my biggest pain point. I don’t know if my brain glazed over the documentation, or what. Once I figure it out though, it’s actually really simple. And the config files are written in YAML ❤️.

这可能是我最大的痛点。 我不知道我的大脑是否对文档感到困惑,还是什么。 一旦我弄清楚了,它实际上真的很简单。 配置文件用YAML❤️编写。

When you eb init , it will create a folder .elasticbeanstalk in your root directory. You don’t really have to mess with anything in here, as it should be setup automatically when you run the command the first time.

eb init ,它将在根目录中创建一个文件夹.elasticbeanstalk 。 您实际上并不需要弄乱这里的任何内容,因为在您第一次运行命令时应自动将其设置。

However, in order to have your environment variables, and any other configuration you need to be run at start time, create a new folder: .ebextensions

但是,为了拥有环境变量以及您需要在启动时运行的其他配置,请创建一个新文件夹: .ebextensions

The folder structure should look something like this:

文件夹结构应如下所示:

- .ebextensions-- 01_yourconfig.config- .elasticbeanstalk-- config.yml

The config files are written in YAML, as mentioned earlier. To give you an idea of what they should look like, here are a few samples:

如前所述,配置文件使用YAML编写。 为了让您大致了解它们的外观,以下是一些示例:

Environment variables file:

环境变量文件:

# 01_envar.configoption_settings:  aws:elasticbeanstalk:application:environment:    PORT: 8081    NODE_ENV: production

A file for configuring Node.js:You don’t really have to specify the NodeVersion because it will give you the latest one it can on the EC2 instances. But it’s here just in case.

用于配置Node.js的文件:您实际上不必指定NodeVersion因为它将为您提供EC2实例上可以提供的最新版本。 但这是为了以防万一。

# 02_nodecommand.configoption_settings:  aws:elasticbeanstalk:container:nodejs:    NodeCommand: "npm run start"    NodeVersion: 8.8.1

This is the easiest way for me to manage the config settings, but they can be adjusted in the EB dashboard under configuration.

这是我管理配置设置的最简单方法,但是可以在配置下的EB仪表板中对其进行调整。

If you want to know more, is an amazing article about just that topic.

如果您想了解更多, 是一篇关于该主题的精彩文章。

创建环境 (Create an environment)

eb create 

then deploy

然后部署

eb deploy

Assuming all went well, your app is now deployed to the “cloud.”

假设一切顺利,您的应用程序现在已部署到“云”中。

Check it out with eb open

eb open检查一下

部署变更 (Deploying changes)

Once you get everything setup, pushing changes is super easy.

一旦完成所有设置,推动更改就变得非常容易。

NOTE: Changes must be committed to Git before pushing to the environment.

注意:在推送到环境之前,必须对Git进行更改。

I didn’t realize that the first time, and it took me forever to figure out. Don’t make the same mistake — commit those changes!

我第一次没有意识到这一点,这使我花了很长时间才弄清楚。 不要犯同样的错误-进行更改!

So, once you committed the changes, simply type in the command below and wait for it to run its course.

因此,一旦提交了更改,只需在下面键入命令并等待其运行即可。

eb deploy 

其他方便的EBCLI命令 (Other handy EBCLI commands)

To open up the instance within the terminal, which is considerably easier than trying to remember the dictionary of a URL that AWS gives you at first:

要在终端中打开实例,这比尝试记住AWS首先提供给您的URL字典要容易得多:

eb open

To open the console:

要打开控制台:

eb console

To get log files straight to your terminal:

要将日志文件直接发送到终端:

eb logs

下一步是什么? (What’s Next?)

自定义域名 (Custom domain name)

If you run eb open you will notice that the URL is a crazy long URL. If you want to, you can hook it up to your domain using Route 53. For the most part that is all standard DNS record stuff. You can leave the DNS management wherever you registered your domain, but I just find it easier to have it all in once place.

如果运行eb open您会注意到该URL是一个疯狂的长URL。 如果愿意,可以使用Route 53将其连接到您的域。在大多数情况下,所有标准DNS记录都是如此。 您可以在注册域名的任何地方都离开DNS管理,但我发现一次性将其全部存储起来更容易。

SSL证书 (SSL Cert)

Getting a SSL cert for your instance is pretty easy too. Visit the certificate manager and create a new certificate for your domain. This is a simple process, too.

为您的实例获取SSL证书也非常容易。 访问证书管理器并为您的域创建一个新证书。 这也是一个简单的过程。

Note: If you plan on using an SSL cert for Cloudfront, you have to initiate the process from the N. Virginia zone. You can change your zone at the top right of the screen.

注意:如果计划对Cloudfront使用SSL证书,则必须从N. Virginia区域启动该过程。 您可以在屏幕的右上方更改区域。

Once it’s verified and ready to use, throw it in your EB config. The easiest way is to go to the console and select it.

验证并准备使用后,将其放入您的EB配置中。 最简单的方法是转到控制台并选择它。

  1. Go to your EB dashboard

    转到您的EB仪表板
  2. Choose your application

    选择你的应用
  3. Choose your environment

    选择你的环境
  4. Click on “configuration” and choose the SSL certificate.

    单击“配置”,然后选择SSL证书。

Another Note: Sometimes you might have issues with the certificate manager if you have a brand new account. If it tells you to contact customer support when you try to create a certificate, do that and they’ll fix it.

另一个注意事项:有时,如果您拥有全新的帐户,则证书管理器可能会出现问题。 如果在您尝试创建证书时告诉您与客户支持联系,请执行此操作,他们将对其进行修复。

结论 (Conclusion)

Wow. What a ride. Hopefully you were successful and didn’t have to run to the AWS docs too many times. But, if I’m being honest with myself, I’m sure you had to at least once. AWS is a monstrous service and it only grows larger by the day.

哇。 太好了。 希望您成功了,并且不必运行过多次AWS文档。 但是,如果我对自己说实话,我敢肯定您至少必须这样做一次。 AWS是一项了不起的服务,并且每天都在增长。

翻译自:

node aws 内存溢出

转载地址:http://ejwzd.baihongyu.com/

你可能感兴趣的文章
3、VS2010+ASP.NET MVC4+EF4+JqueryEasyUI+Oracle项目开发之——用户登录
查看>>
面试记-(1)
查看>>
压力测试 相关
查看>>
android update automatically ( android 自动升级)
查看>>
session cookie
查看>>
POJ 1222 EXTENDED LIGHTS OUT(翻转+二维开关问题)
查看>>
【BZOJ-4059】Non-boring sequences 线段树 + 扫描线 (正解暴力)
查看>>
几种简单的负载均衡算法及其Java代码实现
查看>>
TMS3705A PCF7991AT 线路图
查看>>
白盒测试实践(小组作业)day4
查看>>
为什么学sail.js
查看>>
pythen创建cocos2dx项目
查看>>
js调用.net后台事件,和后台调用前台等方法总结
查看>>
Vert.x 之 HelloWorld
查看>>
太阳能路灯项目背景知识
查看>>
Objec类和final关键字的用法
查看>>
打开matlab遗传算法工具箱的方法
查看>>
Ajax制作智能提示搜索
查看>>
打赏页面
查看>>
JAVA之线程同步的三种方法
查看>>