From 06981c1aea94dcf1bcfa9c12ca88e836c8496882 Mon Sep 17 00:00:00 2001 From: XiyuChen Date: Tue, 17 Jul 2018 23:26:03 +0800 Subject: [PATCH] Finished 3-1-ASG.md --- 3-1-ASG.md | 226 ++++++++++++++++++++++------------------------------- 1 file changed, 94 insertions(+), 132 deletions(-) diff --git a/3-1-ASG.md b/3-1-ASG.md index 65da50d..941cd0b 100644 --- a/3-1-ASG.md +++ b/3-1-ASG.md @@ -1,44 +1,43 @@ -# Launch Configurations and Auto Scaling Groups +# Launch Configurations 和 Auto Scaling Groups -## Key Concepts +## 关键概念 -Before we get started, here are a couple of loose concepts: +在我们开始之前, 我们先看几个关键的概念 - - *Launch Configurations are a blueprint for how you want to make your instances*. This means that you configure it in the same way that you would configure an EC2 instance, with the difference that you're not actually making one - you're making a *plan* for your instance. + - *Launch Configurations 是你用来构建你的EC2实例的蓝图.* 也就是说你可以用你配置EC2实例的方式去配置它, 唯一不同的是, 在配置它的过程中, 你不会真正的创建一个EC2 实例, 你只是为它(们)画一个图纸 - - *Autoscaling Groups dictate how many instances you want to run.* It has many mechanisms for doing so - via manual intervention or system checks, but combined with Launch Configurations, you can automate the process of making instances. + - *Autoscaling Groups控制着你期望运行的实例的数量.* 它有很多种机制来实现对运行实例的控制:手动控制或者系统监测等. 它和Launch Configurations 组合使用来自动创建/销毁实例. -Now that's out of the way, let's get started! +好啦, 我们可以开始啦. -## What we're going to do +## 我们接下来要做些什么? -In this practical session, we will: +在这个实操课程中, 我们将会: - - Create a Launch Configuration + - 创建一个Launch Configurations - - Specify UserData as we did with EC2 earlier + - 和为EC2指定UserData类似的方式为Launch configuration指定UserData - - Create an Autoscaling Group + - 创建一个Autoscaling Group - - Configure Autoscaling group so it attaches instances to the ELB + - 配置Autoscaling Group, 使其创建的实例可以关联到ELB上 - - Test scaling up or down - + - 测试 -## Creating a Launch Configuration +## 创建一个Launch Configuration -### 1.) Creating your Launch Configuration -Go to Services > EC2, then look for *Launch Configurations* on the left-hand side. Click on *Create Launch Configuration* +### 1.) 创建你的Launch Configuration -![Image][3-1-createlcfg] +跳转到Services > EC2, 你能在左边栏看到 *Launch Configurations*. 点击 *Create Launch Configuration* +![Image][3-1-createlcfg] -### 2.) Set your Launch configuration size, and AMI -We will configure your Launch Configuration in the same way we configure your instance - with the following parameters: +### 2.) 设置Launch configuration 将要使用的实例的尺寸和AMI +我们使用配置EC2实例的方式来配置Launch Configuration ``` - AMI: Amazon Linux AMI - Instance Type: t2.micro @@ -47,17 +46,17 @@ We will configure your Launch Configuration in the same way we configure your in ![Image][3-1-2-instancetype] -### 3.) Configure Launch Configuration details +### 3.) 配置Launch Configuration其他细节 -We'll then set your Launch Configuration details. Name your Launch Config *myname-launchconfig*. +我们将要设置Launch Configuration的其他细节, 先给它命名*myname-launchconfig*. ![Image][3-1-3-iamrole] -Note that this IAM role only allows read-only access to the contents of the S3 bucket you've placed your Wordpress package in - and nothing else. +需要注意的是: 这个IAM role 只有你放置Wordpress的那个S3 bucket的只读权限. -### 4.) Set Advanced Details +### 4.) 高级设置 -In the same panel, click on *Advanced Details*. In the *User Data* field, paste the following in: +在同一个配置界面, 点击 *Advanced Details*, 将下列内容粘贴到 *User Data* 栏里面: ``` #!/bin/bash @@ -68,202 +67,165 @@ chown -R apache /var/www/html service httpd start ``` -**Make sure** you change `firstname.lastname-wordpress.tgz` to your name, or the filename of the Wordpress package you sent over. And change the S3 bucket name to your specific account. +**确保** 将 `firstname.lastname-wordpress.tgz` 改名为你自己的名字, 或者你自己命名的Wordpress包名. 同时给S3 bucket 命名. ![Image][3-1-4-userdata] -### 5.) Disable public IP addresses - -In the same panel, select *Do not assign public IP*. This is an important security measure, and separates the instances from the public web - all interaction is via your Load Balancer. +### 5.) 禁用公网IP -Go to the next page afterwards. +在同一个配置界面, 选择 *Do not assign public IP*. 这是一个非常重要的安全度量衡, 并且它将实例于公网分割开, 所有交互只能通过负载均衡. -### 6.) Set storage +进入下一个页面 -We don't need to modify the storage, so we'll leave everything in *Add Storage* as default for now. +### 6.) 设置存储 +我们不需要修改存储配置, 所以我们把所有 *Add Storage* 中的配置保持默认 ![Image][3-1-5-storage] - ### 7.) Security Groups -We'll do the same thing that we did with your previous EC2 instance. In *Protocol*, select *HTTP* - then set *Source* to *"Custom IP"*. If you type out the name of the Load Balancer you created earlier, it should show up on the list. +我们将做于之前配置EC2 实例一摸一样的事. 在 *Protocol* 中选择 *HTTP*, 然后设置 *Source* 为 *"Custom IP"*, 如果你输出你之前创建的负载均衡的名称, 它应该要出现在下拉列表里面 ![Image][3-1-6-secgroups] +非常好的是, 对于每一个我们创建的实例来说, 我们只接受来自 *我自己的负载均衡* 的http流量, 这是非常好的 -The good thing about this is that for any instances we're creating, we're only ever expecting HTTP traffic *only from your Load Balancer*. This is a good thing. - -### 8.) Verify your configuration, select the SSH KeyPair +### 8.) 检查你的配置, 选择SSH秘钥对 -We'll finish up with a review of your Launch Configuration. Check that everything is valid, then click on *Create Launch Configuration* +我们将在检查完配置以后完成Launch Configuration 的创建, 确认一切都OK 以后, 点击 +*Create Launch Configuration* ![Image][3-1-7-reviewlc] +和创建EC2 实例一样, 在最后会让你选择一个你之前创建好的SSH秘钥对 -As with creating EC2 instances, this will ask you to specify a Key Pair. Specify the one you created earlier. +## 创建一个AutoScaling Group -## Creating an AutoScaling Group +### 9.) 为你的Launch Configuration创建一个Autoscaling Group -### 9.) Create an Autoscaling Group for your Launch Config - -Once you click *Create Launch Configuration*, you should see another button called *Create an Autoscaling Group using this Launch Configuration*. Click on it. +当你点击 *Create Launch Configuration* 以后, 你应该能看到另外一个按钮: *Create an Autoscaling Group using this Launch Configuration*. 点击它. ![Image][3-1-8-createsgh] -### 10.) Set Autoscaling Group details - -In the next panel, specify the GroupPame as *myname-asg*. Set Group Size to *2* instances. - +### 10.) Autoscaling Group 细节配置 +在下一个配置界面, 将GroupName 指定为 *myname-asg*, 设置Group Size为 *2* ![Image][3-1-9-asgname] - - -### 11.) Select Network and Subnets - -For this exercise, we'll use the VPC marked *default*. If you click on the *Subnet* input box, you should be given two to three subnets to choose from. Select *all of them* as destinations. - +### 11.) 选择Network和Subnets +在这次练习中, 我们将使用 *default* VPC, 点击 *Subnet* 输入框, 你应该选择2-3个Subnet ![Image][3-1-10-subnets] +Subnet 的设置基本上决定了你的实例将在哪个AZ部署--可以把AZ理解成数据中心, 数据中心将分布在一个region的不同地点, 你会需要很好的扩散性--这将在某个AZ挂掉的情况下为你的服务提供保障. +### 12.) 设置 Load Balancer -Subnets essentially set which Availability Zones to deply your instances under. Think of Availability Zones as datacenters - separate locations in Sydney where your instance will live. You'll want a good spread - this protects your service from outages if say, a datacenter in one Sydney location goes down. - -### 12.) Set Load Balancer - -If you click on *Advanced Details* under the same pane, you should see a tickbox called *Load Balancing*. This allows you to register the server as *live* and attaches it to the Load Balancer you created earlier. - +在同一个配置界面上点击 *Advanced Details*, 你能看到一个复选框 *Load Balancing*. 这个选项可以让你把新创建的实例附属到负载均衡上. ![Image][3-1-11-elb] +一个额外的选择框应该会出现在页面上: *Classic Load Balancers*, 你应该可以选择你之前创建的负载均衡了. +### 13.)保持扩展策略的默认值 +我们暂时不打算使用扩展策略 - 所以选择 *Keep this group at its initial size*。请记住,您可以使用策略来监视实例的CPU或内存使用情况 - 例如,如果CPU的使用率超过70%,您可以选择自动添加更多实例。 -An additional set of options should appear. If you click on the input box for *Classic Load Balancers*, you should be able to select the Load Balancer you created earlier. - -### 13.) Keep scaling policies default - - -We're not going to be playing with Scaling Policies for the time being - so choose *Keep this group at its initial size*. Just keep in mind that you can use policies to watch for the CPU or memory use of your instances - so for example, if the CPU ever goes over 70% usage, you can choose to add more instances automatically. - -### 14.) Skip notifications - -We'll choose not to send notifications at this time. Think of this as a way of notifying someone if an event occurs - if say, an instance is launched or deleted. +### 14.)跳过通知 +我们此时会选择不发送通知。可以将此视为一种通知某人是否发生事件的方式 - 例如,启动或删除实例。 -### 15.) Configure tags - -As with anything that we do, it's iportant to tag our to-be-created instances as soon as they're created. Set a Key of *Name*, and set the Value to your name. +### 15.)配置标签 +与我们所做的任何事情一样,一旦创建它们就会标记我们要创建的实例。设置 *Name* 的键,并将值设置为您的名称。 ![Image][3-1-12-tags] +### 16.)复习,结束! -### 16.) Review, and finish up! - -You should be met with a section where you can review the changes that have occurred. Click *Create Auto Scaling Group* once you're ready, and it should kick things off. +您应该会遇到一个部分,您可以在其中查看已发生的更改。准备好后,单击*create Auto Scaling group*,它应该开始被创建了。 ![Image][3-1-13-review] +##测试您的Autoscaling组:替换实例 +现在,一切都应该准备好了!我们有 *blueprint* 用于创建实例,我们有 *count* 个实例要创建,所以让我们看看它是否正常工作! -## Testing your Autoscaling Group: Replacing Instances - -Now, everything should be ready! We have our *blueprint* for creating instances, and we have a *count* of instances to create, so let's see if it's working! +### 17.)再次检查Load Balancer -### 17.) Check your Load Balancer again - -Go to *Services > EC2 > Load Balancers*. Select the Load Balancer you created previously (*myname-elb*), then look for the description. +转到 *Services > EC2 > Load Balancers* 。选择您之前创建的Load Balancer( *myname-elb* ),然后查看说明。 ![Image][3-1-14-elbinstances] +### 18.)使用DNS名称访问Load Balancer -### 18.) Use the DNS Name to access your Load Balancer - -Copy the DNS name (similar to below), and paste it on another tab. You're effectively looking at any of your four instances. +复制DNS名称(类似于下面),并将其粘贴到浏览器中。你将访问到你的四个实例中的任何一个。 ![Image][3-1-15-accesslb] +### 19.)杀死你的实例 -### 19.) Kill your instances +转到 *Services > EC2 > Instances*。在上面的搜索框中,您应该可以输入您的姓名 - 允许您搜索使用您的姓名标记的任何实例。 -Go to *Services > EC2 > Instances*. In the search box above, you should be able to type your name - allowing you to search any instances you tagged with your name. - -For all of your four instances, *Right-Click > Instance State > Terminate*. +对于所有四个实例,*Right-Click > Instance State > Terminate*。 ![Image][3-1-16-killec2] +### 20.)检查您的ELB +检查粘贴Load Balancer的DNS名称的浏览器选项卡。它应该很快就会出现问题。 -### 20.) Check your ELB - -Check the browser tab where you pasted your Load Balancer's DNS name. It should be return with a problem shortly. - - -### 21.) Watch new instances get created - -In the AWS console, check under *Services > EC2 > Instances* every minute or so. What you should see is that eventually, new instances with your name should be created. +### 21.)观看新实例的创建 +在AWS控制台中,每分钟左右检查 *Services > EC2 > Instances*。你应该看到的是,最终应该创建具有你名字的新实例。 ![Image][3-1-17-instancereplace] +## 测试您的Autoscaling组:调整实例数量 +现在我们知道您的实例正在自动替换,我们可以看到当我们更改Autoscaling Group中的实例数时会发生什么。 - -## Testing your Autoscaling Group: Resizing the number of instances - -Now that we know that your instances are getting automatically replaced, we can see what happens when we change the number of instances in your Autoscaling Group. - -### 22.) Modify your Autoscaling Group - -Go to *Services > EC2 > Autoscaling Group*. Look for the Autoscaling Group you created. - -Once you highlight the Autoscaling Group you created, go to the bottom panel and click on *Edit*. Set your *Desired Instances* to 3 and your *Max Instances* to 3. Click on *Save*. +### 22.)修改您的Autoscaling组 +转到 *Services > EC2 > Autoscaling Group*。查找您创建的Autoscaling组。 +突出显示您创建的Autoscaling Group后,转到底部面板,然后单击 *Edit* 。将 *Desired Instances* 设置为3,将 *Max Instances* 设置为3.单击 *Save*。 ![Image][3-1-18-setasg] +### 23.)观看新实例的创建 -### 23.) Watch new instances get created +在AWS控制台中,每分钟左右检查 *Services > EC2 > Instances*。你应该看到的是,最终应该创建具有你名字的新实例。 -In the AWS console, check under *Services > EC2 > Instances* every minute or so. What you should see is that eventually, new instances with your name should be created. +恭喜!您已经有了一个可自动扩展的服务! +##基础设施作为代码 -Congratulations! You have an automated scaling service! +现在您已经完成了创建自我修复扩展组的所有工作,现在是时候将它全部部署为代码了。作为代码的基础架构是DevOps中的一个重要思想 - 这可以确保您的基础架构可重复,并且易于协作。 -## Infrastructure as code +### 24.)下载Cloudformation模板 -Now that you've done everything to make a self-healing scaling group, it's time for you to deploy it all as code. Infrastructure-as-code is an important idea within DevOps - this makes sure that your infrastructure is repeatable, and is easy to collaborate on. +下载cloudformation模板[这里](https://raw.githubusercontent.com/DevOpsGirls/devopsgirls-bootcamp/master/devopsgirls-wordpress.yaml)。您可以使用文本编辑器(记事本或类似的东西)打开它。 -### 24.) Download the Cloudformation template +### 25.)阅读模板 -Download the cloudformation template [here](https://raw.githubusercontent.com/DevOpsGirls/devopsgirls-bootcamp/master/devopsgirls-wordpress.yaml). You can open it with your text editor (Notepad, or something similar). +您要注意的是,如果向下滚动,您所做的一切基本上都是逐行声明的。我知道它看起来很吓人,但不要担心!这只是您想要构建的内容的声明。 -### 25.) Read through the template +### 26.)转到Cloudformation部分 -What you're going to notice is that everything you've made is basically declared line by line if you scroll down. I know it looks intimidating, but don't worry! This is just a declaration of what things you want build. +转到 **Services> Cloudformation** 。单击 **Create Stack**。 -### 26.) Go to the Cloudformation section - -Go to **Services > Cloudformation**. Click on **Create Stack**. - -This will point you to a page where you can upload your template file. Click on **Next**. +这将指向一个页面,您可以在其中上传模板文件。点击 **Next**。 ![Image][3-1-19-upload] +### 27.)设置堆栈名称和参数 -### 27.) Set the Stack Name and Parameters - -Set the `DevopsGirlsUser` parameter. Use your `firstname.lastname` format for this. +设置`DevopsGirlsUser`参数。使用您的`firstname.lastname`格式。 -Change `WordpressS3Bucket` to the name of your S3 bucket name - for example `devopsgirls-training-2` or `devopsgirls-training-3` depending on which account you were setup in. +将`WordpressS3Bucket`更改为S3存储桶名称的名称 - 例如`devopsgirls-training-2`或`devopsgirls-training-3`,具体取决于您设置的帐号。 -### 28.) Review, and click on IAM resources +### 28.)查看,然后单击IAM资源 -Click through the rest of the dialogs until you get to the **Review** section. On the text box at the bottom that says "*I acknowledge that AWS CloudFormation might create IAM resources*", tick the boxes. +单击其余对话框,直到进入 **Review** 部分。在底部的文本框中显示“ *I acknowledge that AWS CloudFormation might create IAM resources*,勾选方框。 ![Image][3-1-20-iam] -Click on *Create*. - -### 29.) See your stack get created - -Go to **Services > Cloudformation** and look for the stack name you set earlier. On the dialog box at the bottom, click on *Events*. Refresh it every now and then - and watch as your environment gets created! +点击 *Create*. +### 29.)看看您的堆栈是否已创建 -Congratulations! Now you've deployed things with code! +跳转到 **Services > Cloudformation** 并查找您之前设置的堆栈名称。在底部的对话框中,单击 *Events*。不时刷新它, 然后你就能看到你的环境正在被创建 +恭喜你, 你已经实现代码的部署了. [3-1-10-subnets]: https://raw.githubusercontent.com/DevOpsGirls/devopsgirls-bootcamp/master/images/3-1-ASG/3-1-10-subnets.png [3-1-11-elb]: https://raw.githubusercontent.com/DevOpsGirls/devopsgirls-bootcamp/master/images/3-1-ASG/3-1-11-elb.png