Dela via


Aktivera Azure VM-tillägg med hjälp av en ARM-mall

Den här artikeln visar hur du använder en Azure Resource Manager-mall (ARM-mall) för att distribuera tillägg för virtuella datorer (VM) till Azure Arc-aktiverade servrar.

Om du vill distribuera tillägg till Arc-aktiverade servrar med en ARM-mall lägger du till tillägg i mallen och kör dem med malldistributionen. Du kan distribuera tilläggen på Linux- eller Windows-anslutna datorer med hjälp av Azure PowerShell.

Den här artikeln visar hur du distribuerar flera olika VM-tillägg till en Arc-aktiverad server med hjälp av en mallfil, tillsammans med en separat parameterfil för vissa tillägg. Ersätt exempelvärdena i exemplen med dina egna värden innan du distribuerar.

Distributionskommandon

Dessa PowerShell-exempelkommandon installerar ett tillägg på alla anslutna datorer i en resursgrupp, baserat på informationen i ARM-mallen. Kommandot använder parametern TemplateFile för att ange mallen. Om en parameterfil krävs inkluderas parametern TemplateParameterFile för att ange en fil som innehåller parametrar och parametervärden. Ersätt platshållarna med lämpliga värden för distributionen.

Om du vill distribuera en ARM-mall och parameterfil använder du följande kommando och ersätter exempelvärdena med dina egna:

New-AzResourceGroupDeployment -ResourceGroupName "<resource-group-name>" -TemplateFile "<template-filename.json>" -TemplateParameterFile "<parameter-filename.json>"

Till exempel:

New-AzResourceGroupDeployment -ResourceGroupName "ContosoEngineering" -TemplateFile "D:\Azure\Templates\AzureMonitorAgent.json" -TemplateParameterFile "D:\Azure\Templates\AzureMonitorAgentParms.json"

Om du vill distribuera en ARM-mall utan en parameterfil använder du följande kommando och ersätter exempelvärdena med dina egna:

New-AzResourceGroupDeployment -ResourceGroupName "<resource-group-name>" -TemplateFile "<template-filename.json>>"

Till exempel:

New-AzResourceGroupDeployment -ResourceGroupName "<ContosoEngineering>" -TemplateFile "D:\Azure\Templates\DependencyAgent.json"

Distribuera vm-tillägget för Azure Monitor Agent

Om du vill distribuera Azure Monitor-agenten använder du någon av följande exempelmallar för att installera agenten i Linux eller Windows.

Azure Monitor Agent-mallfil för Linux

{
    "$schema": "http://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json",
    "contentVersion": "1.0.0.0",
    "parameters": {
        "vmName": {
            "type": "string"
        },
        "location": {
            "type": "string"
        },
        "workspaceId": {
            "type": "string"
        },
        "workspaceKey": {
            "type": "string"
        }
    },
    "resources": [
        {
            "name": "[concat(parameters('vmName'),'/AzureMonitorLinuxAgent')]",
            "type": "Microsoft.Compute/machines/extensions",
            "location": "[parameters('location')]",
            "apiVersion": "2021-11-01",
            "properties": {
                "publisher": "Microsoft.Azure.Monitor",
                "type": "AzureMonitorLinuxAgent",
                "enableAutomaticUpgrade": true,
                "settings": {
                    "workspaceId": "[parameters('workspaceId')]"
                },
                "protectedSettings": {
                    "workspaceKey": "[parameters('workspaceKey')]"
                }
            }
        }
    ]
}

Azure Monitor Agent-mallfil för Windows

{
    "$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentTemplate.json#",
    "contentVersion": "1.0.0.0",
    "parameters": {
        "vmName": {
            "type": "string"
        },
        "location": {
            "type": "string"
        },
        "workspaceId": {
            "type": "string"
        },
        "workspaceKey": {
            "type": "string"
        }
    },
    "resources": [
        {
            "name": "[concat(parameters('vmName'),'/AzureMonitorWindowsAgent')]",
            "type": "Microsoft.Compute/machines/extensions",
            "location": "[parameters('location')]",
            "apiVersion": "2021-11-01",
            "properties": {
                "publisher": "Microsoft.Azure.Monitor",
                "type": "AzureMonitorWindowsAgent",
                "autoUpgradeMinorVersion": true,
                "enableAutomaticUpgrade": true,
                "settings": {
                    "workspaceId": "[parameters('workspaceId')]"
                },
                "protectedSettings": {
                    "workspaceKey": "[parameters('workspaceKey')]"
                }
            }
        }
    ]
}

