我们在 Amazon EC2 上运行我们的 Web 应用程序,并使用负载平衡、自动缩放的 Web 服务器 (IIS)。
在自动缩放之前,我们的部署过程是将文件复制到几个大型 Web 服务器。
现在通过自动缩放,我们可以随意出现和消失 5 到 12 个网络服务器,这使得部署过程更加困难。
为了解决这个问题,我编写了一个 powershell 脚本,该脚本检索自动缩放组中服务器的 IP,并使用 MSDeploy 将它们与指定的部署服务器(在负载均衡器中,在自动缩放组之外)同步。然后它会创建一个新的 AMI 并更新自动缩放配置。
一切似乎都很好,直到重建部署服务器后,同步脚本才更新网站的运行状态。所以我可以将网站置于维护模式。
我想知道:
其他人如何解决问题(特别是在自动缩放 ec2 中同步 iis 服务器)(在没有用于 IIS 8 的 WFF 的情况下)
为什么启动/停止同步失败
代码:
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
}