次の方法で共有


AZURE VM アプリケーションの管理

この記事では、Azure コンピューティング ギャラリーで発行済み VM アプリケーションを表示、更新、削除する方法について説明します。 次に、デプロイされた VM アプリケーション リソースを、Azure仮想マシン (VM) またはVirtual Machine Scale Setsで表示、監視、更新、削除する方法について説明します。

このセクションでは、Azure コンピューティング ギャラリーで発行済み VM アプリケーションを表示、更新、および削除する方法について説明します。

発行された VM アプリケーションを表示する

  • ポータル
  • 休む
  • CLI
  • PowerShell

Azure ポータルで発行済み VM アプリケーションのプロパティを表示するには:

  1. Azure ポータルにサインインします。
  2. Azure Compute Gallery を検索します。
  3. VM アプリケーションを含むギャラリーを選択します。
  4. 表示する VM アプリケーション名 をクリックします。
  5. [ 概要]/[プロパティ] ブレードには、VM アプリケーションに関する情報が表示されます。
  6. [ 概要]/[バージョン] ブレードには、公開されているすべてのバージョンとその基本プロパティ (ターゲット リージョン、プロビジョニング状態、レプリケーション状態など) が表示されます。
  7. 特定の バージョン を選択すると、そのすべての詳細が表示されます。

Azure ポータル内に表示される VM アプリケーションのプロパティとすべてのバージョンのスクリーンショット。

&&&Azure portal の VM アプリケーションバージョンのプロパティを示すスクリーンショット&&

Azure Resource Graphを使用して発行された VM アプリケーションを表示する

Azure リソース グラフ クエリを使用すると、すべてのコンピューティング ギャラリーで発行されたすべての VM アプリケーションとそのプロパティを表示できます。 アプリケーション インベントリとそのプロパティを大規模に表示するプログラムによる方法が提供されます。 ダッシュボードやカスタム レポートと統合する場合は、この方法を使用します。

すべてのコンピューティング ギャラリーの一覧を表示する

resources
| where type == "microsoft.compute/galleries"
| where subscriptionId == "85236c53-92ad-4e66-97a4-8253a5246b99"
| extend provisioningState = properties["provisioningState"]
| extend permissions = properties["sharingProfile"]["permissions"]
| extend communityGalleryInfo = properties["sharingProfile"]["communityGalleryInfo"]
| project subscriptionId, resourceGroup, location, name, provisioningState, permissions, communityGalleryInfo

すべてのギャラリーで公開されているすべての VM アプリケーションの一覧を表示する

resources
| where subscriptionId == "85236c53-92ad-4e66-97a4-8253a5246b99"
| where type == "microsoft.compute/galleries/applications"
| extend OSType = properties["supportedOSType"]
| extend description = properties["description"]
| extend endOfLifeDate = properties["endOfLifeDate"]
| parse id with  "/subscriptions/" SubId "/resourceGroups/" rgName "/providers/Microsoft.Compute/galleries/" gallaryName "/applications/" appName  
| project subscriptionId, resourceGroup, location, gallaryName, name, OSType, description

すべてのアプリケーションとギャラリーで公開されているすべての VM アプリケーション バージョンの一覧を表示する

resources
| where type == "microsoft.compute/galleries/applications/versions"
| project subscriptionId, resourceGroup, id, location, properties
| parse id with  "/subscriptions/" SubId "/resourceGroups/" rgName "/providers/Microsoft.Compute/galleries/" gallaryName "/applications/" appName "/versions/" versionNumber 
| extend provisioningState = properties["provisioningState"]
| extend publishingProfile = properties["publishingProfile"]
| extend storageAccountType = publishingProfile["storageAccountType"]
| extend scriptBehaviorAfterReboot = publishingProfile["settings"]["scriptBehaviorAfterReboot"]
| extend packageFileName = publishingProfile["settings"]["packageFileName"]
| extend configFileName = publishingProfile["settings"]["configFileName"]
| extend mediaLink = publishingProfile["source"]["mediaLink"]
| extend defaultConfigurationLink = publishingProfile["source"]["defaultConfigurationLink"]
| extend excludeFromLatest = publishingProfile["excludeFromLatest"]
| extend targetRegions = publishingProfile["targetRegions"]
| extend replicaCount = publishingProfile["replicaCount"]
| extend publishedDate = publishingProfile["publishedDate"]
| extend installScript = publishingProfile["manageActions"]["install"]
| extend removeScript = publishingProfile["manageActions"]["remove"]
| extend safetyProfile = properties["safetyProfile"]
| extend allowDeletionOfReplicatedLocations = safetyProfile["allowDeletionOfReplicatedLocations"]
| project-away safetyProfile, publishingProfile, SubId, rgName, id, properties

発行された VM アプリケーションを更新する

発行された VM アプリケーションまたは VM アプリケーションのバージョンのすべてのプロパティを更新できるわけではありません。 更新可能なプロパティの完全な一覧については、 VM アプリケーション リソースと VM アプリケーションバージョンのリソース スキーマを参照してください。

  • レスト
  • CLI
  • PowerShell

VM アプリケーション リソースの更新:

PATCH
https://management.azure.com/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Compute/galleries/{galleryName}/applications/{galleryApplicationName}?api-version=2024-03-03

Body
{
    "properties": {
        "description": "Updated description",
        "endOfLifeDate": "2026-12-31T00:00:00Z",
        "eula": "Updated EULA text",
        "privacyStatementUri": "https://contoso.com/privacy",
        "releaseNoteUri": "https://contoso.com/release-notes"
    }
}

VM アプリケーション のバージョン リソースを更新します。

PATCH
https://management.azure.com/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Compute/galleries/{galleryName}/applications/{galleryApplicationName}/versions/{galleryApplicationVersionName}?api-version=2024-03-03

Body
{
    "properties": {
        "publishingProfile": {
            "targetRegions": [
                {
                    "name": "eastus",
                    "regionalReplicaCount": 2,
                    "storageAccountType": "Standard_LRS"
                },
                {
                    "name": "westus",
                    "regionalReplicaCount": 1,
                    "storageAccountType": "Standard_LRS"
                }
            ],
            "excludeFromLatest": false
        }
    }
}

VM アプリケーション リソースを削除するには、まず、そのすべてのバージョンを削除する必要があります。 アプリケーション のバージョンを削除すると、Azure コンピューティング ギャラリーとそのすべてのレプリカからアプリケーション バージョン リソースが削除されます。 アプリケーション バージョンの作成に使用されるストレージ アカウント内のアプリケーション BLOB は影響を受けません。

Warnung

  • アプリケーションのバージョンを削除すると、そのバージョンを使用している VM に対する後続の PUT 操作が失敗します。 このエラーを回避するには、バージョン番号をハード コーディングする代わりに、のバージョン番号として キーワードを使用します。

  • 任意の VM またはVirtual Machine Scale Setsにデプロイされている VM アプリケーションを削除すると、これらのリソースに対する後続の PUT 操作が失敗します (更新、スケール、再イメージ化など)。 削除する前に、すべての VM/Virtual Machine Scale Sets インスタンスが applicationProfile からアプリケーションを削除してアプリケーションの使用を停止していることを確認します。

  • 誤って削除されないようにするには、バージョンの発行時に safetyProfile/allowDeletionOfReplicatedLocationsfalse に設定し、VM アプリケーション リソースにAzure Resource Manager ロック (CanNotDelete または ReadOnly) を適用します。

  • ポータル
  • レスト
  • CLI
  • PowerShell
  1. Azure ポータルにサインインします。
  2. コンピューティング ギャラリー Azure検索し、ターゲット ギャラリーを開きます。
  3. 削除する VM アプリケーションを選択します。
  4. 削除する 1 つ以上のバージョンを選択します。
  5. VM アプリケーションを削除するには、まずすべてのバージョンを削除します。 次に、(ブレードの上部にある) [削除] をクリックします。
  6. 通知の完了を監視します。 削除がブロックされている場合は、ロックを削除し、VM またはVirtual Machine Scale Setsがアプリケーションを参照しないようにします。

Azure portal での VM アプリケーションとそのバージョンの削除を示すスクリーンショット。

