我正在尝试自动将我使用 ARM 模板创建的新 VM 的 IP 地址包含到 Azure 应用程序网关后端池中。
据我所知,我需要获取当前池成员,然后将新的 IP 地址附加到此列表中,并执行 Set-AzApplicationGatewayBackendAddressPool 命令,然后执行 Set-AzApplicationGateway 命令。
无论我是否引用我的 IP 地址,迄今为止的努力都导致了以下错误。请注意,我尝试了另一个不带空格的字符串,这也产生了相同的结果。
之前有其他人遇到过这种情况吗?如果是这样,您是如何解决的?
$AppGw = Get-AzApplicationGateway -Name "app-gw-name" -ResourceGroupName "Region-Name"
$BackendPool = Get-AzApplicationGatewayBackendAddressPool -Name "pool-name" -ApplicationGateway $AppGw
$BackendPoolAddresses = $BackendPool.BackendAddressesText |
Select-String -Pattern '"IpAddress":\s*"?([^",]+)"?,?' -allmatches |
Foreach-Object { $_.Matches |
Foreach-Object { $_.Groups[1].Value }
}
$BackendPoolString = '"' + [String]::Join('", "',$BackendPoolAddresses) + '"' + ", " + '"10.0.0.10"'
$AppGw = Set-AzApplicationGatewayBackendAddressPool -ApplicationGateway $AppGw -Name "pool-name" -BackendIPAddresses $BackendPoolString
Set-AzApplicationGateway -ApplicationGateway $AppGw
Set-AzApplicationGateway : Backend Address "10.0.0.6", "10.0.0.7", "10.0.0.8", "10.0.0.9", "10.0.0.10" present within Backend Address Pool pool-name does not meet the format requirements. The address must contain only digits,
letters, hyphens and dots for separation. Moreover, it cannot have hyphens at the start, end or next to a dot.
At line:10 char:1
+ Set-AzApplicationGateway -ApplicationGateway $AppGw
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : CloseError: (:) [Set-AzApplicationGateway], CloudException
+ FullyQualifiedErrorId : Microsoft.Azure.Commands.Network.SetAzureApplicationGatewayCommand
AppGw = Get-AzApplicationGateway -Name "pp-gw-name" -ResourceGroupName "Region-Name"
$BackendPool = Get-AzApplicationGatewayBackendAddressPool -Name "pool-name" -ApplicationGateway $AppGw
$BackendPoolAddresses = $BackendPool.BackendAddressesText |
Select-String -Pattern '"IpAddress":\s*"?([^",]+)"?,?' -allmatches |
Foreach-Object { $_.Matches |
Foreach-Object { $_.Groups[1].Value }
}
$BackendPoolString = [String]::Join(", ",$BackendPoolAddresses) + ", " + "10.0.0.10"
$AppGw = Set-AzApplicationGatewayBackendAddressPool -ApplicationGateway $AppGw -Name "pool-name" -BackendIPAddresses $BackendPoolString
Set-AzApplicationGateway -ApplicationGateway $AppGw
Set-AzApplicationGateway : Backend Address 10.0.0.6, 10.0.0.7, 10.0.0.8, 10.0.0.9, 10.0.0.10 present within Backend Address Pool pool-name does not meet the format requirements. The address must contain only digits, letters, hyphens
and dots for separation. Moreover, it cannot have hyphens at the start, end or next to a dot.
At line:10 char:1
+ Set-AzApplicationGateway -ApplicationGateway $AppGw
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : CloseError: (:) [Set-AzApplicationGateway], CloudException
+ FullyQualifiedErrorId : Microsoft.Azure.Commands.Network.SetAzureApplicationGatewayCommand
最佳答案
我尝试了同样的方法,但遇到了如下所示的相同错误:
要在后端池中添加虚拟机 IP 地址,请使用以下修改脚本。
# Set the variables for the Application Gateway and Backend Pool
$AppGwName = "<AppGatewayName>"
$ResourceGroupName = "<RGName>"
$BackendPoolName = "<poolName>"
$NewIPAddresses = @("10.0.0.6", "10.0.0.7", "10.0.0.8", "10.0.0.9", "10.0.0.10")
# Get the Application Gateway and Backend Pool
$AppGw = Get-AzApplicationGateway -Name $AppGwName -ResourceGroupName $ResourceGroupName
$BackendPool = Get-AzApplicationGatewayBackendAddressPool -Name $BackendPoolName -ApplicationGateway $AppGw
# Set the updated backend addresses for the Backend Pool
Set-AzApplicationGatewayBackendAddressPool -ApplicationGateway $AppGw -Name $BackendPoolName -BackendIPAddresses $NewIPAddresses
# Update the Application Gateway
Set-AzApplicationGateway -ApplicationGateway $AppGw
输出:
执行脚本后,在portal后端池地址添加成功,如下:
要添加单个 IP 地址,您可以使用 $NewIPAddresses = "10.0.0.10"
关于azure - 将新的 VM IP 地址添加到 Azure 网关后端池失败,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/77176172/