次の方法で共有


Azure CLI (Windows および Linux) を使用して Azure VM 拡張機能を有効にする

この記事では、Azure CLI (Windows および Linux) を使用して、Azure Arc 対応サーバーに 仮想マシン (VM) 拡張機能 をデプロイ、アップグレード、更新、アンインストールする方法について説明します。

前提条件

  • Azure Cloud Shell で Bash 環境を使用します。 詳細については、「Azure Cloud Shell の概要」を参照してください。

  • CLI リファレンス コマンドをローカルで実行する場合、Azure CLI をインストールします。 Windows または macOS で実行している場合は、Docker コンテナーで Azure CLI を実行することを検討してください。 詳細については、「Docker コンテナーで Azure CLI を実行する方法」を参照してください。

    • ローカル インストールを使用する場合は、az login コマンドを使用して Azure CLI にサインインします。 認証プロセスを完了するには、ターミナルに表示される手順に従います。 その他のサインイン オプションについては、「 Azure CLI を使用した Azure への認証」を参照してください。

    • 初回使用時にインストールを求められたら、Azure CLI 拡張機能をインストールします。 拡張機能の詳細については、「Azure CLI で拡張機能を使用および管理する」を参照してください。

    • az version を実行し、インストールされているバージョンおよび依存ライブラリを検索します。 最新バージョンにアップグレードするには、az upgrade を実行します。

Azure CLI で Connected Machine 拡張機能をインストールする

ConnectedMachine コマンドは、Azure CLI の一部として提供されません。 Azure CLI を使用して Azure に接続し、Azure Arc 対応サーバーで管理されているハイブリッド サーバーで VM 拡張機能を管理する前に、 ConnectedMachine 拡張機能を読み込む必要があります。

これらの管理操作は、Azure Arc 対応サーバーではなく、ワークステーションから実行できます。

次のコマンドを実行して、Azure CLI ConnectedMachine 拡張機能をインストールします。

az extension add --name connectedmachine

拡張機能を有効にする

Azure Arc 対応サーバーで VM 拡張機能を有効にするには、az connectedmachine extension create--machine-name--extension-name--___location--typesettings の各パラメーターと共に --publisher を使用します。

この例では、Azure Arc 対応サーバーでカスタム スクリプト拡張機能を有効にします。

az connectedmachine extension create --machine-name "myMachineName" --name "CustomScriptExtension" --___location "regionName" --type "CustomScriptExtension" --publisher "Microsoft.Compute" --settings "{\"commandToExecute\":\"powershell.exe -c \\\"Get-Process | Where-Object { $_.CPU -gt 10000 }\\\"\"}" --type-handler-version "1.10" --resource-group "myResourceGroup"

この例では、Azure Arc 対応サーバーで Azure Key Vault VM 拡張機能を有効にします。

az connectedmachine extension create --resource-group "resourceGroupName" --machine-name "myMachineName" --___location "regionName" --publisher "Microsoft.Azure.KeyVault" --type "KeyVaultForLinux or KeyVaultForWindows" --name "KeyVaultForLinux or KeyVaultForWindows" --settings '{"secretsManagementSettings": { "pollingIntervalInS": "60", "observedCertificates": ["observedCert1"] }, "authenticationSettings": { "msiEndpoint": "http://localhost:40342/metadata/identity" }}'

この例では、Azure Arc 対応 Windows サーバーで Microsoft マルウェア対策拡張機能を有効にします。

az connectedmachine extension create --resource-group "resourceGroupName" --machine-name "myMachineName" --___location "regionName" --publisher "Microsoft.Azure.Security" --type "IaaSAntimalware" --name "IaaSAntimalware" --settings '"{\"AntimalwareEnabled\": \"true\"}"'

この例では、Azure Arc 対応 Windows サーバーで Datadog 拡張機能を有効にします。

az connectedmachine extension create --resource-group "resourceGroupName" --machine-name "myMachineName" --___location "regionName" --publisher "Datadog.Agent" --type "DatadogWindowsAgent" --settings '{"site": "us3.datadoghq.com"}' --protected-settings '{"api_key": "YourDatadogAPIKey" }'

ヒント

Arc 対応サーバーでは、他の多くの拡張機能がサポートされています。 詳細については、 Azure Arc 対応サーバーを使用した仮想マシン拡張機能の管理に関するページを参照してください。

インストールされている拡張機能を一覧表示する

Azure Arc 対応サーバー上の VM 拡張機能の一覧を取得するには、az connectedmachine extension listパラメーターと--machine-name パラメーターで--resource-groupを使用します。

az connectedmachine extension list --machine-name "myMachineName" --resource-group "myResourceGroup"

既定では、Azure CLI コマンドの出力形式は JSON (JavaScript Object Notation) です。 既定の出力をリストまたはテーブルなどに変更するには、az config set core.output=table を使用します。 出力形式で 1 回のみ変更するために --output を任意のコマンドに追加することもできます。

次の例に、az connectedmachine extension -list コマンドの JSON 形式の出力の一部を示します。

[
  {
    "autoUpgradingMinorVersion": "false",
    "forceUpdateTag": null,
    "id": "/subscriptions/subscriptionId/resourceGroups/resourceGroupName/providers/Microsoft.HybridCompute/machines/SVR01/extensions/DependencyAgentWindows",
    "___location": "regionName",
    "name": "DependencyAgentWindows",
    "namePropertiesInstanceViewName": "DependencyAgentWindows",

拡張機能の構成を更新する

一部の VM 拡張機能では、Azure Arc 対応サーバーにインストールできるように、構成設定が必要になります (カスタム スクリプト拡張機能など)。 拡張機能の構成をアップグレードするには、az connectedmachine extension update を使用します。

次に示したのは、カスタム スクリプト拡張機能を構成する方法の例です。

az connectedmachine extension update --name "CustomScriptExtension" --type "CustomScriptExtension" --publisher "Microsoft.HybridCompute" --settings "{\"commandToExecute\":\"powershell.exe -c \\\"Get-Process | Where-Object { $_.CPU -lt 100 }\\\"\"}" --type-handler-version "1.10" --machine-name "myMachine" --resource-group "myResourceGroup"

拡張機能のアップグレード

サポートされている VM 拡張機能は、新しいバージョンがリリースされた時点でその最新リリースにアップグレードできます。 VM 拡張機能をアップグレードするには、az connectedmachine upgrade-extension--machine-name--resource-group パラメーターと共に --extension-targets を使用します。

--extension-targets パラメーターには、拡張機能と提供されている最新バージョンを指定する必要があります。 拡張機能で使用できる最新バージョンを確認するには、Azure portal で選択した Azure Arc 対応サーバーの [拡張機能] ページにアクセスするか、az vm extension image list を実行します。 1 つのアップグレード要求で複数の拡張機能を指定するには、次の両方を指定します。

  • パブリッシャーと種類 (ピリオド区切り) で定義された、拡張機能のコンマ区切りの一覧
  • 各拡張機能のターゲット バージョン

コマンド az connectedmachine extension list を実行することで、インストールされている VM 拡張機能のバージョンをいつでも確認できます。 拡張機能のバージョンは、typeHandlerVersion プロパティの値によって表されます。

ヒント

多くの VM 拡張機能は、 自動アップグレード用に構成できます。

拡張機能を削除する

Azure Arc 対応サーバーからインストール済みの VM 拡張機能を削除するには、az connectedmachine extension delete--extension-name--machine-name の各パラメーターと共に --resource-group を使用します。