デプロイされた VM アプリケーションAzure VM とVirtual Machine Scale Setsで管理する

このセクションでは、デプロイされたアプリケーションの詳細を表示し、インフラストラクチャ全体でデプロイされたアプリケーションを監視する方法について説明します。 また、Azure VM とVirtual Machine Scale Setsデプロイされた VM アプリケーションを更新および削除する方法についても説明します。

デプロイされた VM アプリケーションとその状態を表示する

Azureでは、VMAppExtension を使用して VM アプリケーションをデプロイ、監視、管理します。 そのため、デプロイされた VM アプリケーションのプロビジョニング状態は、VMAppExtension の状態で記述されます。

  • ポータル
  • レスト
  • CLI
  • PowerShell

VM アプリケーションの状態を表示するには、[設定] の [ 拡張機能とアプリケーション ] タブに移動し、VMAppExtension の状態を確認します。

VM アプリケーションの状態を示すスクリーンショット。

Virtual Machine Scale Setsの VM アプリケーションの状態を表示するには、Azure ポータルの Virtual Machine Scale Sets ページに移動します。 [インスタンス] セクションで、いずれかのインスタンスを選択します。 次に、[設定] の [ 拡張機能とアプリケーション ] タブに移動し、 VMAppExtension の状態を確認します。

Virtual Machine Scale Sets のアプリケーション状況を示すスクリーンショット。

[実行] コマンドを使用してアプリケーションのインストールのログを表示する

AZURE VM アプリケーションは、Azure VM またはVirtual Machine Scale Setsにアプリケーションをダウンロードしてインストールすると、すべての stdout 結果をパイプして、アプリケーション リポジトリ内の stdout ファイルに送られます。 お客様は、アプリケーションのインストールに対して詳細ログを有効にし、特定のツールを使用してカスタム ログを書き込むことができます。 その後、お客様は ファイルを手動で確認するか、Runcommand を使用してファイルの内容を取得できます。

マネージド実行コマンドで次の PowerShell スクリプトを使用します。 アプリケーションの <変数1> と <変数2> を更新する

$appName = "vm-application-name"        # VM Application definition name
$appVersion = "1.0.0"                   # VM Application version name

$VMAppManagerVersion = "1.0.16"         # Version of the VMApplicationManagerWindows extension on the VM
$StdoutFilePath = "C:\Packages\Plugins\Microsoft.CPlat.Core.VMApplicationManagerWindows\$VMAppManagerVersion\Downloads\$appName\$appVersion\stdout"
$StderrFilePath = "C:\Packages\Plugins\Microsoft.CPlat.Core.VMApplicationManagerWindows\$VMAppManagerVersion\Downloads\$appName\$appVersion\stderr"

Write-Host "`n=== Contents of stdout ==="
Get-Content -Path $StdoutFilePath

Write-Host "`n=== Contents of stderr ==="
Get-Content -Path $StderrFilePath

スクリプトを使用して実行コマンドを実行し、アプリケーションのインストール ログを取得します。

  • ポータル
  • CLI
  • PowerShell
  1. Azure ポータルを開き、VM に移動します。
  2. [ 操作] で、[ コマンドの実行] を選択します。
  3. 一覧から [RunPowerShellScript ] を選択します。
  4. エディターで PowerShell スクリプトを入力します。
  5. [ 実行 ] を選択してスクリプトを実行します。
  6. 出力セクションで出力を表示します。 スクリプトが失敗した場合は、[ エラー ] セクションで詳細を確認してください。

詳細については、「 Run Commandを参照してください。

Azure Resource Graphを使用してデプロイされたすべての VM アプリケーションを表示する

Azure リソース グラフ クエリを使用すると、デプロイされたすべての VM アプリケーションとそのプロパティをすべての VM とVirtual Machine Scale Setsにわたって表示できます。 アプリケーション インベントリ、状態、およびデプロイされたバージョンを大規模に表示するプログラムによる方法が提供されます。 ダッシュボードやカスタム レポートと統合する場合は、この方法を使用します。

