我正在尝试使用Move-AzureDeployment cmdlet交换服务器,方法是在我的Powershell中运行它。从暂存切换到生产似乎需要大约 4 分钟。这是 4 分钟的停机时间,这是不可接受的。当我从 Azure 门户手动交换服务器时,它几乎是立即发生的。
我想知道为什么使用 cmdlet 需要更长的时间,以及我可以做些什么来解决此问题,因为我希望能够使用 powershell 交换我的暂存服务器和生产服务器。
这是我的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 SDKsAzurePowerShellServiceManagementAzureAzure.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
}
据我了解,暂存槽和生产之间的交换是 VIP 交换,因为它们都在运行。Microsoft说你不应该在网站/应用程序本身看到任何停机时间。在更改完成之前,请求仍将命中旧的生产服务器。在交换期间,您是否看到站点停机?