ビュー:
Azure仮想マシンスケールセット (VMSS) を使用すると、同一のVMのセットをデプロイおよび管理できます。 VMの数は、設定可能なスケーリングルールに基づいて自動的に増減できます。詳細については、 Azureの仮想マシン スケール セットとは何ですか?
エージェントが事前にインストールされ、有効化されたベース仮想マシンイメージを含めるようにVMSSを設定できます。 VMSSがスケールアップすると、スケールセット内の新しいVMインスタンスに自動的にエージェントが追加されます。
AgentをVMSSに追加するには:

手順1: (推奨) Azureアカウントを Server & Workload Protectionに追加する

Azureアカウントを Server & Workload Protectionに追加すると、そのアカウントで作成されたすべてのAzureインスタンスが Server & Workload Protection に読み込まれ、 [コンピュータ]の下に表示されます。インスタンスは、エージェントがインストールされているかどうかに関係なく表示されます。エージェントを含まないエージェントの [ステータス][Agentなし]です。 エージェントをインストールして有効化すると、 [管理対象 (オンライン)][ステータス] に変わります。
Azureアカウントの追加後にスケールセットが手動または自動でスケールアップされた場合、 Server & Workload Protection は新しいAzureインスタンスを検出し、 [コンピュータ]の下のリストに追加します。同様に、スケールセットを縮小すると、インスタンスが表示されなくなります。したがって、 Server & Workload Protection には、スケールセット内の使用可能なAzureインスタンスの現在のリストが常に表示されます。
ただし、Azureアカウントを Server & Workload Protectionに追加せずに、別の方法を使用して個々のAzureインスタンスを追加した場合、 Server & Workload Protection ではスケールダウンが検出されず、存在しないAzureインスタンスがリストから削除されることはありません。 Server & Workload Protection内のAzure仮想マシンのリストが増え続けることを防ぎ、スケールセットで使用可能なAzureインスタンスを常に正確に表示するには、Azureアカウントを Server & Workload Protectionに追加することを強くお勧めします。
Azureアカウントを追加する手順については、「 Microsoft Azureアカウントを Server & Workload Protectionに追加する

手順2: 配信スクリプトを準備する

Server & Workload Protectionで、配置スクリプトを準備します。手順については、を参照してください。インストールスクリプトを使用してコンピュータを追加および保護する。この配置スクリプトは、次に設定するカスタムスクリプト拡張機能で参照されます。
注意
注意
次のVMSSスクリプトを使用してカスタムスクリプトを実行するには、スクリプトがAzure Blob Storageまたは有効なURLを介してアクセス可能なその他の場所に格納されている必要があります。 Azure Blob Storageにファイルをアップロードする手順については、「 Azure PowerShellを使用してAzure BLOBストレージの操作を実行する

手順3: カスタムスクリプト拡張機能を使用してエージェントをVMSSインスタンスに追加する

次に、PowerShellを使用してAgentを追加する方法に関する例を示します。
  • 例1に、 エージェントを含む新しいVMSSを作成する方法を示します。
  • 例2に、既存のVMSSにエージェントを追加する方法を示します。
両方の例:
注意
注意
PowerShellコマンドレットを使用して新しいVMSSを作成する手順については、このMicrosoftチュートリアル。 Linuxプラットフォームについては、を参照してください。https://github.com/Azure/custom-script-extension-linux

例1:エージェントを含む新しいVMSSを作成する

