簡體   English   中英

Azure外部負載平衡器-使用PowerShell添加LB規則

[英]Azure External Load Balancer - Adding LB Rules with PowerShell

我已經使用Azure負載平衡器解決了這一問題已有兩天了,但仍在繼續努力... :(

首先,我可以使用以下命令登錄到Azure,而不會出現問題:

Login-AzureRmAccount

因此,情況如下:

外部負載均衡器多個具有唯一公共IP地址的前端池多個具有唯一私有IP地址的后端池(池中有VM)前端和后端池與1:1 LBRule1-FrontEndPool-> BackEndPool端口80匹配后端LBRule1-FrontEndPool->后端上的BackEndPool端口443

現在,當嘗試使用80/443添加另一個LBRule時,我不能,因為它已被使用。 與Microsoft支持人員聯系時,只能通過Powershell來完成(我也啟用/禁用了浮動IP)。

這是我的腳本:

# 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)

現在,當我運行此命令時,什么也沒發生。 如果您使用Powershell ISE進行此操作,您將看到變量將返回正確的信息,但是在資源管理器中,不會創建新池。

因此,我進行了一些研究,並使用與上面相同的變量集,將它們放在一起:

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

這做同樣的事情,什么也沒做。 沒有錯誤,沒事。

有人能看到我所缺少的嗎?

好的,不確定為什么會有所不同,但我已將其修復(我想我需要宣泄並發布問題)。 無論如何,我希望這可以幫助處於這種情況的其他人:

將以下行添加到腳本的末尾:

$Set=Set-AzureRmLoadBalancer -LoadBalancer $lb

所以整個事情看起來像:

# 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

好吧,我很高興能夠解決此問題,希望對其他人有所幫助。 :D

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM