Dela via


Open an application port in the Azure load balancer

A Service Fabric application running in Azure sits behind the Azure load balancer. This sample script opens a port in an Azure load balancer so that a Service Fabric application can communicate with external clients. Anpassa parametrarna efter behov. If your cluster is in a network security group, also add an inbound network security group rule to allow inbound traffic.

Anmärkning

Vi rekommenderar att du använder Azure Az PowerShell-modulen för att interagera med Azure. Se Installera Azure PowerShell för att komma igång. Information om hur du migrerar till Az PowerShell-modulen finns i Migrera Azure PowerShell från AzureRM till Az.

Om det behövs installerar du Service Fabric PowerShell-modulen med Service Fabric SDK.

Exempelskript

# Variables
$probename = "AppPortProbe6"
$rulename="AppPortLBRule6"
$RGname="mysftestclustergroup"
$port=8303
$subscriptionID = 'subscription ID'

# Login and select your subscription
Connect-AzAccount
Get-AzSubscription -SubscriptionId $subscriptionID | Select-AzSubscription 

# Get the load balancer resource
$resource = Get-AzResource | Where {$_.ResourceGroupName –eq $RGname -and $_.ResourceType -eq "Microsoft.Network/loadBalancers"} 
$slb = Get-AzLoadBalancer -Name $resource.Name -ResourceGroupName $RGname

# Add a new probe configuration to the load balancer
$slb | Add-AzLoadBalancerProbeConfig -Name $probename -Protocol Tcp -Port $port -IntervalInSeconds 15 -ProbeCount 2

# Add rule configuration to the load balancer
$probe = Get-AzLoadBalancerProbeConfig -Name $probename -LoadBalancer $slb
$slb | Add-AzLoadBalancerRuleConfig -Name $rulename -BackendAddressPool $slb.BackendAddressPools[0] -FrontendIpConfiguration $slb.FrontendIpConfigurations[0] -Probe $probe -Protocol Tcp -FrontendPort $port -BackendPort $port

# Set the goal state for the load balancer
$slb | Set-AzLoadBalancer

Förklaring av skript

Det här skriptet använder följande kommandon. Varje kommando i tabellen länkar till kommandospecifik dokumentation.

Befallning Noteringar
Get-AzResource Gets an Azure resource.
Get-AzLoadBalancer Gets the Azure load balancer.
Add-AzLoadBalancerProbeConfig Adds a probe configuration to a load balancer.
Get-AzLoadBalancerProbeConfig Gets a probe configuration for a load balancer.
Add-AzLoadBalancerRuleConfig Adds a rule configuration to a load balancer.
Set-AzLoadBalancer Sets the goal state for a load balancer.

Nästa steg

Mer information om Azure PowerShell-modulen finns i Azure PowerShell-dokumentationen.

Ytterligare PowerShell-exempel för Azure Service Fabric finns i Azure PowerShell-exemplen.