简体   繁体   中英

Azure External Load Balancer - Adding LB Rules with PowerShell

I have been fighting this issue with Azure Load Balancers for a couple days now and am still pulling my hair out... :(

First off, I am able to log into Azure without issue using:

Login-AzureRmAccount

So, here is the situation:

External Load Balancer Multiple Front-End Pools with unique Public IP Addresses Multiple Back-End Pools with unique Private IP Addresses (with VM's in the pools) Front and Back end pools match 1:1 LBRule1 - FrontEndPool -> BackEndPool Port 80 on front and back end LBRule1 - FrontEndPool -> BackEndPool Port 443 on front and back end

Now, when trying to add another LBRule with 80/443, I cannot because it is already used. Talking to Microsoft Support, it can only be done via Powershell (I did enable/disable Floating IP as well).

Here is my script:

# Variables
$rg='ResourceGroupName'
$location='west us'
$lb=Get-AzureRmLoadBalancer -Name LBName -ResourceGroupName $rg 
$FEConfig=get-AzureRmLoadBalancerFrontendIpConfig -Name FEPoolName -LoadBalancer $lb
$fec=Get-AzureRmLoadBalancerFrontendIpConfig -Name $FEConfig.Name -LoadBalancer $lb
$BEPool=Get-AzureRmLoadBalancerBackendAddressPoolConfig -Name BEPoolName -LoadBalancer $lb
$BEP=Get-AzureRmLoadBalancerBackendAddressPoolConfig -Name $BEPool.Name -LoadBalancer $lb
$Probe=Get-AzureRmLoadBalancerProbeConfig -Name HTTP-80 -LoadBalancer $lb
$Probe1=Get-AzureRmLoadBalancerProbeConfig -Name HTTPS-443 -LoadBalancer $lb
$LBRule1=New-AzureRmLoadBalancerRuleConfig -Name APP-HTTP80 -FrontendIpConfigurationId $fec.Id -BackendAddressPoolId $BEP.Id -ProbeId $Probe.Id -Protocol Tcp -FrontendPort 80 -BackendPort 80 -EnableFloatingIP 
$LBRule2=New-AzureRmLoadBalancerRuleConfig -Name APP-HTTP443 -FrontendIpConfigurationId $fec.Id -BackendAddressPoolId $BEP.Id -ProbeId $Probe.Id -Protocol Tcp -FrontendPort 443 -BackendPort 443 -EnableFloatingIP 

# Command
$lb.LoadBalancingRules.Add($LBRule1)
$lb.LoadBalancingRules.Add($LBRule2)

Now, when I run this, nothing happens. If you use Powershell ISE to play with this, you will see that the variables will come back with the right information, but looking in the Resource Manager, no new pool is created.

So, I did some research and using the same variable set above, I put this together:

New-AzureRmLoadBalancerRuleConfig -Name $FEConfig.Name -FrontendIpConfigurationId $fec.Id -BackendAddressPoolId $BEP.Id -ProbeId $Probe.Id -Protocol Tcp -FrontendPort 80 -BackendPort 80 -EnableFloatingIP 

This does the same thing, nothing. No errors, nothing.

Anyone able to see what I am missing?

Ok, not sure why this makes the difference, but I fixed it (I guess I needed to vent and post the question). Regardless, I hope this helps someone else that is in the situation:

Add the following line to the end of the script:

$Set=Set-AzureRmLoadBalancer -LoadBalancer $lb

So the whole thing will look like:

# Variables
$rg='ResourceGroupName'
$location='west us'
$lb=Get-AzureRmLoadBalancer -Name LBName -ResourceGroupName $rg 
$FEConfig=get-AzureRmLoadBalancerFrontendIpConfig -Name FEPoolName -LoadBalancer $lb
$fec=Get-AzureRmLoadBalancerFrontendIpConfig -Name $FEConfig.Name -LoadBalancer $lb
$BEPool=Get-AzureRmLoadBalancerBackendAddressPoolConfig -Name BEPoolName -LoadBalancer $lb
$BEP=Get-AzureRmLoadBalancerBackendAddressPoolConfig -Name $BEPool.Name -LoadBalancer $lb
$Probe=Get-AzureRmLoadBalancerProbeConfig -Name HTTP-80 -LoadBalancer $lb
$Probe1=Get-AzureRmLoadBalancerProbeConfig -Name HTTPS-443 -LoadBalancer $lb
$LBRule1=New-AzureRmLoadBalancerRuleConfig -Name APP-HTTP80 -FrontendIpConfigurationId $fec.Id -BackendAddressPoolId $BEP.Id -ProbeId $Probe.Id -Protocol Tcp -FrontendPort 80 -BackendPort 80 -EnableFloatingIP 
$LBRule2=New-AzureRmLoadBalancerRuleConfig -Name APP-HTTP443 -FrontendIpConfigurationId $fec.Id -BackendAddressPoolId $BEP.Id -ProbeId $Probe.Id -Protocol Tcp -FrontendPort 443 -BackendPort 443 -EnableFloatingIP 

# Command
$lb.LoadBalancingRules.Add($LBRule1)
$lb.LoadBalancingRules.Add($LBRule2)
$Set=Set-AzureRmLoadBalancer -LoadBalancer $lb

Well, I am glad I was able to solve this and I hope this helps others. :D

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM