你当前正在访问 Microsoft Azure Global Edition 技术文档网站。 如果需要访问由世纪互联运营的 Microsoft Azure 中国技术文档网站,请访问 https://docs.azure.cn。
本文介绍如何使用自定义策略定义通过 Azure Policy 将 Azure Monitor 代理(AMA)部署到已启用 Arc 的服务器。 使用 Azure Policy 可确保 Azure Monitor 在已启用 Arc 的所选服务器上运行,并且 AMA 会自动安装在新添加的 Arc 资源上。
通过自定义策略定义部署 Azure Monitor 代理涉及两个主要步骤:
- 选择现有的数据收集规则 (DCR),或者创建新的规则
- 创建和部署策略定义
为了使 Azure Monitor 在计算机上工作,它需要与数据收集规则(DCR)相关联。 创建策略定义时,请包含 DCR 的资源 ID。
选择数据收集规则
数据收集规则定义了 Azure Monitor 中的数据收集过程。 它们指定应收集的数据以及应将该数据发送到的位置。 你需要选择或创建与策略定义关联的 DCR。
From your browser, go to the Azure portal.
导航到“Monitor | 概述”页。 Under Settings, select Data Collection Rules to show the list of existing DCRs.
选择要使用的 DCR。
Select Overview, then select JSON View to view the JSON code for the DCR:
Locate the Resource ID field at the top of the Resource JSON pane, then select the button to copy the resource ID. 创建策略定义时,需要使用此资源 ID。
创建并部署策略定义
为了让 Azure Policy 检查已启用 Arc 的服务器上是否安装了 Azure Monitor 代理,您需要创建自定义策略定义来执行以下操作:
评估新 VM 是否已安装代理并与 DCR 相关联。
强制实施修正任务以安装 Azure Monitor 代理,并在不符合策略的任何 VM 上创建与 DCR 的关联。
根据计算机的操作系统选择以下策略定义模板之一:
这些模板用于创建策略来配置计算机,从而运行 Azure Monitor 代理并将这些计算机关联到 DCR。
Select Assign initiative to begin creating the policy definition. 输入每个选项卡的适用信息。有关这些选项的详细信息,请参阅 “创建策略分配 ”。
On the Parameters tab, paste the Data Collection Rule Resource ID that you copied during the previous procedure:
选择 “查看 + 创建 ”以完成策略创建并将其部署到适用的计算机。 部署 Azure Monitor 代理后,已启用 Azure Arc 的服务器可以应用其服务并将其用于日志收集。