Azure Monitor Agent-parameterfil

Den här parameterfilen kan användas för både Linux och Windows.

{
    "$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentParameters.json#",
    "contentVersion": "1.0.0.0",
    "parameters": {
        "vmName": {
            "value": "<vmName>"
        },
        "location": {
            "value": "<region>"
        },
        "workspaceId": {
            "value": "<MyWorkspaceID>"
        },
        "workspaceKey": {
            "value": "<MyWorkspaceKey>"
        }
    }
}

Spara mallen och parameterfilen och redigera parameterfilen med lämpliga värden för distributionen. Installera sedan Azure Monitor Agent-tillägget på dina anslutna datorer genom att köra PowerShell-distributionskommandot som hittades tidigare i den här artikeln.

Distribuera tillägget för anpassat skript

Om du vill använda tillägget för anpassat skript distribuerar du en av följande exempelmallar för Linux och Windows. Information om tillägget för anpassade skript finns i Tillägget för anpassat skript för Linux eller tillägget för anpassade skript för Windows. Det finns några olika egenskaper som du bör förstå när du använder det här tillägget med hybriddatorer:

  • Listan över operativsystem som stöds med det anpassade skripttillägget för virtuella Azure-datorer gäller inte för Azure Arc-aktiverade servrar. Se listan över operativsystem som stöds för Azure Arc-aktiverade servrar.
  • Konfigurationsinformation om skalningsuppsättningar för virtuella Azure-datorer eller virtuella datorer som skapats via den klassiska distributionsmodellen är inte tillämpliga.
  • Om dina datorer behöver ladda ned ett skript externt och endast kan kommunicera via en proxyserver måste du konfigurera connected machine-agenten för att ange proxyserverns miljövariabel.

Konfigurationen för anpassat skripttillägg anger saker som skriptplats och kommandot som ska köras. Den här konfigurationen anges i följande mallar.

Mallfil för anpassat skripttillägg för Linux

{
  "$schema": "http://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#",
  "contentVersion": "1.0.0.0",
  "parameters": {
    "vmName": {
      "type": "string"
    },
    "location": {
      "type": "string"
    },
    "fileUris": {
      "type": "array"
    },
    "commandToExecute": {
      "type": "securestring"
    }
  },
  "resources": [
    {
      "name": "[concat(parameters('vmName'),'/CustomScript')]",
      "type": "Microsoft.HybridCompute/machines/extensions",
      "location": "[parameters('location')]",
      "apiVersion": "2022-03-10",
      "properties": {
        "publisher": "Microsoft.Azure.Extensions",
        "type": "CustomScript",
        "autoUpgradeMinorVersion": true,
        "settings": {},
        "protectedSettings": {
          "commandToExecute": "[parameters('commandToExecute')]",
          "fileUris": "[parameters('fileUris')]"
        }
      }
    }
  ]
}

Mallfil för anpassat skript för Windows

{
    "$schema": "http://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#",
    "contentVersion": "1.0.0.0",
    "parameters": {
        "vmName": {
            "type": "string"
        },
        "location": {
            "type": "string"
        },
        "fileUris": {
            "type": "string"
        },
        "arguments": {
            "type": "securestring",
            "defaultValue": " "
        }
    },
    "variables": {
        "UriFileNamePieces": "[split(parameters('fileUris'), '/')]",
        "firstFileNameString": "[variables('UriFileNamePieces')[sub(length(variables('UriFileNamePieces')), 1)]]",
        "firstFileNameBreakString": "[split(variables('firstFileNameString'), '?')]",
        "firstFileName": "[variables('firstFileNameBreakString')[0]]"
    },
    "resources": [
        {
            "name": "[concat(parameters('vmName'),'/CustomScriptExtension')]",
            "type": "Microsoft.HybridCompute/machines/extensions",
            "location": "[parameters('location')]",
            "apiVersion": "2022-03-10",
            "properties": {
                "publisher": "Microsoft.Compute",
                "type": "CustomScriptExtension",
                "autoUpgradeMinorVersion": true,
                "settings": {
                    "fileUris": "[split(parameters('fileUris'), ' ')]"
                },
                "protectedSettings": {
                    "commandToExecute": "[concat ('powershell -ExecutionPolicy Unrestricted -File ', variables('firstFileName'), ' ', parameters('arguments'))]"
                }
            }
        }
    ]
}

Anpassad skriptparameterfil

{
  "$schema": "https://schema.management.azure.com/schemas/0.1.2-preview/CreateUIDefinition.MultiVm.json#",
  "handler": "Microsoft.Azure.CreateUIDef",
  "version": "0.1.2-preview",
  "parameters": {
    "basics": [
      {}
    ],
    "steps": [
      {
        "name": "customScriptExt",
        "label": "Add Custom Script Extension",
        "elements": [
          {
            "name": "fileUris",
            "type": "Microsoft.Common.FileUpload",
            "label": "Script files",
            "toolTip": "The script files that will be downloaded to the virtual machine.",
            "constraints": {
              "required": false
            },
            "options": {
              "multiple": true,
              "uploadMode": "url"
            },
            "visible": true
          },
          {
            "name": "commandToExecute",
            "type": "Microsoft.Common.TextBox",
            "label": "Command",
            "defaultValue": "sh script.sh",
            "toolTip": "The command to execute, for example: sh script.sh",
            "constraints": {
              "required": true
            },
            "visible": true
          }
        ]
      }
    ],
    "outputs": {
      "vmName": "[vmName()]",
      "location": "[location()]",
      "fileUris": "[steps('customScriptExt').fileUris]",
      "commandToExecute": "[steps('customScriptExt').commandToExecute]"
    }
  }
}

Spara mallen och parameterfilen och redigera parameterfilen med lämpliga värden för distributionen. Installera sedan tillägget Anpassat skript till dina anslutna datorer genom att köra PowerShell-distributionskommandot som hittades tidigare i den här artikeln.

Distribuera tillägget för beroendeagent

Om du vill använda Azure Monitor Dependency Agent-tillägget kör du något av följande exempel för Linux och Windows. Mer information om beroendeagenten finns i Översikt över Azure Monitor-agenter.

Mallfil för beroendeagent för Linux

{
  "$schema": "https://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#",
  "contentVersion": "1.0.0.0",
  "parameters": {
    "vmName": {
      "type": "string",
      "metadata": {
        "description": "The name of existing Linux machine."
      }
    }
  },
  "resources": [
    {
      "type": "Microsoft.HybridCompute/machines/extensions",
      "name": "[concat(parameters('vmName'),'/DAExtension')]",
      "apiVersion": "2022-03-10",
      "location": "[resourceGroup().location]",
      "dependsOn": [
      ],
      "properties": {
        "publisher": "Microsoft.Azure.Monitoring.DependencyAgent",
        "type": "DependencyAgentLinux",
        "enableAutomaticUpgrade": true
      }
    }
  ],
  "outputs": {
  }
}

Mallfil för beroendeagent för Windows

{
  "$schema": "https://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#",
  "contentVersion": "1.0.0.0",
  "parameters": {
    "vmName": {
      "type": "string",
      "metadata": {
        "description": "The name of existing Windows machine."
      }
    }
  },
  "resources": [
    {
      "type": "Microsoft.HybridCompute/machines/extensions",
      "name": "[concat(parameters('vmName'),'/DAExtension')]",
      "apiVersion": "2022-03-10",
      "location": "[resourceGroup().location]",
      "dependsOn": [
      ],
      "properties": {
        "publisher": "Microsoft.Azure.Monitoring.DependencyAgent",
        "type": "DependencyAgentWindows",
        "enableAutomaticUpgrade": true
      }
    }
  ],
  "outputs": {
  }
}

Spara mallen och installera sedan beroendeagenttillägget på dina anslutna datorer genom att köra PowerShell-distributionskommandot som hittades tidigare i den här artikeln.

Distribuera Azure Key Vault-tillägget

Följande JSON visar schemat för Azure Key Vault-tillägget. Det här tillägget kräver inte skyddade inställningar eftersom alla dess inställningar betraktas som offentlig information. Tillägget kräver en lista över övervakade certifikat, kontrollfrekvensen och målcertifikatsarkivet.

Azure Key Vault-mallfil för Linux

