powershell - Move-Azure 部署交换服务器花费的时间太长?

标签 powershell azure azure-powershell

我正在尝试通过在 powershell 中运行 Move-AzureDeployment cmdlet 来交换服务器。从暂存切换到生产似乎需要大约 4 分钟。那是 4 分钟的停机时间,这是 Not Acceptable 。当我从 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 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
 }   

最佳答案

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

关于powershell - Move-Azure 部署交换服务器花费的时间太长?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37419239/

相关文章:

windows - Remove-Item 不起作用,Delete 起作用

powershell - 如何在 Powershell 中为 Format-Table 创建别名?

azure - 将 Azure VMS 从一个帐户的一个订阅移动到另一个帐户的另一个订阅的最快方法

powershell - 如何在 PowerShell 脚本中重用/导入脚本代码?

Powershell:启动进程不将参数传递给 cmd.exe

node.js - 使用 axios 进行 Azure Zip 部署

Azure VM 操作系统构建 - Powershell

Azure ARM - Microsoft.Resources/deploymentScripts

azure - 如何使用 prependpath 在 azure-pipeline 中设置路径

azure - 从 Azure 门户创建用户委托(delegate) key