我想将现有的Azure负载平衡器附加到虚拟机规模集,为此,我需要创建入站nat池,以便我可以获取入站nat池的资源ID并将其传递给VMSS的ARM模板。 预先感谢。
答案 0 :(得分:1)
根据我的研究,我们可以使用PowerShell命令New-AzLoadBalancerInboundNatPoolConfig
创建入站nat池。有关更多详细信息,请参阅https://docs.microsoft.com/en-us/powershell/module/az.network/New-AzLoadBalancerInboundNatPoolConfig?view=azps-2.8.0。
例如:
Connect-AzAccount
$slb = Get-AzLoadBalancer -Name "testload" -ResourceGroupName "testfun07"
$feIpConfig = Get-AzLoadBalancerFrontendIpConfig -Name "LoadBalancerFrontEnd" -Loadbalancer $slb
New-AzLoadBalancerInboundNatPoolConfig -Name "myInboundNatPool" -FrontendIpConfigurationId $feIpConfig.Id -Protocol TCP -FrontendPortRangeStart 1001 -FrontendPortRangeEnd 2000 -BackendPort 1001
如果我们要使用PowerShell为现有负载均衡器创建入站NAT池,则需要执行以下步骤
$slb = Get-AzureRmLoadBalancer -Name "testload" -ResourceGroupName "testfun07"
$feIpConfig = Get-AzureRmLoadBalancerFrontendIpConfig -Name "LoadBalancerFrontEnd" -Loadbalancer $slb
Add-AzureRmLoadBalancerInboundNatPoolConfig -LoadBalancer $slb -Name "myInboundNatPool" -FrontendIpConfigurationId $feIpConfig.Id -Protocol TCP -FrontendPortRangeStart 1001 -FrontendPortRangeEnd 2000 -BackendPort 1001
Set-AzureRmLoadBalancerInboundNatPoolConfig -LoadBalancer $slb -Name "myInboundNatPool" -FrontendIpConfigurationId $feIpConfig.Id -Protocol TCP -FrontendPortRangeStart 1001 -FrontendPortRangeEnd 2000 -BackendPort 1001
Set-AzureRmLoadBalancer -LoadBalancer $slb
例如
$name = "you account"
$password = "password"
$secpasswd = ConvertTo-SecureString $password -AsPlainText -Force
$mycreds = New-Object System.Management.Automation.PSCredential ($name, $secpasswd)
Connect-AzureRmAccount -Credential $mycreds
$slb = Get-AzureRmLoadBalancer -Name "testload" -ResourceGroupName "testfun07"
$feIpConfig = Get-AzureRmLoadBalancerFrontendIpConfig -Name "LoadBalancerFrontEnd" -Loadbalancer $slb
Add-AzureRmLoadBalancerInboundNatPoolConfig -LoadBalancer $slb -Name "myInboundNatPool" -FrontendIpConfigurationId $feIpConfig.Id -Protocol TCP -FrontendPortRangeStart 1001 -FrontendPortRangeEnd 2000 -BackendPort 1001
"1" | Out-File -FilePath E:\mytest.txt -Append -Encoding utf8
Get-AzureRmLoadBalancer -Name "testload" -ResourceGroupName "testfun07" | Select-Object InboundNatPools | fl | Out-File -FilePath E:\mytest.txt -Append -Encoding utf8
Set-AzureRmLoadBalancerInboundNatPoolConfig -LoadBalancer $slb -Name "myInboundNatPool" -FrontendIpConfigurationId $feIpConfig.Id -Protocol TCP -FrontendPortRangeStart 1001 -FrontendPortRangeEnd 2000 -BackendPort 1001
"2" | Out-File -FilePath E:\mytest.txt -Append -Encoding utf8
Get-AzureRmLoadBalancer -Name "testload" -ResourceGroupName "testfun07" | Select-Object InboundNatPools | fl | Out-File -FilePath E:\mytest.txt -Append -Encoding utf8
Set-AzureRmLoadBalancer -LoadBalancer $slb
"3" | Out-File -FilePath E:\mytest.txt -Append -Encoding utf8
Get-AzureRmLoadBalancer -Name "testload" -ResourceGroupName "testfun07" | Select-Object InboundNatPools | fl | Out-File -FilePath E:\mytest.txt -Append -Encoding utf8
答案 1 :(得分:0)
感谢您的回复,但经过一番摸索,终于找到了答案。
New-AzureRmLoadBalancerInboundNatPoolConfig -Name "natpool3" -Protocol Tcp -FrontendPortRangeStart 50000 -FrontendPortRangeEnd 50119 -BackendPort 3389
$lb= Get-AzureRmLoadBalancer -ResourceGroupName VMSS-RG -Name nbslb
$feip=(Get-AzureRmLoadBalancer -ResourceGroupName VMSS-RG -Name nbslb).FrontendIpConfigurations[0].Id
Add-AzureRmLoadBalancerInboundNatPoolConfig -LoadBalancer $lb -FrontendIpConfigurationId $feip -Name "natpool3" -Protocol Tcp -FrontendPortRangeStart 50000 -FrontendPortRangeEnd 50119 -BackendPort 3389
Set-AzureRmLoadBalancer -LoadBalancer $lb