简体   繁体   English

如何在多个实例Amazon EC2 Autocaling组上部署代码?

[英]how to deploy code on multiple instances Amazon EC2 Autocaling group?

So we are launching an ecommerce store built on magento. 因此,我们正在建立一个基于magento的电子商务商店。 We are looking to deploy it on Amazon EC2 instance using RDS as database service and using amazon auto-scaling and elastic load balancer to scale the application when needed. 我们希望使用RDS作为数据库服务,并在需要时使用Amazon自动缩放和弹性负载平衡器来将其部署在Amazon EC2实例上。

What I don't understand is this: I have installed and configured my production magento enviorment on an EC2 instance (database is in RDS). 我不明白的是:我已经在EC2实例(数据库位于RDS中)上安装并配置了生产magento环境。 This much is working fine. 这样很好。 But now when I want to dynamically scale the number of instances 但是现在当我想动态扩展实例数时

  • how will I deploy the code on the dynamically generated instances each time? 每次如何在动态生成的实例上部署代码?
  • Will aws copy the whole instance assign it a new ip and spawn it as a new instance or will I have to write some code to automate this process? 将aws复制整个实例,为它分配一个新的ip,并将其作为新实例生成,还是我必须编写一些代码来自动化该过程?
  • Plus will it not be an overhead to pull code from git and deploy every time a new instance is spawned? 加上每次生成新实例时从git中提取代码并进行部署都不会产生开销吗?

A detailed explanation or direction towards some resources on the topic will be greatly appreciated. 对于该主题的一些资源的详细解释或方向将不胜感激。

You do this in the AutoScalingGroup Launch Configuration. 您可以在AutoScalingGroup启动配置中执行此操作。 There is a UserData section in the LaunchConfiguration in CloudFormation where you would write a script that is ran when ever the ASG scales up and deploys a new instance. CloudFormation中的LaunchConfiguration中有一个UserData部分,您可以在其中编写一个脚本,该脚本在ASG扩大规模并部署新实例时运行。

https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-properties-as-launchconfig.html#cfn-as-launchconfig-userdata https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-properties-as-launchconfig.html#cfn-as-launchconfig-userdata

This is the same as the UserData section in an EC2 Instance. 这与EC2实例中的UserData部分相同。 You can use LifeCycle hooks that will tell the ASG not to put the EC2 instance into load until everything you want to have configured it set up. 您可以使用LifeCycle挂钩,该挂钩将告诉ASG在您要配置的所有内容都设置好之前不要将EC2实例加载。

https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-as-lifecyclehook.html https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-as-lifecyclehook.html

I linked all CloudFormation pages, but you may be using some other CI/CD tool for deploying your infrastructure, but hopefully that gets you started. 我链接了所有CloudFormation页面,但是您可能正在使用其他CI / CD工具来部署基础架构,但是希望可以帮助您入门。

To start, do check AWS CloudFormation . 首先,请检查AWS CloudFormation You will be creating templates to design how the infrastructure of your application works ~ infrastructure as code. 您将创建模板来设计应用程序的基础结构的工作方式〜基础结构作为代码。 With these templates in place, you can rollout an update to your infrastructure by pushing changes to your templates and/or to your application code. 有了这些模板后,您可以通过推送对模板和/或应用程序代码的更改来向基础结构推出更新。

In my current project, we have a github repository dedicated for these infrastructure templates and a separate repository for our application code. 在我当前的项目中,我们有一个专用于这些基础结构模板的github存储库,以及一个用于我们的应用程序代码的单独存储库。 Create a pipeline for creating AWS resources that would rollout an updated to AWS every time you push to the repository on a specific branch. 创建用于创建AWS资源的管道,该管道将在您每次推送到特定分支上的存储库时将更新发布到AWS。

  • Create an infrastructure pipeline 创建基础架构管道
  • have your first stage of the pipeline to trigger build whenever there's code changes to your infrastructure templates. 每当基础结构模板的代码发生更改时,您就可以在管道的第一阶段触发构建。 See AWS CodePipeline and also see AWS CodeBuild . 请参阅AWS CodePipeline ,也请参阅AWS CodeBuild These aren't the only AWS resources you'll be needing but those are probably the main ones, of course aside from this being done in cloudformation template as mentioned earlier. 这些不是您唯一需要的AWS资源,但它们可能是主要的资源,当然,除了前面提到的在cloudformation模板中完成的工作之外。

