クイック スタート: ARM テンプレートを使用して VM の負荷を分散するパブリック ロード バランサーを作成する
負荷分散では、着信要求を複数の仮想マシン (VM) に分散させることで、より高いレベルの可用性とスケールを実現します。
このクイックスタートでは、仮想マシンを負荷分散するために標準のロード バランサーをデプロイする方法を説明します。
ARM テンプレートを使用すると、他のデプロイ方法より手順が減ります。
Azure Resource Manager テンプレートは JavaScript Object Notation (JSON) ファイルであり、プロジェクトのインフラストラクチャと構成が定義されています。 このテンプレートでは、宣言型の構文が使用されています。 デプロイしようとしているものを、デプロイを作成する一連のプログラミング コマンドを記述しなくても記述できます。
環境が前提条件を満たしていて、ARM テンプレートの使用に慣れている場合は、 [Azure へのデプロイ] ボタンを選択します。 Azure portal でテンプレートが開きます。
前提条件
Azure サブスクリプションをお持ちでない場合は、開始する前に 無料アカウント を作成してください。
テンプレートを確認する
このクイックスタートで使用されるテンプレートは Azure クイックスタート テンプレートからのものです。
ロード バランサーとパブリック IP の SKU は一致している必要があります。 標準のロード バランサーを作成するときに、標準のロード バランサーのフロントエンドとして構成されている新しい標準パブリック IP アドレスも作成する必要があります。 標準のロード バランサーを作成する場合は、このテンプレートを使用します。 運用環境のワークロードには標準 SKU の使用をお勧めします。
{
"$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentTemplate.json#",
"contentVersion": "1.0.0.0",
"metadata": {
"_generator": {
"name": "bicep",
"version": "0.26.54.24096",
"templateHash": "14680538243429534307"
}
},
"parameters": {
"projectName": {
"type": "string",
"metadata": {
"description": "Specifies a project name that is used for generating resource names."
}
},
"location": {
"type": "string",
"defaultValue": "[resourceGroup().location]",
"metadata": {
"description": "Specifies the location for all of the resources created by this template."
}
},
"adminUsername": {
"type": "string",
"metadata": {
"description": "Specifies the virtual machine administrator username."
}
},
"adminPassword": {
"type": "securestring",
"metadata": {
"description": "Specifies the virtual machine administrator password."
}
},
"vmSize": {
"type": "string",
"defaultValue": "Standard_D2s_v3",
"metadata": {
"description": "Size of the virtual machine"
}
},
"OSVersion": {
"type": "string",
"defaultValue": "2022-datacenter-azure-edition",
"allowedValues": [
"2016-datacenter-gensecond",
"2016-datacenter-server-core-g2",
"2016-datacenter-server-core-smalldisk-g2",
"2016-datacenter-smalldisk-g2",
"2016-datacenter-with-containers-g2",
"2016-datacenter-zhcn-g2",
"2019-datacenter-core-g2",
"2019-datacenter-core-smalldisk-g2",
"2019-datacenter-core-with-containers-g2",
"2019-datacenter-core-with-containers-smalldisk-g2",
"2019-datacenter-gensecond",
"2019-datacenter-smalldisk-g2",
"2019-datacenter-with-containers-g2",
"2019-datacenter-with-containers-smalldisk-g2",
"2019-datacenter-zhcn-g2",
"2022-datacenter-azure-edition",
"2022-datacenter-azure-edition-core",
"2022-datacenter-azure-edition-core-smalldisk",
"2022-datacenter-azure-edition-smalldisk",
"2022-datacenter-core-g2",
"2022-datacenter-core-smalldisk-g2",
"2022-datacenter-g2",
"2022-datacenter-smalldisk-g2"
],
"metadata": {
"description": "The Windows version for the VM. This will pick a fully patched image of this given Windows version."
}
},
"imageSku": {
"type": "string",
"defaultValue": "vs-2019-ent-latest-win11-n-gen2",
"allowedValues": [
"vs-2019-ent-latest-win11-n-gen2",
"vs-2019-pro-general-win11-m365-gen2",
"vs-2019-comm-latest-win11-n-gen2",
"vs-2019-ent-general-win10-m365-gen2",
"vs-2019-ent-general-win11-m365-gen2",
"vs-2019-pro-general-win10-m365-gen2"
],
"metadata": {
"description": "Linux Sku"
}
},
"securityType": {
"type": "string",
"defaultValue": "TrustedLaunch",
"allowedValues": [
"Standard",
"TrustedLaunch"
],
"metadata": {
"description": "Security Type of the Virtual Machine."
}
}
},
"variables": {
"securityProfileJson": {
"uefiSettings": {
"secureBootEnabled": true,
"vTpmEnabled": true
},
"securityType": "[parameters('securityType')]"
},
"lbName": "[format('{0}-lb', parameters('projectName'))]",
"lbSkuName": "Standard",
"lbPublicIpAddressName": "[format('{0}-lbPublicIP', parameters('projectName'))]",
"lbFrontEndName": "LoadBalancerFrontEnd",
"lbBackendPoolName": "LoadBalancerBackEndPool",
"lbProbeName": "loadBalancerHealthProbe",
"nsgName": "[format('{0}-nsg', parameters('projectName'))]",
"vNetName": "[format('{0}-vnet', parameters('projectName'))]",
"vNetAddressPrefix": "10.0.0.0/16",
"vNetSubnetName": "BackendSubnet",
"vNetSubnetAddressPrefix": "10.0.0.0/24",
"bastionName": "[format('{0}-bastion', parameters('projectName'))]",
"bastionSubnetName": "AzureBastionSubnet",
"vNetBastionSubnetAddressPrefix": "10.0.1.0/24",
"bastionPublicIPAddressName": "[format('{0}-bastionPublicIP', parameters('projectName'))]",
"vmStorageAccountType": "Premium_LRS",
"extensionName": "GuestAttestation",
"extensionPublisher": "Microsoft.Azure.Security.WindowsAttestation",
"extensionVersion": "1.0",
"maaTenantName": "GuestAttestation",
"maaEndpoint": "[substring('emptyString', 0, 0)]",
"ascReportingEndpoint": "[substring('emptystring', 0, 0)]",
"natGatewayName": "[format('{0}-natgateway', parameters('projectName'))]",
"natGatewayPublicIPAddressName": "[format('{0}-natPublicIP', parameters('projectName'))]"
},
"resources": [
{
"copy": {
"name": "project_vm_1_networkInterface",
"count": "[length(range(0, 3))]"
},
"type": "Microsoft.Network/networkInterfaces",
"apiVersion": "2021-08-01",
"name": "[format('{0}-vm{1}-networkInterface', parameters('projectName'), add(range(0, 3)[copyIndex()], 1))]",
"location": "[parameters('location')]",
"properties": {
"ipConfigurations": [
{
"name": "ipconfig1",
"properties": {
"privateIPAllocationMethod": "Dynamic",
"subnet": {
"id": "[resourceId('Microsoft.Network/virtualNetworks/subnets', variables('vNetName'), variables('vNetSubnetName'))]"
},
"loadBalancerBackendAddressPools": [
{
"id": "[resourceId('Microsoft.Network/loadBalancers/backendAddressPools', variables('lbName'), variables('lbBackendPoolName'))]"
}
]
}
}
],
"networkSecurityGroup": {
"id": "[resourceId('Microsoft.Network/networkSecurityGroups', variables('nsgName'))]"
}
},
"dependsOn": [
"[resourceId('Microsoft.Network/loadBalancers', variables('lbName'))]",
"[resourceId('Microsoft.Network/networkSecurityGroups', variables('nsgName'))]",
"[resourceId('Microsoft.Network/virtualNetworks/subnets', variables('vNetName'), variables('vNetSubnetName'))]"
]
},
{
"copy": {
"name": "project_vm_1_InstallWebServer",
"count": "[length(range(0, 3))]"
},
"type": "Microsoft.Compute/virtualMachines/extensions",
"apiVersion": "2021-11-01",
"name": "[format('{0}-vm{1}/InstallWebServer', parameters('projectName'), add(range(0, 3)[copyIndex()], 1))]",
"location": "[parameters('location')]",
"properties": {
"publisher": "Microsoft.Compute",
"type": "CustomScriptExtension",
"typeHandlerVersion": "1.10",
"autoUpgradeMinorVersion": true,
"settings": {
"commandToExecute": "powershell.exe Install-WindowsFeature -name Web-Server -IncludeManagementTools && powershell.exe remove-item 'C:\\inetpub\\wwwroot\\iisstart.htm' && powershell.exe Add-Content -Path 'C:\\inetpub\\wwwroot\\iisstart.htm' -Value $('Hello World from ' + $env:computername)"
}
},
"dependsOn": [
"project_vm_1"
]
},
{
"copy": {
"name": "project_vm_1",
"count": "[length(range(1, 3))]"
},
"type": "Microsoft.Compute/virtualMachines",
"apiVersion": "2021-11-01",
"name": "[format('{0}-vm{1}', parameters('projectName'), range(1, 3)[copyIndex()])]",
"location": "[parameters('location')]",
"zones": [
"[string(range(1, 3)[copyIndex()])]"
],
"properties": {
"hardwareProfile": {
"vmSize": "[parameters('vmSize')]"
},
"storageProfile": {
"imageReference": {
"publisher": "MicrosoftWindowsServer",
"offer": "WindowsServer",
"sku": "[parameters('OSVersion')]",
"version": "latest"
},
"osDisk": {
"createOption": "FromImage",
"managedDisk": {
"storageAccountType": "[variables('vmStorageAccountType')]"
}
}
},
"networkProfile": {
"networkInterfaces": [
{
"id": "[resourceId('Microsoft.Network/networkInterfaces', format('{0}-vm{1}-networkInterface', parameters('projectName'), range(1, 3)[copyIndex()]))]"
}
]
},
"osProfile": {
"computerName": "[format('{0}-vm{1}', parameters('projectName'), range(1, 3)[copyIndex()])]",
"adminUsername": "[parameters('adminUsername')]",
"adminPassword": "[parameters('adminPassword')]",
"windowsConfiguration": {
"enableAutomaticUpdates": true,
"provisionVMAgent": true
}
},
"securityProfile": "[if(equals(parameters('securityType'), 'TrustedLaunch'), variables('securityProfileJson'), null())]"
},
"dependsOn": [
"project_vm_1_networkInterface"
]
},
{
"copy": {
"name": "projectName_vm_1_3_GuestAttestation",
"count": "[length(range(1, 3))]"
},
"condition": "[and(equals(parameters('securityType'), 'TrustedLaunch'), and(equals(variables('securityProfileJson').uefiSettings.secureBootEnabled, true()), equals(variables('securityProfileJson').uefiSettings.vTpmEnabled, true())))]",
"type": "Microsoft.Compute/virtualMachines/extensions",
"apiVersion": "2022-03-01",
"name": "[format('{0}-vm{1}/GuestAttestation', parameters('projectName'), range(1, 3)[copyIndex()])]",
"location": "[parameters('location')]",
"properties": {
"publisher": "[variables('extensionPublisher')]",
"type": "[variables('extensionName')]",
"typeHandlerVersion": "[variables('extensionVersion')]",
"autoUpgradeMinorVersion": true,
"enableAutomaticUpgrade": true,
"settings": {
"AttestationConfig": {
"MaaSettings": {
"maaEndpoint": "[variables('maaEndpoint')]",
"maaTenantName": "[variables('maaTenantName')]"
},
"AscSettings": {
"ascReportingEndpoint": "[variables('ascReportingEndpoint')]",
"ascReportingFrequency": ""
},
"useCustomToken": "false",
"disableAlerts": "false"
}
}
},
"dependsOn": [
"project_vm_1"
]
},
{
"type": "Microsoft.Network/natGateways",
"apiVersion": "2021-05-01",
"name": "[variables('natGatewayName')]",
"location": "[parameters('location')]",
"sku": {
"name": "Standard"
},
"properties": {
"idleTimeoutInMinutes": 4,
"publicIpAddresses": [
{
"id": "[resourceId('Microsoft.Network/publicIPAddresses', variables('natGatewayPublicIPAddressName'))]"
}
]
},
"dependsOn": [
"[resourceId('Microsoft.Network/publicIPAddresses', variables('natGatewayPublicIPAddressName'))]"
]
},
{
"type": "Microsoft.Network/publicIPAddresses",
"apiVersion": "2021-05-01",
"name": "[variables('natGatewayPublicIPAddressName')]",
"location": "[parameters('location')]",
"sku": {
"name": "Standard"
},
"properties": {
"publicIPAddressVersion": "IPv4",
"publicIPAllocationMethod": "Static",
"idleTimeoutInMinutes": 4
}
},
{
"type": "Microsoft.Network/virtualNetworks/subnets",
"apiVersion": "2021-08-01",
"name": "[format('{0}/{1}', variables('vNetName'), variables('bastionSubnetName'))]",
"properties": {
"addressPrefix": "[variables('vNetBastionSubnetAddressPrefix')]"
},
"dependsOn": [
"[resourceId('Microsoft.Network/virtualNetworks', variables('vNetName'))]",
"[resourceId('Microsoft.Network/virtualNetworks/subnets', variables('vNetName'), variables('vNetSubnetName'))]"
]
},
{
"type": "Microsoft.Network/virtualNetworks/subnets",
"apiVersion": "2021-08-01",
"name": "[format('{0}/{1}', variables('vNetName'), variables('vNetSubnetName'))]",
"properties": {
"addressPrefix": "[variables('vNetSubnetAddressPrefix')]",
"natGateway": {
"id": "[resourceId('Microsoft.Network/natGateways', variables('natGatewayName'))]"
}
},
"dependsOn": [
"[resourceId('Microsoft.Network/natGateways', variables('natGatewayName'))]",
"[resourceId('Microsoft.Network/virtualNetworks', variables('vNetName'))]"
]
},
{
"type": "Microsoft.Network/bastionHosts",
"apiVersion": "2021-08-01",
"name": "[variables('bastionName')]",
"location": "[parameters('location')]",
"properties": {
"ipConfigurations": [
{
"name": "IpConf",
"properties": {
"privateIPAllocationMethod": "Dynamic",
"publicIPAddress": {
"id": "[resourceId('Microsoft.Network/publicIPAddresses', variables('bastionPublicIPAddressName'))]"
},
"subnet": {
"id": "[resourceId('Microsoft.Network/virtualNetworks/subnets', variables('vNetName'), variables('bastionSubnetName'))]"
}
}
}
]
},
"dependsOn": [
"[resourceId('Microsoft.Network/publicIPAddresses', variables('bastionPublicIPAddressName'))]",
"[resourceId('Microsoft.Network/virtualNetworks/subnets', variables('vNetName'), variables('bastionSubnetName'))]"
]
},
{
"type": "Microsoft.Network/publicIPAddresses",
"apiVersion": "2021-08-01",
"name": "[variables('bastionPublicIPAddressName')]",
"location": "[parameters('location')]",
"sku": {
"name": "[variables('lbSkuName')]"
},
"properties": {
"publicIPAddressVersion": "IPv4",
"publicIPAllocationMethod": "Static"
}
},
{
"type": "Microsoft.Network/loadBalancers",
"apiVersion": "2021-08-01",
"name": "[variables('lbName')]",
"location": "[parameters('location')]",
"sku": {
"name": "[variables('lbSkuName')]"
},
"properties": {
"frontendIPConfigurations": [
{
"name": "[variables('lbFrontEndName')]",
"properties": {
"publicIPAddress": {
"id": "[resourceId('Microsoft.Network/publicIPAddresses', variables('lbPublicIpAddressName'))]"
}
}
}
],
"backendAddressPools": [
{
"name": "[variables('lbBackendPoolName')]"
}
],
"loadBalancingRules": [
{
"name": "myHTTPRule",
"properties": {
"frontendIPConfiguration": {
"id": "[resourceId('Microsoft.Network/loadBalancers/frontendIPConfigurations', variables('lbName'), variables('lbFrontEndName'))]"
},
"backendAddressPool": {
"id": "[resourceId('Microsoft.Network/loadBalancers/backendAddressPools', variables('lbName'), variables('lbBackendPoolName'))]"
},
"frontendPort": 80,
"backendPort": 80,
"enableFloatingIP": false,
"idleTimeoutInMinutes": 15,
"protocol": "Tcp",
"enableTcpReset": true,
"loadDistribution": "Default",
"disableOutboundSnat": true,
"probe": {
"id": "[resourceId('Microsoft.Network/loadBalancers/probes', variables('lbName'), variables('lbProbeName'))]"
}
}
}
],
"probes": [
{
"name": "[variables('lbProbeName')]",
"properties": {
"protocol": "Tcp",
"port": 80,
"intervalInSeconds": 5,
"numberOfProbes": 2
}
}
],
"outboundRules": []
},
"dependsOn": [
"[resourceId('Microsoft.Network/publicIPAddresses', variables('lbPublicIpAddressName'))]"
]
},
{
"type": "Microsoft.Network/publicIPAddresses",
"apiVersion": "2021-08-01",
"name": "[variables('lbPublicIpAddressName')]",
"location": "[parameters('location')]",
"sku": {
"name": "[variables('lbSkuName')]"
},
"properties": {
"publicIPAddressVersion": "IPv4",
"publicIPAllocationMethod": "Static"
}
},
{
"type": "Microsoft.Network/networkSecurityGroups",
"apiVersion": "2021-08-01",
"name": "[variables('nsgName')]",
"location": "[parameters('location')]",
"properties": {
"securityRules": [
{
"name": "AllowHTTPInbound",
"properties": {
"protocol": "*",
"sourcePortRange": "*",
"destinationPortRange": "80",
"sourceAddressPrefix": "Internet",
"destinationAddressPrefix": "*",
"access": "Allow",
"priority": 100,
"direction": "Inbound"
}
}
]
}
},
{
"type": "Microsoft.Network/virtualNetworks",
"apiVersion": "2021-08-01",
"name": "[variables('vNetName')]",
"location": "[parameters('location')]",
"properties": {
"addressSpace": {
"addressPrefixes": [
"[variables('vNetAddressPrefix')]"
]
}
}
}
],
"outputs": {
"location": {
"type": "string",
"value": "[parameters('location')]"
},
"name": {
"type": "string",
"value": "[variables('lbName')]"
},
"resourceGroupName": {
"type": "string",
"value": "[resourceGroup().name]"
},
"resourceId": {
"type": "string",
"value": "[resourceId('Microsoft.Network/loadBalancers', variables('lbName'))]"
}
}
}
テンプレートでは、複数の Azure リソースが定義されています。
- Microsoft.Network/loadBalancers
- Microsoft.Network/publicIPAddresses: ロード バランサー、bastion ホスト、NAT ゲートウェイ用。
- Microsoft.Network/bastionHosts
- Microsoft.Network/networkSecurityGroups
- Microsoft.Network/virtualNetworks
- Microsoft.Compute/virtualMachines (3)。
- Microsoft.Network/networkInterfaces (3)。
- Microsoft.Compute/virtualMachine/extensions (3): Internet Information Server (IIS) と Web ページの構成に使用。
- Microsoft.Network/natGateways: NAT ゲートウェイ用。
重要
時間単位の料金は、送信データの使用量に関係なく、Bastion がデプロイされた時点から発生します。 詳しくは、「価格」および「SKU」を参照してください。 チュートリアルまたはテストの一環として Bastion をデプロイしている場合は、使用終了後にこのリソースを削除することをお勧めします。
Azure Load Balancer に関連するテンプレートをさらに探すには、「Azure クイックスタート テンプレート」を参照してください。
テンプレートのデプロイ
次のコード ブロックの [使ってみる] を選択して Azure Cloud Shell を開き、指示に従って Azure にサインインします。
$projectName = Read-Host -Prompt "Enter a project name with 12 or less letters or numbers that is used to generate Azure resource names" $location = Read-Host -Prompt "Enter the location (i.e. centralus)" $adminUserName = Read-Host -Prompt "Enter the virtual machine administrator account name" $adminPassword = Read-Host -Prompt "Enter the virtual machine administrator password" -AsSecureString $resourceGroupName = "${projectName}rg" $templateUri = "https://raw.githubusercontent.com/Azure/azure-quickstart-templates/master/quickstarts/microsoft.network/load-balancer-standard-create/azuredeploy.json" New-AzResourceGroup -Name $resourceGroupName -Location $location New-AzResourceGroupDeployment -ResourceGroupName $resourceGroupName -TemplateUri $templateUri -projectName $projectName -location $location -adminUsername $adminUsername -adminPassword $adminPassword Write-Host "Press [ENTER] to continue."
コンソールからプロンプトが表示されるまで待ちます。
前のコード ブロックから [コピー] を選択して、PowerShell スクリプトをコピーします。
シェル コンソール ウィンドウを右クリックし、 [貼り付け] を選択します。
値を入力します。
テンプレートのデプロイによって、3 つの可用性ゾーンが作成されます。 可用性ゾーンは特定のリージョンでのみサポートされています。 サポートされているリージョンのいずれかを使用します。 よくわからない場合は、「centralus」と入力します。
リソース グループの名前は、
rg
が付加されたプロジェクト名です。 次のセクションでリソース グループ名が必要になります。
テンプレートのデプロイには約 10 分かかります。 完了すると、次のように出力されます。
テンプレートをデプロイするには Azure PowerShell を使用します。 Azure portal、Azure CLI、および REST API を使用することもできます。 他のデプロイ方法については、「テンプレートのデプロイ」を参照してください。
デプロイされているリソースを確認する
Azure portal にサインインします。
左側のウィンドウから [リソース グループ] を選択します。
前のセクションで作成したリソース グループを選択します 既定のリソース グループ名は、プロジェクト名に -rg が追加されたものです。
ロード バランサーを選択します。 既定の名前は、プロジェクト名に -lb が追加されたものです。
パブリック IP アドレスの IP アドレス部分のみをコピーして、ブラウザーのアドレス バーに貼り付けます。
ブラウザーにはインターネット インフォメーション サービス (IIS) Web サーバーの既定ページが表示されます。
ロード バランサーが 3 つの VM すべての間でトラフィックを分散していることを確認するには、クライアント マシンから Web ブラウザーを強制的に最新の情報に更新します。
リソースをクリーンアップする
それらが不要になったら、以下を削除します。
- Resource group
- Load Balancer
- 関連資料
Azure portal に移動し、ロード バランサーを含むリソース グループを選択し、 [リソース グループの削除] を選択します。
次のステップ
このクイック スタートでは次の作業を行います。
- ロード バランサーと仮想マシン用の仮想ネットワークを作成しました。
- 管理用の Azure Bastion ホストを作成しました。
- 標準のロード バランサーを作成し、それに VM をアタッチしました。
- ロード バランサーのトラフィック規則と正常性プローブを構成しました。
- ロード バランサーをテストしました。
さらに学習するには、Azure Load Balancer に関するチュートリアルに進みます。