移动AzureDeployment需要太长时间来交换服务器?

时间:2016-05-24 16:33:26

标签: powershell azure azure-powershell

我尝试使用Move-AzureDeployment cmdlet在我的PowerShell中运行它来交换服务器。它似乎需要大约4分钟才能从分期换成生产。这是4分钟的停机时间,并不是真的可以接受。当我从Azure门户手动交换服务器时,它几乎是瞬间发生的。

我想知道为什么使用cmdlet需要更长的时间,我该怎么做才能解决这个问题,因为我希望能够使用PowerShell交换我的Staging和Production Server。

这是我的powershell脚本:

  try
{   
$ErrorActionPreference = "stop"

Write-Host "Deploying build build no. $env:build_number to $_serviceName"

#import azure cmdlets module
Write-Host "Importing azure service management modules (i.e for the old portal)"
Import-Module "C:\Program Files (x86)\Microsoft SDKs\Azure\PowerShell\ServiceManagement\Azure\Azure.psd1"

Write-Host "Started Command for Switching Slots"
#Switch slots from Staging to Production
Move-AzureDeployment -ServiceName $_serviceName
Write-Host "Finished Command for Switching Slots"


#make sure deployment is in running state
$deployment = Get-AzureDeployment -servicename $_serviceName -slot $_slotName
Write-Host "$_serviceName is in state $($deployment.status)"
$StopWatch = [System.Diagnostics.Stopwatch]::StartNew() #declare stopwatch
while (($deployment.Status -ne "running") -and ($StopWatch.Elapsed.Hours -lt 2)) #running the loop for a maximum of 2 hours
{   
    Write-Host "wait 5 seconds before trying again" 
    Start-Sleep -s 5
    $deployment = Get-AzureDeployment -servicename $_serviceName -slot $_slotName
    Write-Host "$_serviceName is in state $($deployment.status)"        
}

#make sure all roles are in ready state
$nonReadyInstances = (Get-AzureDeployment $_serviceName -Slot $_slotName).RoleInstanceList | Where-Object { $_.InstanceStatus -ne "ReadyRole" } | ft -Property RoleName, InstanceName, InstanceStatus
$nonReadyInstances
$StopWatch = [System.Diagnostics.Stopwatch]::StartNew() #declare stopwatch
while (($nonReadyInstances -ne $null) -and ($StopWatch.Elapsed.Hours -lt 2)) #running the loop for a maximum of 2 hours
{
    Write-Host "wait 5 seconds before trying again" 
    Start-Sleep -s 5
    $nonReadyInstances = (Get-AzureDeployment $_serviceName -Slot $_slotName).RoleInstanceList | Where-Object { $_.InstanceStatus -ne "ReadyRole" }
    $nonReadyInstances
}

#output deployment id   
#$deploymentid = Check-Deployment -serviceName $_serviceName -slotName $_slotName
#Write-Host "Deployed to $_serviceName with deployment id $deploymentid and slot $_slotName"
    exit 0

  }
catch [System.Exception]
  {
Write-Host $_.Exception.ToString()
exit 1
 }   

1 个答案:

答案 0 :(得分:0)

根据我的理解,暂存槽和生产之间的交换是VIP交换,因为它们都在运行。微软表示,您不应该在网站/应用程序本身上看到任何停机时间。在更改完成之前,请求仍将命中旧的生产服务器。您是否在交换期间看到网站停机?