how will I deploy the code on the dynamically generated instances each time? 每次如何在动态生成的实例上部署代码?

  • Check how containers work, it would be better and will greatly supplement on your learning on how launching new version of application work. 检查containers工作方式,这样会更好,并且将大大补充您对启动新版本应用程序的工作方式的学习。 To begin, see docker , but feel free to check any resources at your disposal 首先,请参阅docker ,但请随时检查可用的任何资源
  • Continuation with my current project: We do have a separate pipeline dedicated for our application, but will also get triggered after our infrastructure pipeline update. 继续我当前的项目:我们确实有一个专用于我们应用程序的单独管道,但也会在我们的基础结构管道更新后触发。 Our application pipeline is designed to build a new version of our application via AWS Codebuild, this will create an image that will become a container ~ from the docker documentation. 我们的应用程序管道旨在通过AWS Codebuild构建应用程序的新版本,这将创建一个image ,该image将成为docker文档中的一个容器。
  • we have two triggers or two sources that will trigger an update rollout to our application pipeline, one is when there's changes to infrastructure pipeline and it successfully built and second when there's code changes on our github repository connected via AWS CodeBuild. 我们有两个触发器或两个源将触发对应用程序管道的更新部署,一个是对基础结构管道的更改成功建立,第二个是通过AWS CodeBuild连接的github存储库上的代码更改时。
  • Check AWS AutoScaling , this areas covers the dynamic launching of new instances, shutting down instances when needed, replacing unhealthy instances when needed. 选中AWS AutoScaling ,该区域涵盖了新实例的动态启动,在需要时关闭实例,在需要时替换不正常的实例。 See also AWS CloudWatch , you can design criteria with it to trigger scaling down/up and/or in/out. 另请参阅AWS CloudWatch ,您可以使用它设计标准以触发缩小/放大和/或放大/缩小。

Will aws copy the whole instance assign it a new ip and spawn it as a new instance or will I have to write some code to automate this process? 将aws复制整个实例,为它分配一个新的ip,并将其作为新实例生成,还是我必须编写一些代码来自动化该过程?

  • See AWS ElasticLoadBalancing and also check out more on AWS AutoScaling. 请参阅AWS ElasticLoadBalancing,并进一步了解AWS AutoScaling。 On the automation process, if ever you'll push through with CloudFormation, instance and/or containers(depending on your design) will be managed gracefully. 在自动化过程中,如果您将继续使用CloudFormation,实例和/或容器(取决于您的设计)将得到优雅的管理。

Plus will it not be an overhead to pull code from git and deploy every time a new instance is spawned? 加上每次生成新实例时从git中提取代码并进行部署都不会产生开销吗?

  • As mentioned, earlier having a pipeline for rolling out new versions of your application via CodeBuild, this will create an image with the new code changes and when everything is ready, it will be deployed ~ becomes a container. 如前所述,前面有一个通过CodeBuild推出应用程序新版本的管道,这将创建一个具有新代码更改的映像,当一切准备就绪时,它将被部署为容器。 The old EC2 instance or the old container( depending on how you want your application be deployed) will be gracefully shut down after a new version of your application is up and running. 在新版本的应用程序启动并运行之后,旧的EC2实例或旧的容器(取决于您希望如何部署应用程序)将正常关闭。 This will give you zero downtime. 这将使您的停机时间为零。

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

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