$resourceGroupName = <The resource group of the VMSS> $vmssname = <The name of the VMSS> # Create ResourceGroup New-AzureRmResourceGroup -ResourceGroupName $resourceGroupName -Location EastUS # Create a config object $vmssConfig = New-AzureRmVmssConfig ` -Location EastUS ` -SkuCapacity 2 ` -SkuName Standard_DS2 ` -UpgradePolicyMode Automatic # Define the script for your Custom Script Extension to run on the Windows Platform $customConfig = @{ "fileUris" = (,"A URL of your copy of deployment script, ex. deploymentscript.ps1"); "commandToExecute" = "powershell -ExecutionPolicy Unrestricted -File deploymentscript.ps1" } # Define the script for your Custom Script Extension to run on the Linux Platform #$customConfig = @{ # "fileUris" = (,"A URL of your copy of deployment script, ex. deploymentscript.sh"); # "commandToExecute" = "bash deploymentscript.sh" #} # The section is required only if deploymentscript has been located within Azure StorageAccount $storageAccountName = <StorageAccountName if deploymentscript is locate in Azure Storage> $key = (Get-AzureRmStorageAccountKey -Name $storageAccountName -ResourceGroupName $resourceGroupName).Value[0] $protectedConfig = @{ "storageAccountName" = $storageAccountName; "storageAccountKey" = $key } # Use Custom Script Extension to install the agent (Windows) Add-AzureRmVmssExtension -VirtualMachineScaleSet $vmssConfig ` -Name "customScript" ` -Publisher "Microsoft.Compute" ` -Type "CustomScriptExtension" ` -TypeHandlerVersion 1.8 ` -Setting $customConfig ` -ProtectedSetting $protectedConfig # Use Custom Script Extension to install the agent (Linux) #Add-AzureRmVmssExtension -VirtualMachineScaleSet $vmssConfig ` # -Name "customScript" ` # -Publisher "Microsoft.Azure.Extensions" ` # -Type "customScript" ` # -TypeHandlerVersion 2.0 ` # -Setting $customConfig ` # -ProtectedSetting $protectedConfig # Create a public IP address # Create a frontend and backend IP pool # Create the load balancer # Create a load balancer health probe on port 80 # Create a load balancer rule to distribute traffic on port 80 # Update the load balancer configuration # Reference a virtual machine image from the gallery # Set up information for authenticating with the virtual machine # Create the virtual network resources # Attach the virtual network to the config object # Create the scale set with the config object (this step might take a few minutes) New-AzureRmVmss ` -ResourceGroupName $resourceGroupName ` -Name $vmssname ` -VirtualMachineScaleSet $vmssConfig

例2: 既存のVMSSにエージェントを追加する

$resourceGroupName = <The resource group of the VMSS> $vmssname = <The name of the VMSS> # Get the VMSS model $vmssobj = Get-AzureRmVmss -ResourceGroupName $resourceGroupName -VMScaleSetName $vmssname # Show model data if you prefer # Write-Output $vmssobj # Define the script for your Custom Script Extension to run on the Windows platform $customConfig = @{ "fileUris" = (,"A URL of your copy of deployment script, ex. deploymentscript.ps1"); "commandToExecute" = "powershell -ExecutionPolicy Unrestricted -File deploymentscript.ps1" } # Define the script for your Custom Script Extension to run on the Linux platform #$customConfig = @{ # "fileUris" = (,"A URL of your copy of deployment script, ex. deploymentscript.sh"); # "commandToExecute" = "bash deploymentscript.sh" #} # The section is required only if deploymentscript has been located within Azure StorageAccount $storageAccountName = <StorageAccountName if deploymentscript is locate in Azure Storage> $key= (Get-AzureRmStorageAccountKey -Name $storageAccountName -ResourceGroupName $resourceGroupName).Value[0] $protectedConfig = @{ "storageAccountName" = $storageAccountName; "storageAccountKey" = $key } # Use Custom Script Extension to install the agent (Windows) $newvmssobj = Add-AzureRmVmssExtension ` -VirtualMachineScaleSet $vmssobj ` -Name "customScript" ` -Publisher "Microsoft.Compute" ` -Type "CustomScriptExtension" ` -TypeHandlerVersion 1.8 ` -Setting $customConfig ` -ProtectedSetting $protectedConfig # Use Custom Script Extension to install the agent (Linux) #$newvmssobj = Add-AzureRmVmssExtension ` # -VirtualMachineScaleSet $vmssobj ` # -Name "customScript" ` # -Publisher "Microsoft.Azure.Extensions" ` # -Type "customScript" ` # -TypeHandlerVersion 2.0 ` # -Setting $customConfig ` # -ProtectedSetting $protectedConfig # Update the virtual machine scale set model Update-AzureRmVmss -ResourceGroupName $resourceGroupName -name $vmssname -VirtualMachineScaleSet $newvmssobj -Verbose # Get Instance ID for all instances in this VMSS, and decide which instance you'd like to update # Get-AzureRmVmssVM -ResourceGroupName $resourceGroupName -VMScaleSetName $vmssname # Now start updating instances # If upgradePolicy is Automatic in the VMSS, do NOT execute the next command Update-AzureRmVmssInstance. Azure will auto-update the VMSS. # There's no PowerShell command to update all instances at once. But you could refer to the output of Update-AzureRmVmss, and loop all instances into this command. Update-AzureRmVmssInstance -ResourceGroupName $resourceGroupName -VMScaleSetName $vmssname -InstanceId 0