resources
| where type == "microsoft.compute/virtualmachines" or type == "microsoft.compute/virtualmachinescalesets"
| where properties has "applicationProfile"
| extend resourceType = iff(type == "microsoft.compute/virtualmachines", "VM", "VMSS")
| extend applications = iff(resourceType == "VM", parse_json(properties["applicationProfile"]["galleryApplications"]), parse_json(properties["virtualMachineProfile"]["applicationProfile"]["galleryApplications"]))
| mv-expand applications
| extend enableAutomaticUpgrade = applications["enableAutomaticUpgrade"]
| extend packageReferenceId = applications["packageReferenceId"]
| extend treatFailureAsDeploymentFailure = applications["treatFailureAsDeploymentFailure"]
| parse packageReferenceId with "/subscriptions/" publisherSubcriptionId "/resourceGroups/" publisherResourceGroup "/providers/Microsoft.Compute/galleries/" galleryName "/applications/" appName "/versions/" version
| project tenantId, subscriptionId, resourceGroup, resourceName = name, type, location, appName, version, enableAutomaticUpgrade, treatFailureAsDeploymentFailure, galleryName, publisherSubcriptionId, publisherResourceGroup, properties

Azure Policyを使用して必要な VM アプリケーションを監査する

Azure Policyは、必要な VM アプリケーションが VM とVirtual Machine Scale Setsにデプロイされているかどうかを監査することで、ガバナンスを適用するのに役立ちます。 カスタム ポリシーを作成して割り当ててコンプライアンスを確認し、特定のアプリケーションがインフラストラクチャに存在することを確認できます。

Azure Policyを使用して VM アプリケーションのデプロイを監査する手順については、「audit required VM applications using Azure Policy」を参照してください。

デプロイされた VM アプリケーションを更新する

デプロイされた VM アプリケーションを更新するには、 を変更して新しいバージョンを参照するか、 や などのデプロイ設定を変更します。

  • レスト
  • CLI
  • PowerShell

1 つの VM で VM アプリケーションのバージョンまたは設定を更新します。

PATCH
https://management.azure.com/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Compute/virtualMachines/{vmName}?api-version=2024-03-03

Body
{
    "properties": {
        "applicationProfile": {
            "galleryApplications": [
                {
                    "packageReferenceId": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Compute/galleries/{galleryName}/applications/{applicationName}/versions/{newVersion}",
                    "treatFailureAsDeploymentFailure": true,
                    "enableAutomaticUpgrade": true
                }
            ]
        }
    }
}

Virtual Machine Scale Sets (モデル) における VM アプリケーションの更新:

PATCH
https://management.azure.com/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Compute/virtualMachineScaleSets/{vmssName}?api-version=2024-03-03

Body
{
    "properties": {
        "virtualMachineProfile": {
            "applicationProfile": {
                "galleryApplications": [
                    {
                        "packageReferenceId": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Compute/galleries/{galleryName}/applications/{applicationName}/versions/{newVersion | latest}",
                        "treatFailureAsDeploymentFailure": true,
                        "order": 2
                    }
                ]
            }
        }
    }
}

既存のVirtual Machine Scale Sets インスタンスに変更を適用します (upgradePolicy.mode が Manual の場合に必要)。

POST
https://management.azure.com/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Compute/virtualMachineScaleSets/{vmssName}/updateInstances?api-version=2024-03-03

Body
{
    "instanceIds": ["*"]
}

ヒント

のバージョン識別子として を使用して、手動でデプロイを更新することなく、最新の発行済みバージョンを自動的にデプロイします。

Azure VM または仮想マシンスケールセットから VM アプリケーションを削除する

  • ポータル
  • レスト
  • CLI
  • PowerShell
  1. Azure ポータルを開き、ターゲット仮想マシン (VM) またはVirtual Machine Scale Setsに移動します。
  2. [設定] で、[ 拡張機能とアプリケーション] を選択し、[ VM アプリケーション ] タブを選択します。
  3. VM アプリケーションの [アンインストール] ボタンをクリックし、[保存] をクリックします。
  4. [通知] で進行状況を追跡するか、VMAppExtension 状態の [インスタンス] ビューを確認します。

VM から VM アプリケーションをアンインストールする方法を示すスクリーンショット。

次のステップ