powershell命令,用于创建现有负载均衡器的新的入站NAT池

时间:2019-10-18 05:01:50

标签: azure powershell azure-load-balancer

我想将现有的Azure负载平衡器附加到虚拟机规模集,为此,我需要创建入站nat池,以便我可以获取入站nat池的资源ID并将其传递给VMSS的ARM模板。 预先感谢。

2 个答案:

答案 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

enter image description here


更新

如果我们要使用PowerShell为现有负载均衡器创建入站NAT池,则需要执行以下步骤

  1. 创建入站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
  1. 为laad平衡器配置ppol
Set-AzureRmLoadBalancerInboundNatPoolConfig -LoadBalancer $slb -Name "myInboundNatPool" -FrontendIpConfigurationId $feIpConfig.Id -Protocol TCP -FrontendPortRangeStart 1001 -FrontendPortRangeEnd 2000 -BackendPort 1001

  1. 更新负载均衡器
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

enter image description here

答案 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