本文介绍如何使用 Azure 资源管理器模板(ARM 模板 )将虚拟机(VM)扩展 部署到已启用 Azure Arc 的服务器(已启用 Arc 的计算机)。
若要使用 ARM 模板将扩展部署到已启用 Arc 的服务器,请将扩展添加到模板,并使用模板部署执行它们。 可以使用 Azure PowerShell 在连接到 Azure Arc 的 Linux 或 Windows 计算机上部署扩展。
本文介绍如何使用模板文件将多个不同的 VM 扩展部署到已启用 Arc 的服务器,以及一些扩展的单独参数文件。 在部署之前,将示例中的示例值替换为自己的值。
部署命令
这些示例 PowerShell 命令基于 ARM 模板中的信息,在资源组中所有已启用 Arc 的服务器上安装扩展。 该命令使用 TemplateFile 参数来指定模板。 如果需要参数文件, TemplateParameterFile 则包含参数以指定包含参数和参数值的文件。 将占位符替换为部署的相应值。
若要部署 ARM 模板和参数文件,请使用以下命令,将示例值替换为你自己的值:
New-AzResourceGroupDeployment -ResourceGroupName "<resource-group-name>" -TemplateFile "<template-filename.json>" -TemplateParameterFile "<parameter-filename.json>"
例如:
New-AzResourceGroupDeployment -ResourceGroupName "ContosoEngineering" -TemplateFile "D:\Azure\Templates\AzureMonitorAgent.json" -TemplateParameterFile "D:\Azure\Templates\AzureMonitorAgentParams.json"
若要在没有参数文件的情况下部署 ARM 模板,请使用以下命令,将示例值替换为你自己的值:
New-AzResourceGroupDeployment -ResourceGroupName "<resource-group-name>" -TemplateFile "<template-filename.json>"
例如:
New-AzResourceGroupDeployment -ResourceGroupName "ContosoEngineering" -TemplateFile "D:\Azure\Templates\DependencyAgent.json"
部署 Azure Monitor 代理 VM 扩展
若要将 Azure Monitor 代理 部署到已启用 Arc 的服务器,请使用以下示例模板之一在 Linux 或 Windows 上安装代理。
资源类型
所有已启用 Arc 的服务器 VM 扩展都使用资源类型
Microsoft.HybridCompute/machines/extensions(从 Azure VM 扩展资源类型映射)。
适用于 Linux 的 Azure Monitor 代理模板文件(已启用 Arc 的服务器)
参数
-
vmName(字符串,示例:myArcMachine -
location(字符串,示例:chinaeast2 -
workspaceId(字符串,示例:Log Analytics 工作区 ID) -
workspaceKey(字符串,示例:Log Analytics 主键)
{
"$schema": "https://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.HybridCompute/machines/extensions",
"location": "[parameters('location')]",
"apiVersion": "2025-06-01",
"properties": {
"publisher": "Microsoft.Azure.Monitor",
"type": "AzureMonitorLinuxAgent",
"enableAutomaticUpgrade": true,
"settings": {
"workspaceId": "[parameters('workspaceId')]"
},
"protectedSettings": {
"workspaceKey": "[parameters('workspaceKey')]"
}
}
}
]
}
适用于 Windows 的 Azure Monitor 代理模板文件(已启用 Arc 的服务器)
参数
-
vmName(字符串,示例:myArcMachine -
location(字符串,示例:chinaeast2 -
workspaceId(字符串,示例:Log Analytics 工作区 ID) -
workspaceKey(字符串,示例:Log Analytics 主键)
{
"$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.HybridCompute/machines/extensions",
"location": "[parameters('location')]",
"apiVersion": "2025-06-01",
"properties": {
"publisher": "Microsoft.Azure.Monitor",
"type": "AzureMonitorWindowsAgent",
"autoUpgradeMinorVersion": true,
"enableAutomaticUpgrade": true,
"settings": {
"workspaceId": "[parameters('workspaceId')]"
},
"protectedSettings": {
"workspaceKey": "[parameters('workspaceKey')]"
}
}
}
]
}
Azure Monitor 代理参数文件(已启用 Arc 的服务器)
此参数文件可用于 Linux 和 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>"
}
}
}
保存模板和参数文件,并使用部署的适当值编辑参数文件。
部署 Azure Monitor 代理
- 先决条件:已启用 Arc 的服务器已连接,并且存在 Log Analytics 工作区。
-
部署:
New-AzResourceGroupDeployment -ResourceGroupName "<resource-group-name>" -TemplateFile "AzureMonitorAgent.json" -TemplateParameterFile "AzureMonitorAgentParams.json" - 验证:在 Azure 门户中,确认扩展状态在已启用 Arc 的服务器上 成功 。
部署自定义脚本扩展
若要在已启用 Arc 的服务器上使用自定义脚本扩展,请为 Linux 或 Windows 部署以下示例模板之一。 有关详细信息,请参阅 适用于 Linux 的自定义脚本扩展 或 适用于 Windows 的自定义脚本扩展。
适用于 Linux 的自定义脚本扩展模板文件(已启用 Arc 的服务器)
参数
-
vmName(字符串,示例:myArcMachine -
location(字符串,示例:chinaeast2 -
fileUris(数组,示例:脚本 URL) -
commandToExecute(securestring,示例:sh script.sh
{
"$schema": "https://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": "2025-06-01",
"properties": {
"publisher": "Microsoft.Azure.Extensions",
"type": "CustomScript",
"autoUpgradeMinorVersion": true,
"settings": {},
"protectedSettings": {
"commandToExecute": "[parameters('commandToExecute')]",
"fileUris": "[parameters('fileUris')]"
}
}
}
]
}
适用于 Windows 的自定义脚本模板文件(已启用 Arc 的服务器)
参数
-
vmName(字符串,示例:myArcMachine -
location(字符串,示例:chinaeast2 -
fileUris(字符串,示例:脚本 URL) -
arguments(securestring,可选,示例:-Param1 Value1
{
"$schema": "https://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'))]"
}
}
}
]
}
部署自定义脚本扩展
- 先决条件:脚本文件可从已启用 Arc 的服务器访问。
-
部署:
New-AzResourceGroupDeployment -ResourceGroupName "<resource-group-name>" -TemplateFile "CustomScript.json"
部署 Dependency Agent 扩展件
使用以下模板将依赖项代理部署到已启用 Arc 的 Linux 或 Windows 计算机。
适用于 Linux 的依赖项代理模板文件(已启用 Arc 的服务器)
参数
-
vmName(字符串,示例:myArcMachine
{
"$schema": "https://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#",
"contentVersion": "1.0.0.0",
"parameters": {
"vmName": {
"type": "string"
}
},
"resources": [
{
"type": "Microsoft.HybridCompute/machines/extensions",
"name": "[concat(parameters('vmName'),'/DAExtension')]",
"apiVersion": "2025-06-01",
"location": "[resourceGroup().location]",
"properties": {
"publisher": "Microsoft.Azure.Monitoring.DependencyAgent",
"type": "DependencyAgentLinux",
"enableAutomaticUpgrade": true
}
}
]
}
适用于 Windows 的依赖项代理模板文件(已启用 Arc 的服务器)
参数
-
vmName(字符串,示例:myArcMachine
{
"$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": {
}
}
部署依赖项代理
- 先决条件:为已启用 Arc 的服务器启用 Azure Monitor。
-
部署:
New-AzResourceGroupDeployment -ResourceGroupName "<resource-group-name>" -TemplateFile "DependencyAgent.json" - 验证:在 Azure 门户中,确认扩展状态在已启用 Arc 的服务器上 成功 。
部署 Azure Key Vault 扩展
以下 JSON 显示了 Azure Key Vault 扩展的架构。 此扩展不需要受保护的设置,因为其所有设置都被视为公共信息。 该扩展需要受监视的证书列表、轮询频率和目标证书存储。
适用于 Linux 的 Azure Key Vault 模板文件(已启用 Arc 的服务器)
参数
-
vmName(字符串,示例:myArcMachine -
location(字符串,示例:chinaeast2 -
autoUpgradeMinorVersion(bool,示例:true -
pollingIntervalInS(int,示例:3600 -
certificateStoreName(Linux 上忽略的字符串) -
certificateStoreLocation(字符串,示例:/var/lib/waagent/Microsoft.Azure.KeyVault -
observedCertificates(字符串,示例:Key Vault 证书 URI) -
msiEndpoint(字符串,示例:http://localhost:40342/metadata/identity -
msiClientId(字符串,示例:托管标识客户端 ID)
{
"$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.cn/secrets/mycertificate"
},
"authenticationSettings": {
"msiEndpoint": "http://localhost:40342/metadata/identity"
}
}
}
}
]
}
适用于 Windows 的 Azure Key Vault 模板文件(已启用 Arc 的服务器)
参数
-
vmName(字符串,示例:myArcMachine -
location(字符串,示例:chinaeast2 -
autoUpgradeMinorVersion(bool,示例:true -
pollingIntervalInS(int,示例:3600 -
certificateStoreName(字符串,示例:MY -
linkOnRenewal(bool,示例:false -
certificateStoreLocation(字符串,示例:LocalMachine -
requireInitialSync(bool,示例:true -
observedCertificates(字符串,示例:Key Vault 证书 URI) -
msiEndpoint(字符串,示例:http://localhost:40342/metadata/identity -
msiClientId(字符串,示例:托管标识客户端 ID)
{
"$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.cn"
},
"authenticationSettings": {
"msiEndpoint": "http://localhost:40342/metadata/identity"
}
}
}
}
]
}
注意
你观察到的证书 URL 应采用 https://myVaultName.vault.azure.cn/secrets/myCertName 格式。 这是因为 /secrets 路径会返回完整证书(包括私钥),但 /certificates 路径不会。 有关证书的详细信息,请参阅 Azure Key Vault 密钥、机密和证书概述。
保存模板,并根据您环境的需要进行编辑。 然后,通过运行本文前面找到的 PowerShell 部署命令 ,将 Azure Key Vault 扩展安装到连接的计算机。
小窍门
Azure Key Vault 扩展需要系统分配的标识才能向 Key Vault 进行身份验证。 有关详细信息,请参阅 使用已启用 Azure Arc 的服务器对 Azure 资源进行身份验证。
相关内容
- 详细了解 已启用 Azure Arc 的服务器支持的 VM 扩展。
- 了解如何使用 Azure PowerShell、 Azure 门户或 Azure CLI 部署、管理和删除 VM 扩展。
- 在故障排除 VM 扩展的指南中浏览故障排除信息。