|
| 1 | +--- |
| 2 | +title: include file |
| 3 | +description: include file |
| 4 | +services: load-balancer |
| 5 | +ms.service: sap-on-azure |
| 6 | +ms.topic: include |
| 7 | +ms.date: 01/10/2024 |
| 8 | +author: dennispadia |
| 9 | +ms.author: depadia |
| 10 | +--- |
| 11 | + |
| 12 | +```azurecli-interactive |
| 13 | +# Create frontend IP configurations |
| 14 | +$db_fip = New-AzLoadBalancerFrontendIpConfig -Name MyDBFrontendIpName -SubnetId MyDBSubnetName |
| 15 | +
|
| 16 | +# Create backend pool |
| 17 | +$bePool = New-AzLoadBalancerBackendAddressPoolConfig -Name MyBackendPool |
| 18 | +
|
| 19 | +# Create health probes for ASCS and ERS |
| 20 | +$db_healthprobe = New-AzLoadBalancerProbeConfig -Name MyDBHealthProbe -Protocol 'tcp' -Port MyDBHealthProbePort -IntervalInSeconds 5 -ProbeThreshold 2 -ProbeCount 1 |
| 21 | +
|
| 22 | +# Create load balancing rules for ASCS and ERS |
| 23 | +$db_rule = New-AzLoadBalancerRuleConfig -Name MyDBRuleName -Probe $db_healthprobe -Protocol 'All' -IdleTimeoutInMinutes 30 -FrontendIpConfiguration $db_fip -BackendAddressPool $bePool -EnableFloatingIP |
| 24 | +
|
| 25 | +# Create the load balancer resource |
| 26 | +$lb = New-AzLoadBalancer -ResourceGroupName MyResourceGroup -Name MyLB -Location MyRegion -Sku 'Standard' -FrontendIpConfiguration $db_fip -BackendAddressPool $bePool -LoadBalancingRule $db_rule -Probe $db_healthprobe |
| 27 | +``` |
| 28 | + |
| 29 | +<details> |
| 30 | +<summary>Expand to view full PowerShell code</summary> |
| 31 | + |
| 32 | +```azurepowershell-interactive |
| 33 | +# Define variables for Resource Group, and Database VMs. |
| 34 | +
|
| 35 | +$rg_name = 'resourcegroup-name' |
| 36 | +$vm1_name = 'db1-name' |
| 37 | +$vm2_name = 'db2-name' |
| 38 | +
|
| 39 | +# Define variables for the load balancer that will be utilized in the creation of the load balancer resource. |
| 40 | +
|
| 41 | +$lb_name = 'sap-db-sid-ilb' |
| 42 | +$bkp_name = 'db-backendpool' |
| 43 | +$db_fip_name = 'db-frontendip' |
| 44 | + |
| 45 | +$db_hp_name = 'db-healthprobe' |
| 46 | +$db_hp_port = '625<instance-no>' |
| 47 | + |
| 48 | +$db_rule_name = 'db-lb-rule' |
| 49 | + |
| 50 | +# Command to get VMs network information like primary NIC name, primary IP configuration name, virtual network name, and subnet name. |
| 51 | + |
| 52 | +$vm1 = Get-AzVM -ResourceGroupName $rg_name -Name $vm1_name |
| 53 | +$vm1_primarynic = $vm1.NetworkProfile.NetworkInterfaces | Where-Object {($_.Primary -eq "True") -or ($_.Primary -eq $null)} |
| 54 | +$vm1_nic_name = $vm1_primarynic.Id.Split('/')[-1] |
| 55 | + |
| 56 | +$vm1_nic_info = Get-AzNetworkInterface -Name $vm1_nic_name -ResourceGroupName $rg_name |
| 57 | +$vm1_primaryip = $vm1_nic_info.IpConfigurations | Where-Object -Property Primary -EQ -Value "True" |
| 58 | +$vm1_ipconfig_name = ($vm1_primaryip).Name |
| 59 | + |
| 60 | +$vm2 = Get-AzVM -ResourceGroupName $rg_name -Name $vm2_name |
| 61 | +$vm2_primarynic = $vm2.NetworkProfile.NetworkInterfaces | Where-Object {($_.Primary -eq "True") -or ($_.Primary -eq $null)} |
| 62 | +$vm2_nic_name = $vm2_primarynic.Id.Split('/')[-1] |
| 63 | + |
| 64 | +$vm2_nic_info = Get-AzNetworkInterface -Name $vm2_nic_name -ResourceGroupName $rg_name |
| 65 | +$vm2_primaryip = $vm2_nic_info.IpConfigurations | Where-Object -Property Primary -EQ -Value "True" |
| 66 | +$vm2_ipconfig_name = ($vm2_primaryip).Name |
| 67 | + |
| 68 | +$vnet_name = $vm1_primaryip.Subnet.Id.Split('/')[-3] |
| 69 | +$subnet_name = $vm1_primaryip.Subnet.Id.Split('/')[-1] |
| 70 | +$location = $vm1.Location |
| 71 | + |
| 72 | +# Create frontend IP resource. |
| 73 | +# Allocation of private IP address is dynamic using below command. If you want to pass static IP address, include parameter -PrivateIpAddress |
| 74 | + |
| 75 | +$db_lb_fip = @{ |
| 76 | + Name = $db_fip_name |
| 77 | + SubnetId = $vm1_primaryip.Subnet.Id |
| 78 | +} |
| 79 | +$db_fip = New-AzLoadBalancerFrontendIpConfig @db_lb_fip |
| 80 | +
|
| 81 | +# Create backend pool |
| 82 | + |
| 83 | +$bepool = New-AzLoadBalancerBackendAddressPoolConfig -Name $bkp_name |
| 84 | +
|
| 85 | +# Create the health probe |
| 86 | + |
| 87 | +$db_probe = @{ |
| 88 | + Name = $db_hp_name |
| 89 | + Protocol = 'tcp' |
| 90 | + Port = $db_hp_port |
| 91 | + IntervalInSeconds = '5' |
| 92 | + ProbeThreshold = '2' |
| 93 | + ProbeCount = '1' |
| 94 | +} |
| 95 | +$db_healthprobe = New-AzLoadBalancerProbeConfig @db_probe |
| 96 | + |
| 97 | +# Create load balancing rule |
| 98 | + |
| 99 | +$db_lbrule = @{ |
| 100 | + Name = $db_rule_name |
| 101 | + Probe = $db_healthprobe |
| 102 | + Protocol = 'All' |
| 103 | + IdleTimeoutInMinutes = '30' |
| 104 | + FrontendIpConfiguration = $db_fip |
| 105 | + BackendAddressPool = $bePool |
| 106 | +} |
| 107 | +$db_rule = New-AzLoadBalancerRuleConfig @db_lbrule -EnableFloatingIP |
| 108 | + |
| 109 | +# Create the load balancer resource |
| 110 | + |
| 111 | +$loadbalancer = @{ |
| 112 | + ResourceGroupName = $rg_name |
| 113 | + Name = $lb_name |
| 114 | + Location = $location |
| 115 | + Sku = 'Standard' |
| 116 | + FrontendIpConfiguration = $db_fip |
| 117 | + BackendAddressPool = $bePool |
| 118 | + LoadBalancingRule = $db_rule |
| 119 | + Probe = $db_healthprobe |
| 120 | +} |
| 121 | +$lb = New-AzLoadBalancer @loadbalancer |
| 122 | +
|
| 123 | +# Add DB VMs in backend pool |
| 124 | + |
| 125 | +$vm1_primaryip.LoadBalancerBackendAddressPools.Add($lb.BackendAddressPools[0]) |
| 126 | +$vm2_primaryip.LoadBalancerBackendAddressPools.Add($lb.BackendAddressPools[0]) |
| 127 | +$vm1_nic_info | Set-AzNetworkInterface |
| 128 | +$vm2_nic_info | Set-AzNetworkInterface |
| 129 | +``` |
| 130 | + |
| 131 | +</details> |
0 commit comments