Azure-beli virtuálisgép-bővítmények engedélyezése ARM-sablonnal

Ez a cikk bemutatja, hogyan használhat Azure Resource Manager-sablont (ARM-sablont) azure-beli virtuálisgép-bővítmények üzembe helyezéséhez, amelyeket az Azure Arc-kompatibilis kiszolgálók támogatnak.

A virtuálisgép-bővítmények hozzáadhatók egy Azure Resource Manager-sablonhoz, és a sablon üzembe helyezésével végrehajthatók. Az Azure Arc-kompatibilis kiszolgálók által támogatott virtuálisgép-bővítményekkel a támogatott virtuálisgép-bővítményt Linux vagy Windows rendszerű gépeken is üzembe helyezheti az Azure PowerShell használatával. Az alábbi minták egy sablonfájlt és egy paraméterfájlt tartalmaznak, amely mintaértékeket tartalmaz a sablon számára.

Megjegyzés:

Bár több bővítmény is kötegelhető és feldolgozható, a bővítmények sorosan vannak telepítve. Az első bővítmény telepítésének befejezése után megkísérli a következő bővítmény telepítését.

Megjegyzés:

Az Azure Arc-kompatibilis kiszolgálók nem támogatják a virtuálisgép-bővítmények üzembe helyezését és kezelését az Azure-beli virtuális gépeken. Azure-beli virtuális gépek esetén tekintse meg a következő virtuálisgép-bővítmény áttekintési cikkét .

A Log Analytics virtuálisgép-bővítmény üzembe helyezése

A Log Analytics-ügynök egyszerű üzembe helyezéséhez az alábbi minta szolgál az ügynök windowsos vagy linuxos telepítéséhez.

Sablonfájl Linuxhoz

{
    "$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'),'/OMSAgentForLinux')]",
            "type": "Microsoft.HybridCompute/machines/extensions",
            "location": "[parameters('location')]",
            "apiVersion": "2022-03-10",
            "properties": {
                "publisher": "Microsoft.EnterpriseCloud.Monitoring",
                "type": "OmsAgentForLinux",
                "enableAutomaticUpgrade": true,
                "settings": {
                    "workspaceId": "[parameters('workspaceId')]"
                },
                "protectedSettings": {
                    "workspaceKey": "[parameters('workspaceKey')]"
                }
            }
        }
    ]
}

Sablonfájl Windowshoz

{
    "$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'),'/MicrosoftMonitoringAgent')]",
            "type": "Microsoft.HybridCompute/machines/extensions",
            "location": "[parameters('location')]",
            "apiVersion": "2022-03-10",
            "properties": {
                "publisher": "Microsoft.EnterpriseCloud.Monitoring",
                "type": "MicrosoftMonitoringAgent",
                "autoUpgradeMinorVersion": true,
                "enableAutomaticUpgrade": true,
                "settings": {
                    "workspaceId": "[parameters('workspaceId')]"
                },
                "protectedSettings": {
                    "workspaceKey": "[parameters('workspaceKey')]"
                }
            }
        }
    ]
}

Paraméterfájl

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

Mentse a sablon- és paraméterfájlokat a lemezre, és szerkessze a paraméterfájlt az üzembe helyezéshez megfelelő értékekkel. Ezután telepítheti a bővítményt az erőforráscsoport összes csatlakoztatott gépére az alábbi paranccsal. A parancs a TemplateFile paraméterrel adja meg a sablont és a TemplateParameterFile paramétert egy olyan fájl megadásához, amely paramétereket és paraméterértékeket tartalmaz.

New-AzResourceGroupDeployment -ResourceGroupName "ContosoEngineering" -TemplateFile "D:\Azure\Templates\LogAnalyticsAgent.json" -TemplateParameterFile "D:\Azure\Templates\LogAnalyticsAgentParms.json"

Az egyéni szkriptbővítmény üzembe helyezése

