簡體   English   中英

使用PowerShell將可用性集添加到Azure負載均衡器的后端池

[英]Using PowerShell to add an Availability Set to Backend Pool for Azure Load Balancer

盡管使用了官方文檔,但我仍在努力尋找合適的PowerShell,以將具有2個VM的可用性集及其第一個IP關聯到Azure負載平衡器的后端池配置。

有人可以幫忙嗎?

您可以使用Get-AzureRmAvailabilitySet獲取並枚舉可用性集中的VM。 然后使用Set-AzureRmNetworkInterface在每個VM NIC上設置LoadBalancerBackendAddressPool

此鏈接對此https://docs.microsoft.com/en-us/azure/networking/scripts/load-balancer-windows-powershell-sample-nlb提供了一些不錯的代碼

我遇到了相同的問題,我的目標是根據可用性集中的計算機更新負載均衡器backendPool。

我創建了一個腳本:

<#
.SYNOPSIS
    Updates the Azure Load Balancer backend Pool
.DESCRIPTION
    Add's vm's to the backend pool of the specified Azure Load Balancer.
.OUTPUTS
    Progress messages
#>
[CmdletBinding()]
Param(
    [Parameter(Mandatory = $True)]
    [string]$loadBalancerName,
    [Parameter(Mandatory = $True)]
    [string]$resourceGroupName,
    [Parameter(Mandatory = $True)]
    [string]$debugDeploymentDebugLevel,
    [Parameter(Mandatory = $True)]
    [string]$availabilitySetName,
    [Parameter(Mandatory = $True)]
    [string]$backendPoolName
)

$ErrorActionPreference = "Stop"

Try {
    $loadBalancer = Get-AzureRmLoadBalancer `
        -Name $loadBalancerName `
        -ResourceGroupName $resourceGroupName `
        -ErrorAction Stop
}
Catch {
    Write-Warning "No Load Balancer found with name $loadBalancerName in resource group $resourceGroupName"
    Return
}

try {
    $backendPool = Get-AzureRmLoadBalancerBackendAddressPoolConfig `
        -Name $backendPoolName `
        -LoadBalancer $loadBalancer
}
catch {
    #Write-Warning "no Backend Pool found with the name $backendPoolName in the load balancer with the name $loadBalancerName"
    Return
}

try {
    $AvSet = Get-AzureRmAvailabilitySet `
        -Name $availabilitySetName `
        -ResourceGroupName (Get-AzureRmResource | Where-Object {
            ($_.Name -eq $availabilitySetName) -and `
            ($_.ResourceType -eq "Microsoft.Compute/AvailabilitySets")}).ResourceGroupName
}
catch {
    Write-Warning "no AvailabilitySet found with the name $availabilitySetName in resource group $availabilitySetResourceGroup"
    Return
}

ForEach ($id in $avSet.VirtualMachinesReferences.id) {

    $nic = Get-AzureRmNetworkInterface | Where-Object {($_.VirtualMachine.id).ToLower() -eq ($id).ToLower()}
    $nic.IpConfigurations[0].LoadBalancerBackendAddressPools = $backendPool

    Set-AzureRmNetworkInterface -NetworkInterface $nic -AsJob    
}    

If ($ErrorMessages) {
    Write-Error "Deployment returned the following errors: $ErrorMessages";
    Return
}

您也可以在我的github上找到: https : //github.com/azurekid/blog/blob/master/Update-BackendPool.ps1

希望這可以幫助 ;-)

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM