为群集设置 Azure Monitor 日志Set up Azure Monitor logs for a cluster

要监视群集级别的事件,建议使用 Azure Monitor 日志。Azure Monitor logs is our recommendation to monitor cluster level events. 可以通过 Azure 资源管理器、PowerShell 或 Azure 市场设置 Log Analytics 工作区。You can set up Log Analytics workspace through Azure Resource Manager, PowerShell, or Azure Marketplace. 对于你的部署,如果你维护其更新后的资源管理器模板供将来使用,请使用同一模板来设置 Azure Monitor 日志环境。If you maintain an updated Resource Manager template of your deployment for future use, use the same template to set up your Azure Monitor logs environment. 如果部署的群集已启用诊断,则通过市场部署更方便。Deployment via Marketplace is easier if you already have a cluster deployed with diagnostics enabled. 如果你在要部署到的帐户中没有订阅级别访问权限,请通过 PowerShell 或资源管理器模板进行部署。If you do not have subscription-level access in the account to which you are deploying to, deploy by using PowerShell or the Resource Manager template.


若要设置 Azure Monitor 日志来监视群集,需要启用诊断来查看群集级别事件或平台级别事件。To set up Azure Monitor logs to monitor your cluster, you need to have diagnostics enabled to view cluster-level or platform-level events. 有关详细信息,请参阅如何在 Windows 群集中设置诊断如何在 Linux 群集中设置诊断Refer to how to set up diagnostics in Windows clusters and how to set up diagnostics in Linux clusters for more


本文最近已更新,从使用术语“Log Analytics”改为使用术语“Azure Monitor 日志”。This article was recently updated to use the term Azure Monitor logs instead of Log Analytics. 日志数据仍然存储在 Log Analytics 工作区中,并仍然由同一 Log Analytics 服务收集并分析。Log data is still stored in a Log Analytics workspace and is still collected and analyzed by the same Log Analytics service. 我们正在更新术语,以便更好地反映 Azure Monitor 中日志的角色。We are updating the terminology to better reflect the role of logs in Azure Monitor. 有关详细信息,请参阅 Azure Monitor 术语更改See Azure Monitor terminology changes for details.


本文进行了更新,以便使用新的 Azure PowerShell Az 模块。This article has been updated to use the new Azure PowerShell Az module. 你仍然可以使用 AzureRM 模块,至少在 2020 年 12 月之前,它将继续接收 bug 修补程序。You can still use the AzureRM module, which will continue to receive bug fixes until at least December 2020. 若要详细了解新的 Az 模块和 AzureRM 兼容性,请参阅新 Azure Powershell Az 模块简介To learn more about the new Az module and AzureRM compatibility, see Introducing the new Azure PowerShell Az module. 有关 Az 模块安装说明,请参阅安装 Azure PowerShellFor Az module installation instructions, see Install Azure PowerShell.

使用 Azure 资源管理器部署 Azure Monitor 日志Deploy Azure Monitor logs with Azure Resource Manager

使用资源管理器模板部署群集时,该模板还会新建一个 Log Analytics 工作区,向其添加 Service Fabric 解决方案,并将其配置为读取相应存储表中的数据。When you deploy a cluster by using a Resource Manager template, the template creates a new Log Analytics workspace, adds the Service Fabric solution to the workspace, and configures it to read data from the appropriate storage tables.

可使用此示例模板,还可进行修改,使其满足你的要求。You can use and modify this sample template to meet your requirements. 此模板执行以下操作This template does the following

  • 创建一个 5 节点 Service Fabric 群集Creates a 5 node Service Fabric cluster
  • 创建 Log Analytics 工作区和 Service Fabric 解决方案Creates a Log Analytics workspace and Service Fabric solution
  • 配置 Log Analytics 代理以收集 2 个示例性能计数器并将其发送到工作区Configures the Log Analytics agent to collect and send 2 sample performance counters to the workspace
  • 配置 WAD 以收集 Service Fabric 并将其发送到 Azure 存储表 (WADServiceFabric*EventTable)Configures WAD to collect Service Fabric and sends them to Azure storage tables (WADServiceFabric*EventTable)
  • 配置 Log Analytics 工作区以从这些表中读取事件Configures the Log Analytics workspace to read the events from these tables

[!NOTE] 为了适合 Azure 中国云环境,必须修改从 GitHub 存储库“Azure-Sample”下载或引用的模板。Templates you downloaded or referenced from the GitHub Repo "Azure-Sample" must be modified in order to fit in the Azure China Cloud Environment. 例如,替换某些终结点(将“blob.core.windows.net”替换为“blob.core.chinacloudapi.cn”,将“cloudapp.azure.com”替换为“cloudapp.chinacloudapi.cn”);必要时更改某些不受支持的位置、VM 映像、VM 大小、SKU 以及资源提供程序的 API 版本。For example, replace some endpoints -- "blob.core.windows.net" by "blob.core.chinacloudapi.cn", "cloudapp.azure.com" by "cloudapp.chinacloudapi.cn"; change some unsupported Location, VM images, VM sizes, SKU and resource-provider's API Version when necessary.

在本文中,请在运行 powershell 命令之前更改以下项。In this article, change the following items before run the powershell command.

  1. 更改 computeLocationomsRegion 参数的以下属性。Change the following properties of computeLocation and omsRegion parameters.
    • defaultValue 的属性更新为 chinaeast2Update the property of defaultValue as chinaeast2.
    • allowedValues 的属性更新为 ["chinaeast","chinaeast2","chinanorth","chinanorth2"]Update the properties of allowedValues as ["chinaeast","chinaeast2","chinanorth","chinanorth2"]
  2. 将所有终结点后缀从 windows.net 更改为 chinacloudapi.cnChange all the endpoint suffixes from windows.net to chinacloudapi.cn.

可以通过使用 Azure PowerShell 模块中的 New-AzResourceGroupDeployment API,将该模板作为资源管理器升级部署到群集。You can deploy the template as a Resource Manager upgrade to your cluster by using the New-AzResourceGroupDeployment API in the Azure PowerShell module. 示例命令如下:An example command would be:

New-AzResourceGroupDeployment -ResourceGroupName "<resourceGroupName>" -TemplateFile "<templatefile>.json" 

Azure 资源管理器可检测出此命令要更新到现有资源。Azure Resource Manager detects that this command is an update to an existing resource. 它仅处理驱动现有部署的模板和提供的新模板之间的变化。It only processes the changes between the template driving the existing deployment and the new template provided.

使用 Azure PowerShell 部署 Azure Monitor 日志Deploy Azure Monitor logs with Azure PowerShell

也可以使用 New-AzOperationalInsightsWorkspace 命令,通过 PowerShell 来部署日志分析资源。You can also deploy your log analytics resource via PowerShell by using the New-AzOperationalInsightsWorkspace command. 要使用此方法,请确保已安装 Azure PowerShellTo use this method, make sure you have installed Azure PowerShell. 使用此脚本新建 Log Analytics 工作区,并向其添加 Service Fabric 解决方案:Use this script to create a new Log Analytics workspace and add the Service Fabric solution to it:

$SubID = "<subscription ID>"
$ResourceGroup = "<Resource group name>"
$Location = "<Resource group location>"
$WorkspaceName = "<Log Analytics workspace name>"
$solution = "ServiceFabric"

# Sign in to Azure and access the correct subscription
Connect-AzAccount -Environment AzureChinaCloud
Select-AzSubscription -SubscriptionId $SubID 

# Create the resource group if needed
try {
    Get-AzResourceGroup -Name $ResourceGroup -ErrorAction Stop
} catch {
    New-AzResourceGroup -Name $ResourceGroup -Location $Location

New-AzOperationalInsightsWorkspace -Location $Location -Name $WorkspaceName -Sku Standard -ResourceGroupName $ResourceGroup
Set-AzOperationalInsightsIntelligencePack -ResourceGroupName $ResourceGroup -WorkspaceName $WorkspaceName -IntelligencePackName $solution -Enabled $true

完成后,请按照前一部分中的步骤将 Azure Monitor 日志连接到相应的存储帐户。When you're done, follow the steps in the preceding section to connect Azure Monitor logs to the appropriate storage account.

还可添加其他解决方案或使用 PowerShell 对 Log Analytics 工作区进行其他修改。You can also add other solutions or make other modifications to your Log Analytics workspace by using PowerShell. 有关详细信息,请参阅使用 PowerShell 管理 Azure Monitor 日志To learn more, see Manage Azure Monitor logs using PowerShell.

后续步骤Next steps