Az egyéni szkriptbővítmény használatához a következő minta érhető el Windows és Linux rendszeren való futtatáshoz. Ha nem ismeri az Egyéni szkript bővítményt, tekintse meg a Windows egyéni szkriptbővítményét vagy a Linux egyéni szkriptbővítményét. A bővítmény hibrid gépekkel való használata során több különböző jellemzőt is figyelembe kell vennie:

  • Az Azure-beli virtuális gép egyéni szkriptbővítménnyel rendelkező támogatott operációs rendszerek listája nem alkalmazható az Azure Arc-kompatibilis kiszolgálókra. Az Azure Arc-kompatibilis kiszolgálók támogatott OS-jeinek listája itt található.

  • Az Azure-beli virtuálisgép-méretezési csoportokra vagy a klasszikus virtuális gépekre vonatkozó konfigurációs részletek nem alkalmazhatók.

  • Ha a gépeknek külsőleg kell letöltenie egy szkriptet, és csak proxykiszolgálón keresztül tud kommunikálni, konfigurálnia kell a Csatlakozás gépügynököt a proxykiszolgáló környezeti változójának beállításához.

Az egyéni szkriptbővítmény konfigurációja olyan dolgokat határoz meg, mint a szkript helye és a futtatandó parancs. Ez a konfiguráció egy Azure Resource Manager-sablonban van megadva, amely linuxos és windowsos hibrid gépekhez is elérhető.

Sablonfájl Linuxhoz

{
  "$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')]"
        }
      }
    }
  ]
}

Sablonfájl Windowshoz

{
    "$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'))]"
                }
            }
        }
    ]
}

Paraméterfájl

{
  "$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]"
    }
  }
}

A Függőségi ügynök bővítmény üzembe helyezése

Az Azure Monitor függőségi ügynök bővítményének használatához a következő minta érhető el Windows és Linux rendszeren való futtatáshoz. Ha nem ismeri a függőségi ügynököt, tekintse meg az Azure Monitor-ügynökök áttekintését.

Sablonfájl Linuxhoz

{
  "$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": {
  }
}

Sablonfájl Windowshoz

{
  "$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": {
  }
}

Sablonalapú telepítés

Mentse a sablonfájlt a lemezre. Ezután az alábbi paranccsal telepítheti a bővítményt a csatlakoztatott gépen.

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

Azure Key Vault virtuálisgép-bővítmény üzembe helyezése (előzetes verzió)

Az alábbi JSON a Key Vault virtuálisgép-bővítmény sémáját mutatja be (előzetes verzió). A bővítmény nem igényel védett beállításokat – az összes beállítás nyilvános információnak minősül. A bővítményhez szükség van a figyelt tanúsítványok listájára, a lekérdezési gyakoriságra és a céltanúsítvány-tárolóra. Ezek konkrétan a következők:

Sablonfájl Linuxhoz

{
    "$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"
        }
      }
    }
  }
 ]
}

Sablonfájl Windowshoz

{
    "$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"
        }
      }
    }
  }
 ]
}

Megjegyzés:

A megfigyelt tanúsítványok URL-címeinek űrlapnak https://myVaultName.vault.azure.net/secrets/myCertNamekell lenniük.

Ennek az az oka, hogy az /secrets elérési út a teljes tanúsítványt adja vissza, beleértve a titkos kulcsot is, míg az /certificates elérési út nem. További információ a tanúsítványokról: Key Vault-tanúsítványok

Sablonalapú telepítés

Mentse a sablonfájlt a lemezre. Ezután az alábbi paranccsal telepítheti a bővítményt a csatlakoztatott gépen.

Megjegyzés:

A virtuálisgép-bővítményhez egy rendszer által hozzárendelt identitást kellene hozzárendelni a Key Vaulthoz való hitelesítéshez. Tekintse meg , hogyan hitelesíthető a Key Vaultban felügyelt identitással Windows és Linux Azure Arc-kompatibilis kiszolgálókon.

New-AzResourceGroupDeployment -ResourceGroupName "ContosoEngineering" -TemplateFile "D:\Azure\Templates\KeyVaultExtension.json"

Következő lépések