Azure Monitor エージェントを管理する
[アーティクル]
10/24/2023
25 人の共同作成者
フィードバック
この記事の内容
この記事では、Azure Monitor エージェント をインストール、アンインストール、および更新するために現在使用できるさまざまなオプションについて説明します。 このエージェント拡張機能は、Azure 仮想マシン、スケール セット、および Azure Arc 対応サーバーにインストールできます。 また、エージェントが収集するデータを定義するデータ収集ルールとの関連付け を作成するためのオプションも示します。 Azure Monitor エージェントをインストール、アップグレード、アンインストールする場合、サーバーを再起動する必要はありません。
仮想マシン拡張機能の詳細
Azure Monitor エージェントは Azure VM 拡張機能 として実装されます。次の表に詳細を示します。 この記事で説明されている方法を含め、仮想マシン拡張機能をインストールする、どの方法でもインストールできます。
拡張機能のバージョン
Azure Monitor エージェント拡張機能のバージョン を確認します。
前提条件
Azure Monitor エージェントをインストールする前に、次の前提条件を満たす必要があります。
アクセス許可 : Azure portal 以外の方法でエージェントをインストールする場合は、次のロールの割り当てが必要です。
組み込みのロール
スコープ
理由
仮想マシン、スケール セット、 Azure Arc 対応サーバー
エージェントをデプロイするため
アクション Microsoft.Resources/deployments/ * を含むロール (例: Log Analytics 共同作成者 )
サブスクリプションおよび/または リソース グループおよび/または
(Azure Policy でも使用される) Azure Resource Manager テンプレートを使用してエージェント拡張機能をデプロイするには
Azure 以外 : Azure の "外部" (つまり、オンプレミス) または他のクラウドでホストされている物理サーバーと仮想マシンにエージェントをインストールするには、最初に Azure Arc Connected Machine エージェントをインストール する必要があります (追加コストなし)。
認証 : マネージド ID が Azure 仮想マシンで有効になっている必要があります。 ユーザー割り当てとシステム割り当ての両方のマネージド ID がサポートされています。
ユーザー割り当て : このマネージド ID は大規模なデプロイに推奨され、組み込みの Azure ポリシー を使用して構成可能です。 ユーザー割り当てマネージド ID は 1 回作成して複数の VM で共有できるため、システム割り当てマネージド ID よりもスケーラブルです。 ユーザー割り当てマネージド ID を使用する場合は、拡張機能の設定を介してマネージド ID の詳細を Azure Monitor エージェントに渡す必要があります。
{
"authentication": {
"managedIdentity": {
"identifier-name": "mi_res_id" or "object_id" or "client_id",
"identifier-value": "<resource-id-of-uai>" or "<guid-object-or-client-id>"
}
}
}
mi_res_id
を identifier-name
として使用することをお勧めします。 次のサンプル コマンドは、簡潔にするために mi_res_id
での使用方法のみを示しています。 mi_res_id
、object_id
、client_id
の詳細については、マネージド ID のドキュメント を参照してください。
システム割り当て : このマネージド ID は、初期テストまたは小規模なデプロイに適しています。 大規模に (たとえば、サブスクリプション内のすべての VM に対して) 使用すると、Microsoft Entra ID で作成 (および削除) される ID の数が大幅に増えます。 この ID のチャーンを回避するには、代わりにユーザー割り当てマネージド ID を使用してください。 "Azure Arc 対応サーバーの場合、Azure Arc エージェントをインストールするとすぐに、システム割り当てマネージド ID が自動的に有効になります"。 これは、Azure Arc 対応サーバーでサポートされている唯一の種類です。
Azure Arc 対応サーバーの場合は不要 : Azure portal でデータ収集ルールを作成する と、システム ID が自動的に有効になります。
ネットワーク : ネットワーク ファイアウォールを使用する場合、仮想マシンの仮想ネットワークで Azure Resource Manager サービス タグ を有効にする必要があります。 仮想マシンは、次の HTTPS エンドポイントにもアクセスできる必要があります。
global.handler.control.monitor.azure.com
<virtual-machine-region-name>
.handler.control.monitor.azure.com (例: westus.handler.control.monitor.azure.com)
<log-analytics-workspace-id>
.ods.opinsights.azure.com (例: 12345a01-b1cd-1234-e1f2-1234567g8h99.ods.opinsights.azure.com)
エージェントでプライベート リンクを使っている場合は、dce エンドポイント も追加する必要があります。
インストール
Azure portal から Azure Monitor エージェントをインストールする方法については、「データ収集ルールを作成する 」を参照してください。 このプロセスにより、ルールが作成され、そのルールが選択したリソースに関連付けられ、それらのリソースに Azure Monitor エージェントがまだインストールされていない場合はインストールされます。
仮想マシン拡張機能を追加するための PowerShell コマンドを使用して、Azure 仮想マシンと Azure Arc 対応サーバーに Azure Monitor エージェントをインストールできます。
Azure 仮想マシンでのインストール
Azure 仮想マシンに Azure Monitor エージェントをインストールするには、次の PowerShell コマンドを使用します。 選択した認証方法に基づいて、適切なコマンドを選択します。
ユーザー割り当てマネージド ID
Windows
Set-AzVMExtension -Name AzureMonitorWindowsAgent -ExtensionType AzureMonitorWindowsAgent -Publisher Microsoft.Azure.Monitor -ResourceGroupName <resource-group-name> -VMName <virtual-machine-name> -Location <location> -TypeHandlerVersion <version-number> -EnableAutomaticUpgrade $true -SettingString '{"authentication":{"managedIdentity":{"identifier-name":"mi_res_id","identifier-value":/subscriptions/<my-subscription-id>/resourceGroups/<my-resource-group>/providers/Microsoft.ManagedIdentity/userAssignedIdentities/<my-user-assigned-identity>"}}}'
Linux
Set-AzVMExtension -Name AzureMonitorLinuxAgent -ExtensionType AzureMonitorLinuxAgent -Publisher Microsoft.Azure.Monitor -ResourceGroupName <resource-group-name> -VMName <virtual-machine-name> -Location <location> -TypeHandlerVersion <version-number> -EnableAutomaticUpgrade $true -SettingString '{"authentication":{"managedIdentity":{"identifier-name":"mi_res_id","identifier-value":/subscriptions/<my-subscription-id>/resourceGroups/<my-resource-group>/providers/Microsoft.ManagedIdentity/userAssignedIdentities/<my-user-assigned-identity>"}}}'
システム割り当てマネージド ID
Windows
Set-AzVMExtension -Name AzureMonitorWindowsAgent -ExtensionType AzureMonitorWindowsAgent -Publisher Microsoft.Azure.Monitor -ResourceGroupName <resource-group-name> -VMName <virtual-machine-name> -Location <location> -TypeHandlerVersion <version-number> -EnableAutomaticUpgrade $true
Linux
Set-AzVMExtension -Name AzureMonitorLinuxAgent -ExtensionType AzureMonitorLinuxAgent -Publisher Microsoft.Azure.Monitor -ResourceGroupName <resource-group-name> -VMName <virtual-machine-name> -Location <location> -TypeHandlerVersion <version-number> -EnableAutomaticUpgrade $true
Azure 仮想マシン スケール セットにインストールする
Add-AzVmssExtension PowerShell コマンドレットを使用して、Azure 仮想マシン スケール セットに Azure Monitor エージェントをインストールします。
Azure Arc 対応サーバーでのインストール
Azure Arc 対応サーバーに Azure Monitor エージェントをインストールするには、次の PowerShell コマンドを使用します。
Windows
New-AzConnectedMachineExtension -Name AzureMonitorWindowsAgent -ExtensionType AzureMonitorWindowsAgent -Publisher Microsoft.Azure.Monitor -ResourceGroupName <resource-group-name> -MachineName <arc-server-name> -Location <arc-server-location> -EnableAutomaticUpgrade
Linux
New-AzConnectedMachineExtension -Name AzureMonitorLinuxAgent -ExtensionType AzureMonitorLinuxAgent -Publisher Microsoft.Azure.Monitor -ResourceGroupName <resource-group-name> -MachineName <arc-server-name> -Location <arc-server-location> -EnableAutomaticUpgrade
仮想マシン拡張機能を追加するための Azure CLI コマンドを使用して、Azure 仮想マシンと Azure Arc 対応サーバーに Azure Monitor エージェントをインストールできます。
Azure 仮想マシンでのインストール
Azure 仮想マシンに Azure Monitor エージェントをインストールするには、次の CLI コマンドを使用します。 選択した認証方法に基づいて、適切なコマンドを選択します。
ユーザー割り当てマネージド ID
Windows
az vm extension set --name AzureMonitorWindowsAgent --publisher Microsoft.Azure.Monitor --ids <vm-resource-id> --enable-auto-upgrade true --settings '{"authentication":{"managedIdentity":{"identifier-name":"mi_res_id","identifier-value":"/subscriptions/<my-subscription-id>/resourceGroups/<my-resource-group>/providers/Microsoft.ManagedIdentity/userAssignedIdentities/<my-user-assigned-identity>"}}}'
Linux
az vm extension set --name AzureMonitorLinuxAgent --publisher Microsoft.Azure.Monitor --ids <vm-resource-id> --enable-auto-upgrade true --settings '{"authentication":{"managedIdentity":{"identifier-name":"mi_res_id","identifier-value":"/subscriptions/<my-subscription-id>/resourceGroups/<my-resource-group>/providers/Microsoft.ManagedIdentity/userAssignedIdentities/<my-user-assigned-identity>"}}}'
システム割り当てマネージド ID
Windows
az vm extension set --name AzureMonitorWindowsAgent --publisher Microsoft.Azure.Monitor --ids <vm-resource-id> --enable-auto-upgrade true
Linux
az vm extension set --name AzureMonitorLinuxAgent --publisher Microsoft.Azure.Monitor --ids <vm-resource-id> --enable-auto-upgrade true
Azure 仮想マシン スケール セットにインストールする
az vmss extension set CLI コマンドレットを使用して、Azure 仮想マシン スケール セットに Azure Monitor エージェントをインストールします。
Azure Arc 対応サーバーでのインストール
Azure Arc 対応サーバーに Azure Monitor エージェントをインストールするには、次の CLI コマンドを使用します。
Windows
az connectedmachine extension create --name AzureMonitorWindowsAgent --publisher Microsoft.Azure.Monitor --type AzureMonitorWindowsAgent --machine-name <arc-server-name> --resource-group <resource-group-name> --location <arc-server-location> --enable-auto-upgrade true
Linux
az connectedmachine extension create --name AzureMonitorLinuxAgent --publisher Microsoft.Azure.Monitor --type AzureMonitorLinuxAgent --machine-name <arc-server-name> --resource-group <resource-group-name> --location <arc-server-location> --enable-auto-upgrade true
Resource Manager テンプレートを使用して、Azure 仮想マシンおよび Azure Arc 対応サーバーに Azure Monitor エージェントをインストールし、データ収集ルールとの関連付けを作成できます。 関連付けを作成する前に、データ収集ルールを作成する必要があります。
エージェントをインストールし、関連付けを作成するためのサンプル テンプレートを、次のリソースから取得します。
次のコマンドのような、Resource Manager テンプレートのデプロイ方法のいずれか を使用して、テンプレートをインストールします。
PowerShell
New-AzResourceGroupDeployment -ResourceGroupName "<resource-group-name>" -TemplateFile "<template-filename.json>" -TemplateParameterFile "<parameter-filename.json>"
Azure CLI
az deployment group create --resource-group "<resource-group-name>" --template-file "<path-to-template>" --parameters "@<parameter-filename.json>"
アンインストール
Azure portal を使用して Azure Monitor エージェントをアンインストールするには、仮想マシン、スケール セット、または Azure Arc 対応サーバーに移動します。 [拡張機能] タブを選択し、[AzureMonitorWindowsAgent] または [AzureMonitorLinuxAgent] を選択します。 開いたダイアログで、[アンインストール] を選択します。
Azure 仮想マシンでのアンインストール
Azure 仮想マシンで Azure Monitor エージェントをアンインストールするには、次の PowerShell コマンドを使用します。
Windows
Remove-AzVMExtension -Name AzureMonitorWindowsAgent -ResourceGroupName <resource-group-name> -VMName <virtual-machine-name>
Linux
Remove-AzVMExtension -Name AzureMonitorLinuxAgent -ResourceGroupName <resource-group-name> -VMName <virtual-machine-name>
Azure 仮想マシン スケール セットからアンインストールする
Remove-AzVmssExtension PowerShell コマンドレットを使用して、Azure 仮想マシン スケール セットから Azure Monitor エージェントをアンインストールします。
Azure Arc 対応サーバーでのアンインストール
Azure Arc 対応サーバーで Azure Monitor エージェントをアンインストールするには、次の PowerShell コマンドを使用します。
Windows
Remove-AzConnectedMachineExtension -MachineName <arc-server-name> -ResourceGroupName <resource-group-name> -Name AzureMonitorWindowsAgent
Linux
Remove-AzConnectedMachineExtension -MachineName <arc-server-name> -ResourceGroupName <resource-group-name> -Name AzureMonitorLinuxAgent
Azure 仮想マシンでのアンインストール
Azure 仮想マシンで Azure Monitor エージェントをアンインストールするには、次の CLI コマンドを使用します。
Windows
az vm extension delete --resource-group <resource-group-name> --vm-name <virtual-machine-name> --name AzureMonitorWindowsAgent
Linux
az vm extension delete --resource-group <resource-group-name> --vm-name <virtual-machine-name> --name AzureMonitorLinuxAgent
Azure 仮想マシン スケール セットからアンインストールする
az vmss extension delete CLI コマンドレットを使用して、Azure 仮想マシン スケール セットから Azure Monitor エージェントをアンインストールします。
Azure Arc 対応サーバーでのアンインストール
Azure Arc 対応サーバーで Azure Monitor エージェントをアンインストールするには、次の CLI コマンドを使用します。
Windows
az connectedmachine extension delete --name AzureMonitorWindowsAgent --machine-name <arc-server-name> --resource-group <resource-group-name>
Linux
az connectedmachine extension delete --name AzureMonitorLinuxAgent --machine-name <arc-server-name> --resource-group <resource-group-name>
更新
注意
拡張機能の自動アップグレード を有効にすることをお勧めします。新しい拡張機能バージョンがリリースされてから、インストールされている拡張機能がすべてのリージョンでリリースされた (最新の) バージョンに更新されるまでに最大 5 週間 かかる場合があります。 アップグレードはバッチで発行されるため、一部の仮想マシン、スケール セット、または Arc 対応サーバーが他のサーバーより先にアップグレードされる場合があります。 拡張機能をすぐにアップグレードする必要がある場合は、以下の手動の手順を使用できます。
エージェントの 1 回限りの更新を実行するには、まず既存のエージェント バージョンをアンインストールする必要があります。 次に、説明に従って新しいバージョンをインストールします。
拡張機能の自動アップグレード 機能を有効にすることで、エージェントの自動更新を有効することを推奨します。 仮想マシンまたはスケール セットに移動し、[拡張機能] タブを選択し、[AzureMonitorWindowsAgent] または [AzureMonitorLinuxAgent] を選択します。 開いたダイアログで、[自動アップグレードを有効にする] を選択します。
Azure 仮想マシンでの更新
エージェントの 1 回限りの更新を実行するには、まず既存のエージェント バージョンをアンインストールしてから、前述のように新しいバージョンをインストールする必要があります。
次の PowerShell コマンドを使用して、拡張機能の自動アップグレード 機能を有効にすることで、エージェントの自動更新を有効することをお勧めします。
Windows
Set-AzVMExtension -ExtensionName AzureMonitorWindowsAgent -ResourceGroupName <resource-group-name> -VMName <virtual-machine-name> -Publisher Microsoft.Azure.Monitor -ExtensionType AzureMonitorWindowsAgent -TypeHandlerVersion <version-number> -Location <location> -EnableAutomaticUpgrade $true
Linux
Set-AzVMExtension -ExtensionName AzureMonitorLinuxAgent -ResourceGroupName <resource-group-name> -VMName <virtual-machine-name> -Publisher Microsoft.Azure.Monitor -ExtensionType AzureMonitorLinuxAgent -TypeHandlerVersion <version-number> -Location <location> -EnableAutomaticUpgrade $true
Azure Arc 対応サーバーでの更新
エージェントの 1 回限りのアップグレードを実行するには、次の PowerShell コマンドを使用します。
Windows
$target = @{"Microsoft.Azure.Monitor.AzureMonitorWindowsAgent" = @{"targetVersion"=<target-version-number>}}
Update-AzConnectedExtension -ResourceGroupName $env.ResourceGroupName -MachineName <arc-server-name> -ExtensionTarget $target
Linux
$target = @{"Microsoft.Azure.Monitor.AzureMonitorLinuxAgent" = @{"targetVersion"=<target-version-number>}}
Update-AzConnectedExtension -ResourceGroupName $env.ResourceGroupName -MachineName <arc-server-name> -ExtensionTarget $target
次の PowerShell コマンドを使用して、拡張機能の自動アップグレード 機能を有効にすることで、エージェントの自動更新を有効することをお勧めします。
Windows
Update-AzConnectedMachineExtension -ResourceGroup <resource-group-name> -MachineName <arc-server-name> -Name AzureMonitorWindowsAgent -EnableAutomaticUpgrade
Linux
Update-AzConnectedMachineExtension -ResourceGroup <resource-group-name> -MachineName <arc-server-name> -Name AzureMonitorLinuxAgent -EnableAutomaticUpgrade
Azure 仮想マシンでの更新
エージェントの 1 回限りの更新を実行するには、まず既存のエージェント バージョンをアンインストールしてから、前述のように新しいバージョンをインストールする必要があります。
次の CLI コマンドを使用して、拡張機能の自動アップグレード 機能を有効にすることで、エージェントの自動更新を有効することをお勧めします。
Windows
az vm extension set --name AzureMonitorWindowsAgent --publisher Microsoft.Azure.Monitor --vm-name <virtual-machine-name> --resource-group <resource-group-name> --enable-auto-upgrade true
Linux
az vm extension set --name AzureMonitorLinuxAgent --publisher Microsoft.Azure.Monitor --vm-name <virtual-machine-name> --resource-group <resource-group-name> --enable-auto-upgrade true
Azure Arc 対応サーバーでの更新
エージェントの 1 回限りのアップグレードを実行するには、次の CLI コマンドを使用します。
Windows
az connectedmachine upgrade-extension --extension-targets "{\"Microsoft.Azure.Monitor.AzureMonitorWindowsAgent\":{\"targetVersion\":\"<target-version-number>\"}}" --machine-name <arc-server-name> --resource-group <resource-group-name>
Linux
az connectedmachine upgrade-extension --extension-targets "{\"Microsoft.Azure.Monitor.AzureMonitorWindowsAgent\":{\"targetVersion\":\"<target-version-number>\"}}" --machine-name <arc-server-name> --resource-group <resource-group-name>
次の PowerShell コマンドを使用して、拡張機能の自動アップグレード 機能を有効にすることで、エージェントの自動更新を有効することをお勧めします。
Windows
az connectedmachine extension update --name AzureMonitorWindowsAgent --machine-name <arc-server-name> --resource-group <resource-group-name> --enable-auto-upgrade true
Linux
az connectedmachine extension update --name AzureMonitorLinuxAgent --machine-name <arc-server-name> --resource-group <resource-group-name> --enable-auto-upgrade true
Azure Policy を使用する
仮想マシン、スケール セット、または Azure Arc 対応サーバーを作成するたびに、次のポリシーとポリシー イニシアティブを使用して、エージェントを自動的にインストールし、データ収集ルールに関連付けます。
注意
Microsoft Identity のベスト プラクティスにより、仮想マシンとスケール セットに Azure Monitor エージェントをインストールするためのポリシーは、ユーザー割り当てマネージド ID に依存します。 このオプションは、これらのリソースのよりスケーラブルで回復性があるマネージド ID です。
Azure Arc 対応サーバーの場合、ポリシーは、現在サポートされている唯一のオプションとして、システム割り当てマネージド ID に依存します。
組み込みのポリシー イニシアチブ
続行する前に、エージェントのインストールの前提条件 を確認してください。
Windows および Linux 仮想マシン用の組み込みポリシー イニシアティブ、Azure Monitor エージェントをエンドツーエンドで使用して大規模なオンボーディングを提供するスケール セットがあります
これらのイニシアティブは、次に示す個別のポリシーで構成されています。
(省略可能) サブスクリプションごと、リージョンごとに、組み込みのユーザー割り当てマネージド ID を作成して割り当てます。 詳細については、こちらを参照してください 。
Bring Your Own User-Assigned Identity
: true
に設定すると、定義済みのリソース グループに組み込みのユーザー割り当てマネージド ID が作成され、ポリシーが適用されているすべてのマシンに割り当てられます。 false
に設定すると、代わりに、事前にマシンに割り当てる必要がある 既存のユーザー割り当て ID を使用できます。
Azure Monitor エージェント拡張機能をマシンにインストールし、次のパラメーターを指定して、このエージェントがユーザー割り当て ID を使用するように構成します。
Bring Your Own User-Assigned Managed Identity
: false
に設定すると、上記のポリシーによって作成された組み込みのユーザー割り当てマネージド ID を使用するようにエージェントが構成されます。 true
に設定すると、事前にスコープ内のマシンに "割り当てる必要がある" 既存のユーザー割り当て ID を使用するようにエージェントが構成されます。
User-Assigned Managed Identity Name
: 独自の ID を使用する (true
を選んだ) 場合は、マシンに割り当てられている ID の名前を指定します。
User-Assigned Managed Identity Resource Group
: 独自の ID を使用する (true
を選んだ) 場合は、ID が存在するリソース グループを指定します。
Additional Virtual Machine Images
: ポリシーを適用する追加の VM イメージ名を渡します (まだ含まれていない場合)。
関連付けを作成してデプロイし、マシンを指定されたデータ収集ルールにリンクします。
Data Collection Rule Resource Id
: ポリシーが適用されているすべてのマシンに、このポリシーを使用して関連付けるルールの Azure Resource Manager resourceId。
既知の問題
マネージド ID の既定の動作。 詳細については、こちらを参照してください 。
組み込みのユーザー割り当て ID 作成ポリシーを使用した場合に競合状態が発生する可能性があります。 詳細については、こちらを参照してください 。
リソース グループへのポリシーの割り当て。 ポリシーの割り当てスコープがサブスクリプションではなくリソース グループである場合、ポリシーの割り当てで使用される ID (エージェントで使用されるユーザー割り当て ID とは異なる) は、割り当てまたは修復の前にこれらのロール を手動で付与する必要があります。 この手順を行わないと、"デプロイ エラー" が発生します。
その他の マネージド ID の制限事項 。
組み込みのポリシー
上記のポリシー イニシアティブの個々のポリシーを使用して、大規模な 1 つのアクションを実行することを選択できます。 たとえば、エージェントを自動でインストールする "だけ" であれば、次に示すように、イニシアティブの 2 番目のエージェント インストール ポリシーを使用します。
イニシアチブとポリシーは、作成時に、各仮想マシンに適用されます。 修復タスク により、イニシアティブのポリシー定義が既存のリソースにデプロイされます。このため、既に作成されているすべてのリソースに対して Azure Monitor エージェントを構成できます。
Azure portal を使用して割り当てを作成するときに、修復タスクを同時に作成することができます。 修復の詳細については、「Azure Policy を使って準拠していないリソースを修復する 」を参照してください。
よく寄せられる質問
このセクションでは、一般的な質問への回答を示します。
Azure Arc Connected Machine エージェントをインストールすると、Azure 以外のマシンにどのような影響がありますか?
Azure Arc Connected Machine エージェントがインストールされた後、マシンには影響はありません。 これは、システム リソースやネットワーク リソースをほとんど使用せず、実行されるホストのフットプリントが少なくなるように設計されています。
次のステップ
データ収集ルールを作成し 、エージェントからデータを収集して Azure Monitor に送信します。