AzureLoadBarancerを使ってバックエンドのIISサーバへ負荷分散させる高可用な構成を作るよ。
チュートリアルを整理しつつやってみました。
https://docs.microsoft.com/ja-jp/azure/virtual-machines/windows/tutorial-load-balancer
以下のようなよくありがちな負荷分散構成を作るよ。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 |
# Azure Load Brancerの作成 PS C:\WINDOWS\system32> New-AzureRmResourceGroup ` >> -ResourceGroupName "myResourceGroupLoadBalancer" ` >> -Location "EastUS" ResourceGroupName : myResourceGroupLoadBalancer Location : eastus ProvisioningState : Succeeded Tags : ResourceId : /subscriptions/0a9f989b-cb7c-406d-a47d-48c673cc752f/resourceGroups/myResourceGroupLoadBalancer # パブリックIPの作成 PS C:\WINDOWS\system32> $publicIP = New-AzureRmPublicIpAddress ` >> -ResourceGroupName "myResourceGroupLoadBalancer" ` >> -Location "EastUS" ` >> -AllocationMethod "Static" ` >> -Name "myPublicIP" # ロードバランサ―の作成 PS C:\WINDOWS\system32> $frontendIP = New-AzureRmLoadBalancerFrontendIpConfig ` >> -Name "myFrontEndPool" ` >> -PublicIpAddress $publicIP PS C:\WINDOWS\system32> $backendPool = New-AzureRmLoadBalancerBackendAddressPoolConfig -Name "myBackEndPool" PS C:\WINDOWS\system32> $lb = New-AzureRmLoadBalancer ` >> -ResourceGroupName "myResourceGroupLoadBalancer" ` >> -Name "myLoadBalancer" ` >> -Location "EastUS" ` >> -FrontendIpConfiguration $frontendIP ` >> -BackendAddressPool $backendPool # 正常性プローブの作成 # アプリの状態を監視することができる # 80番ポートへアクセスし、200OKであることを15秒間隔でチェックし、2回失敗するとバランシング対象から除外される PS C:\WINDOWS\system32> Add-AzureRmLoadBalancerProbeConfig ` >> -Name "myHealthProbe" ` >> -LoadBalancer $lb ` >> -Protocol tcp ` >> -Port 80 ` >> -IntervalInSeconds 15 ` >> -ProbeCount 2 ResourceGroupName Name Location Sku Name ProvisioningState ----------------- ---- -------- -------- ----------------- myResourceGroupLoadBalancer myLoadBalancer eastus Basic Succeeded # 正常性プローブの適用 PS C:\WINDOWS\system32> Set-AzureRmLoadBalancer -LoadBalancer $lb ResourceGroupName Name Location Sku Name ProvisioningState ----------------- ---- -------- -------- ----------------- myResourceGroupLoadBalancer myLoadBalancer eastus Basic Succeeded # ロードバランサ―規則の作成 # フロントエンドIPやVMが構成されるバックエンドIP、ポート、使用する正常性プローブの定義を行う PS C:\WINDOWS\system32> $probe = Get-AzureRmLoadBalancerProbeConfig -LoadBalancer $lb -Name "myHealthProbe" PS C:\WINDOWS\system32> PS C:\WINDOWS\system32> Add-AzureRmLoadBalancerRuleConfig ` >> -Name "myLoadBalancerRule" ` >> -LoadBalancer $lb ` >> -FrontendIpConfiguration $lb.FrontendIpConfigurations[0] ` >> -BackendAddressPool $lb.BackendAddressPools[0] ` >> -Protocol Tcp ` >> -FrontendPort 80 ` >> -BackendPort 80 ` >> -Probe $probe ResourceGroupName Name Location Sku Name ProvisioningState ----------------- ---- -------- -------- ----------------- myResourceGroupLoadBalancer myLoadBalancer eastus Basic Succeeded # ロードバランサ―定義の更新 PS C:\WINDOWS\system32> Set-AzureRmLoadBalancer -LoadBalancer $lb ResourceGroupName Name Location Sku Name ProvisioningState ----------------- ---- -------- -------- ----------------- myResourceGroupLoadBalancer myLoadBalancer eastus Basic Succeeded # 仮想ネットワークの作成 # Create subnet config PS C:\WINDOWS\system32> $subnetConfig = New-AzureRmVirtualNetworkSubnetConfig ` >> -Name "mySubnet" ` >> -AddressPrefix 192.168.1.0/24 # Create the virtual network PS C:\WINDOWS\system32> $vnet = New-AzureRmVirtualNetwork ` >> -ResourceGroupName "myResourceGroupLoadBalancer" ` >> -Location "EastUS" ` >> -Name "myVnet" ` >> -AddressPrefix 192.168.0.0/16 ` >> -Subnet $subnetConfig 警告: Breaking changes in the cmdlet 'New-AzureRmVirtualNetwork' : 警告: - "The output type 'Microsoft.Azure.Commands.Network.Models.PSVirtualNetwork' is changing" - The following properties in the output type are being deprecated : 'EnableVmProtection' # 仮想NICの作成 PS C:\WINDOWS\system32> for ($i=1; $i -le 3; $i++) >> { >> New-AzureRmNetworkInterface ` >> -ResourceGroupName "myResourceGroupLoadBalancer" ` >> -Name myVM$i ` >> -Location "EastUS" ` >> -Subnet $vnet.Subnets[0] ` >> -LoadBalancerBackendAddressPool $lb.BackendAddressPools[0] >> } ResourceGroupName Name Location MacAddress Primary EnableAcceleratedNetworking EnableIPForwarding Provisioni ngState ----------------- ---- -------- ---------- ------- --------------------------- ------------------ ---------- myResourceGroupLoadBalancer myVM1 eastus False False Succeeded myResourceGroupLoadBalancer myVM2 eastus False False Succeeded myResourceGroupLoadBalancer myVM3 eastus False False Succeeded # 仮想マシンの作成 # 可用性セットにVMを配置する PS C:\WINDOWS\system32> $availabilitySet = New-AzureRmAvailabilitySet ` >> -ResourceGroupName "myResourceGroupLoadBalancer" ` >> -Name "myAvailabilitySet" ` >> -Location "EastUS" ` >> -Sku aligned ` >> -PlatformFaultDomainCount 2 ` >> -PlatformUpdateDomainCount 2 # 管理者の資格情報を設定 PS C:\WINDOWS\system32> $cred = Get-Credential コマンド パイプライン位置 1 のコマンドレット Get-Credential 次のパラメーターに値を指定してください: Credential # VMの作成 PS C:\WINDOWS\system32> for ($i=1; $i -le 3; $i++) >> { >> New-AzureRmVm ` >> -ResourceGroupName "myResourceGroupLoadBalancer" ` >> -Name "myVM$i" ` >> -Location "East US" ` >> -VirtualNetworkName "myVnet" ` >> -SubnetName "mySubnet" ` >> -SecurityGroupName "myNetworkSecurityGroup" ` >> -OpenPorts 80 ` >> -AvailabilitySetName "myAvailabilitySet" ` >> -Credential $cred ` >> -AsJob >> } Id Name PSJobTypeName State HasMoreData Location Command -- ---- ------------- ----- ----------- -------- ------- 6 Long Running... AzureLongRun... Running True localhost New-AzureRmVM 7 Long Running... AzureLongRun... Running True localhost New-AzureRmVM 8 Long Running... AzureLongRun... Running True localhost New-AzureRmVM PS C:\WINDOWS\system32> Get-AzureRmVM ResourceGroupName Name Location VmSize OsType NIC ProvisioningState Zone ----------------- ---- -------- ------ ------ --- ----------------- ---- MYRESOURCEGROUPLOADBALANCER myVM1 eastus Standard_DS1_v2 Windows myVM1 Succeeded MYRESOURCEGROUPLOADBALANCER myVM2 eastus Standard_DS1_v2 Windows myVM2 Succeeded MYRESOURCEGROUPLOADBALANCER myVM3 eastus Standard_DS1_v2 Windows myVM3 Succeeded # VMへのIISのインストール PS C:\WINDOWS\system32> for ($i=1; $i -le 3; $i++) >> { >> Set-AzureRmVMExtension ` >> -ResourceGroupName "myResourceGroupLoadBalancer" ` >> -ExtensionName "IIS" ` >> -VMName myVM$i ` >> -Publisher Microsoft.Compute ` >> -ExtensionType CustomScriptExtension ` >> -TypeHandlerVersion 1.8 ` >> -SettingString '{"commandToExecute":"powershell Add-WindowsFeature Web-Server; powershell Add-Content -Path \"C: \\inetpub\\wwwroot\\Default.htm\" -Value $($env:computername)"}' ` >> -Location EastUS >> } RequestId IsSuccessStatusCode StatusCode ReasonPhrase --------- ------------------- ---------- ------------ True OK OK True OK OK True OK OK # パブリックIPアドレスの確認 PS C:\WINDOWS\system32> Get-AzureRmPublicIPAddress ` >> -ResourceGroupName "myResourceGroupLoadBalancer" ` >> -Name "myPublicIP" | select IpAddress IpAddress --------- 104.45.155.158 |
数回アクセスしてみると、各VMへバランシングされていることがわかるね。
このチュートリアルとても分かりやすい(^^)