简体   繁体   English

Azure外部负载平衡器-使用PowerShell添加LB规则

[英]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... :( 我已经使用Azure负载平衡器解决了这一问题已有两天了,但仍在继续努力... :(

First off, I am able to log into Azure without issue using: 首先,我可以使用以下命令登录到Azure,而不会出现问题:

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 外部负载均衡器多个具有唯一公共IP地址的前端池多个具有唯一私有IP地址的后端池(池中有VM)前端和后端池与1:1 LBRule1-FrontEndPool-> BackEndPool端口80匹配后端LBRule1-FrontEndPool->后端上的BackEndPool端口443

Now, when trying to add another LBRule with 80/443, I cannot because it is already used. 现在,当尝试使用80/443添加另一个LBRule时,我不能,因为它已被使用。 Talking to Microsoft Support, it can only be done via Powershell (I did enable/disable Floating IP as well). 与Microsoft支持人员联系时,只能通过Powershell来完成(我也启用/禁用了浮动IP)。

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. 如果您使用Powershell ISE进行此操作,您将看到变量将返回正确的信息,但是在资源管理器中,不会创建新池。

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 :D

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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