This section of beans to see how to use PowerShell to configure ELB and auto Scaling. ELB provides load balancing for multiple servers, while auto scaling can increase or decrease the server in a Elb cluster based on load dynamics.
The specific image interface configuration method can refer to this
http://beanxyz.blog.51cto.com/5570417/1536261
Here's how the command line is implemented:
First look at the configuration of the Elb.
For example, the following script:
He listens on port 80, specifies that ELB is distributed over subnets 10.2.1.0/24 and 10.2.2.0/24, Security Group is NEWSG, and adds a EC2 instance test.
#Create ELB$HTTPListener = New-Object -TypeName ' Amazon.ElasticLoadBalancing.Model.Listener ' $HTTPListener .protocol = ' http ' $HTTPListener. Instanceport = 80$httplistener.loadbalancerport = 80$groupid= (Get-ec2securitygroup| where-object {$_. groupname -eq "NEWSG"}). Groupid$subnet1= (get-ec2subnet | where-object {$_. cidrblock -eq "10.2.1.0/24"}). Subnetid$subnet2= (get-ec2subnet | where-object {$_. cidrblock -eq "10.2.2.0/24"}). subnetidnew-elbloadbalancer -loadbalancername "Myloadbalance" -Listener $HTTPListener -SecurityGroup $groupid -subnet @ ($subnet 1, $subnet 2) $instnaces = get-ec2instanceforeach ($i in $instnaces) { if ($i. Instances.tags.value -eq "test") { $instance 2id= $i. Instances.instanceid }} register-elbinstancewithloadbalancer -loadbalancername "Myloadbalance" -Instance @ ($ INSTANCE2ID)
After configuring ELB, we then configure Auto Scaling, which first requires generating an image file based on the currently prepared virtual machine.
Like what
#Images $instnaces =get-ec2instanceforeach ($i in $instnaces) {if ($i. Instances.tags.value-eq "Linux") {$instanceI d= $i. Instances.instanceid}}new-ec2image-description templatetest-name Template-instanceid $instanceIdGet-ec2ima Ge-owner Self | Unregister-ec2image-passthru
After generating the image file, I need to create a launch configuration file that binds the image and the associated subnet.
#Create Auto Scaling Policy and Groupget-asautoscalinggroupnew-aslaunchconfiguration-imageid (Get-ec2image-owner self ). Imageid-launchconfigurationname "My-launchconfigurationfile"-instancetype "T2.micro"-SecurityGroup $groupid
Finally, the configuration of a basic autoscalinggroup, binding the above launch configuration file is possible. Note that the security group and subnet are bound to be in a range, or else he will error. Unable to generate EC2 instance.
New-asautoscalinggroup-autoscalinggroupname "MY-ASG"-launchconfigurationname "My-launchconfigurationfile"- MinSize 1-maxsize 3-loadbalancername "myloadbalance"-availabilityzone @ ("ap-southeast-2c") '-vpczoneidentifier $ Subnet1write-asscalingpolicy-autoscalinggroupname my-asg-adjustmenttype "changeincapacity"-PolicyName " Myscaleinpolicy "-scalingadjustment 1 remove-asautoscalinggroup-autoscalinggroupname" MY-ASG "
Since I have specified at least 1 instances, he will automatically create a elb inside the
650) this.width=650; "src=" Http://s2.51cto.com/wyfs02/M02/83/AB/wKiom1d6CZWChajRAAB5e8K1d8Q400.png "style=" float: none; "title=" 12.PNG "alt=" Wkiom1d6czwchajraab5e8k1d8q400.png "/>
If you are familiar with auto scaling group, you can see that the policy I created is too simple to have a alarm trigger.
650) this.width=650; "src=" Http://s3.51cto.com/wyfs02/M02/83/AA/wKioL1d6CmWR2StsAADCflHoudk047.png "title=" 13.PNG "alt=" Wkiol1d6cmwr2stsaadcflhoudk047.png "/>
In fact, the auto scaling group created the corresponding policy and alarm so I took a lot of effort. Because AWS does not know for what reason, his creation command is Write-asscalingpolicy, and the corresponding read command is get-aspolicy, the Delete command is Remove-aspolicy, completely does not conform to the naming specification!! Even more strangely, I searched for almost all the relevant keywords and official documents, and just couldn't find how to create the corresponding alarm with PowerShell. Either AWS does not currently provide the corresponding function, or AWS does not follow the custom name, and does not know what the command name is written.
This article is from the "Mapo Tofu" blog, please be sure to keep this source http://beanxyz.blog.51cto.com/5570417/1795603
Powershell AWS Automation Management (5)-ELB and Auto Scaling