{
    "$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentTemplate.json#",
    "contentVersion": "1.0.0.0",
    "parameters": {
        "vmName": {
            "type": "string"
        },
        "location": {
            "type": "string"
        },
        "autoUpgradeMinorVersion":{
            "type": "bool"
        },
        "pollingIntervalInS":{
          "type": "int"
        },
        "certificateStoreName":{
          "type": "string"
        },
        "certificateStoreLocation":{
          "type": "string"
        },
        "observedCertificates":{
          "type": "string"
        },
        "msiEndpoint":{
          "type": "string"
        },
        "msiClientId":{
          "type": "string"
        }
},
"resources": [
   {
      "type": "Microsoft.HybridCompute/machines/extensions",
      "name": "[concat(parameters('vmName'),'/KVVMExtensionForLinux')]",
      "apiVersion": "2022-03-10",
      "location": "[parameters('location')]",
      "properties": {
      "publisher": "Microsoft.Azure.KeyVault",
      "type": "KeyVaultForLinux",
      "enableAutomaticUpgrade": true,
      "settings": {
          "secretsManagementSettings": {
          "pollingIntervalInS": <polling interval in seconds, e.g. "3600">,
          "certificateStoreName": <ignored on linux>,
          "certificateStoreLocation": <disk path where certificate is stored, default: "/var/lib/waagent/Microsoft.Azure.KeyVault">,
          "observedCertificates": <list of KeyVault URIs representing monitored certificates, e.g.: "https://myvault.vault.azure.net/secrets/mycertificate"
          },
          "authenticationSettings": {
                "msiEndpoint":  "http://localhost:40342/metadata/identity"
        }
      }
    }
  }
 ]
}

Azure Key Vault-mallfil för Windows

{
    "$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentTemplate.json#",
    "contentVersion": "1.0.0.0",
    "parameters": {
        "vmName": {
            "type": "string"
        },
        "location": {
            "type": "string"
        },
        "autoUpgradeMinorVersion":{
            "type": "bool"
        },
        "pollingIntervalInS":{
          "type": "int"
        },
        "certificateStoreName":{
          "type": "string"
        },
        "linkOnRenewal":{
          "type": "bool"
        },
        "certificateStoreLocation":{
          "type": "string"
        },
        "requireInitialSync":{
          "type": "bool"
        },
        "observedCertificates":{
          "type": "string"
        },
        "msiEndpoint":{
          "type": "string"
        },
        "msiClientId":{
          "type": "string"
        }
},
"resources": [
   {
      "type": "Microsoft.HybridCompute/machines/extensions",
      "name": "[concat(parameters('vmName'),'/KVVMExtensionForWindows')]",
      "apiVersion": "2022-03-10",
      "location": "[parameters('location')]",
      "properties": {
      "publisher": "Microsoft.Azure.KeyVault",
      "type": "KeyVaultForWindows",
      "enableAutomaticUpgrade": true,
      "settings": {
        "secretsManagementSettings": {
          "pollingIntervalInS": "3600",
          "certificateStoreName": <certificate store name, e.g.: "MY">,
          "linkOnRenewal": <Only Windows. This feature ensures s-channel binding when certificate renews, without necessitating a re-deployment.  e.g.: false>,
          "certificateStoreLocation": <certificate store location, currently it works locally only e.g.: "LocalMachine">,
          "requireInitialSync": <initial synchronization of certificates e.g.: true>,
          "observedCertificates": <list of KeyVault URIs representing monitored certificates, e.g.: "https://myvault.vault.azure.net"
        },
        "authenticationSettings": {
                "msiEndpoint": "http://localhost:40342/metadata/identity"
        }
      }
    }
  }
 ]
}

Kommentar

Dina observerade certifikat-URL:er ska vara i formen https://myVaultName.vault.azure.net/secrets/myCertName. Anledningen är att /secrets sökvägen returnerar det fullständiga certifikatet, inklusive den privata nyckeln, medan /certificates sökvägen inte gör det. Mer information om certifikat finns i Översikt över Azure Key Vault-nycklar, hemligheter och certifikat.

Spara mallen och redigera efter behov för din miljö. Installera sedan Azure Key Vault-tillägget på dina anslutna datorer genom att köra PowerShell-distributionskommandot som hittades tidigare i den här artikeln.

Tips/Råd

Azure Key Vault-tillägget kräver att en systemtilldelad identitet tilldelas för autentisering till Key Vault. Mer information finns i Autentisera mot Azure-resurser med Azure Arc-aktiverade servrar.