Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Synchronising IIS servers in aws ec2 with autoscaling best practice

We run our web application on Amazon EC2 with load-balanced, autoscaling web servers (IIS).

Before autoscaling, our deployment process was file-copy to a couple of big web servers.

Now with autoscaling we have anything from 5 to 12 webservers which appear and vanish at will, making the deployment process more difficult.

To address this, I wrote a powershell script that retrieves the IP of servers in an autoscaling group and uses MSDeploy to synchronise them with a designated deployment server (in load balancer, outside of autoscaling group). It then creates a new AMI and updates the autoscaling config.

All seemed to be good, until after rebuilding the deployment server, the sync script does not update the running state of the web sites. So I can put the site into maintenance mode.

I would like to know:

  • how other people approach the problem (specifically syncing iis servers in autoscaling ec2) (in the absence of WFF for IIS 8)

  • why the start/stop sync is failing

Code:

Set-AWSCredentials -AccessKey XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX -SecretKey XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
Set-DefaultAWSRegion "us-west-2"

$date = get-date
$dateString = $date.ToString("yyyyMMdd-HHmm")
$name = $dateString +  "Web"
$imageId = new-ec2image -InstanceId x-xxxxxxxx -Name $name -NoReboot 1

$launchConfiguration = New-ASLaunchConfiguration -LaunchConfigurationName $name -ImageId $imageId -InstanceType "m3.medium" -SecurityGroups @('Web') -InstanceMonitoring_Enabled $false

Update-AsAutoScalingGroup -AutoScalingGroupName "XxxxxxxxxxxxXxxxxxxxxx" -LaunchConfigurationName $name

$a = Get-ASAutoScalingInstance | select -expandproperty InstanceId | Get-EC2Instance | select -expandproperty RunningInstance | select -property PrivateIpAddress

foreach($ip in $a)
{
        $command = "C:\Program Files\IIS\Microsoft Web Deploy V3\msdeploy.exe"
        $arg = "-dest:webServer,computerName=" + $ip.PrivateIpAddress;
        $args = @('-verb:sync', '-source:webServer', $arg)
        &$command $args
}
like image 723
sentece Avatar asked Apr 02 '14 10:04

sentece


1 Answers

Don't try and "sync" the web servers. Consider doing a one time install - and allowing a tool boot for deploying manage the syncing.

What I've done in the past is used CloudFormation to create the environment, and with a combination of cfn-init and cfn-hup to do the installation. The deployment process then becomes a case of reploying a new package to somewhere like S3, and then using CloudFormation to bump the version.

This triggers a cfn-hup update, whereby each server will pull down the package from S3 and reinstall.

Also - if your scaling group scales, it will automatically use the cfn-init to pull down and install the package completely before registering the instance with the load balancer.

A couple of similar StackOverflow questions here

  • AWS - Automatic deployment (.NET) to CloudFormation stack
  • Installing Windows applications/extensions with Amazon CloudFormation
  • Amazon EC2: load balancing / way to sync files / EC2 + CF
  • How do I execute UserData content in a Windows EC2 instance

Also I wrote two articles many moons ago about it

  • http://blog.kloud.com.au/2013/08/05/bootstrapping-on-aws/
  • http://blog.kloud.com.au/2013/08/19/bootstrap-update/

This should give you enough to get going.

like image 122
Pete - MSFT Avatar answered Oct 20 '22 00:10

Pete - MSFT