你当前正在访问 Microsoft Azure Global Edition 技术文档网站。 如果需要访问由世纪互联运营的 Microsoft Azure 中国技术文档网站,请访问 https://docs.azure.cn

使用 Azure Monitor 日志监视 HDInsight 群集

了解如何启用 Azure Monitor 日志监视 HDInsight 中的 Hadoop 群集操作。 以及如何添加 HDInsight 监视解决方案。

Azure Monitor 日志 是用来监视云和本地环境的 Azure Monitor 服务。 该监视服务用于维持上述环境的可用性和性能。 它将收集云、本地环境和其他监视工具中由资源生成的数据。 而数据用于提供跨多个源的分析。

注意

本文最近已更新,从使用术语“Log Analytics”改为使用术语“Azure Monitor 日志”。 日志数据仍然存储在 Log Analytics 工作区中,并仍然由同一 Log Analytics 服务收集并分析。 我们正在更新术语,以便更好地反映 Azure Monitor 中的日志的角色。 有关详细信息,请参阅 Azure Monitor 术语更改

如果还没有 Azure 订阅,可以在开始前创建一个免费帐户

重要

新的 Azure Monitor 体验在所有区域作为预览功能提供。

先决条件

  • Log Analytics 工作区。 可将此工作区视为独特的 Azure Monitor 日志环境,包含自身的数据存储库、数据源和解决方案。 有关说明,请参阅创建 Log Analytics 工作区

  • 一个 Azure HDInsight 群集。 当前,可以将 Azure Monitor 日志与以下 HDInsight 群集类型配合使用:

    • Hadoop
    • HBase
    • 交互式查询
    • Kafka
    • Spark

    有关如何创建 HDInsight 群集的说明,请参阅 Azure HDInsight 入门

  • 如果使用 PowerShell,则需要 Az 模块。 确保已安装了最新版本。 如有必要,请运行 Update-Module -Name Az

  • 如果想要使用 Azure CLI,但尚未安装,请参阅 安装 Azure CLI

注意

新的 Azure Monitor 体验仅在所有区域作为预览功能提供。 建议将 HDInsight 群集和 Log Analytics 工作区放置在同一区域中,以实现更好的性能。

通过门户启用 Azure Monitor

在本部分中,将配置现有 HDInsight Hadoop 群集,以使用 Azure Log Analytics 工作区来监视作业、调试日志等等。

  1. Azure 门户中,选择群集。 群集会在新的门户页中打开。

  2. 在左侧的“监视”下,选择“监视集成”。

  3. 在主视图中的“用于 HDInsight 群集集成的 Azure Monitor”下,选择“启用”。

  4. 在“选择工作区”下拉列表中,选择现有的 Log Analytics 工作区。

  5. 选择“保存”。 需要几分钟来保存设置。

    Enable monitoring for HDInsight clusters.

如果你要禁用 Azure Monitor,可以在此门户中禁用。

使用 Azure PowerShell 启用 Azure Monitor

可以使用 Azure PowerShell Az 模块 Enable-AzHDInsightAzureMonitor cmdlet 启用 Azure Monitor 日志。

# Enter user information
$resourceGroup = "<your-resource-group>"
$cluster = "<your-cluster>"
$LAW = "<your-Log-Analytics-workspace>"
# End of user input

# obtain workspace id for defined Log Analytics workspace
$WorkspaceId = (Get-AzOperationalInsightsWorkspace `
                    -ResourceGroupName $resourceGroup `
                    -Name $LAW).CustomerId

# obtain primary key for defined Log Analytics workspace
$PrimaryKey = (Get-AzOperationalInsightsWorkspace `
                    -ResourceGroupName $resourceGroup `
                    -Name $LAW | Get-AzOperationalInsightsWorkspaceSharedKeys).PrimarySharedKey

# Enables monitoring and relevant logs will be sent to the specified workspace.
Enable-AzHDInsightAzureMonitor `
    -ResourceGroupName $resourceGroup `
    -ClusterName $cluster `
    -WorkspaceId $WorkspaceId `
    -PrimaryKey $PrimaryKey

# Gets the status of monitoring installation on the cluster.
Get-AzHDInsightAzureMonitor `
    -ResourceGroupName $resourceGroup `
    -ClusterName $cluster

若要禁用,请使用 Disable-AzHDInsightAzureMonitor cmdlet:

Disable-AzHDInsightAzureMonitor -ResourceGroupName $resourceGroup `
-ClusterName $cluster

使用 Azure CLI 启用 Azure Monitor

可以使用 Azure CLI az hdinsight azure-monitor enable 命令启用 Azure Monitor 日志。

# set variables
export resourceGroup=RESOURCEGROUPNAME
export cluster=CLUSTERNAME
export LAW=LOGANALYTICSWORKSPACENAME

# Enable the Azure Monitor logs integration on an HDInsight cluster.
az hdinsight azure-monitor enable --name $cluster --resource-group $resourceGroup --workspace $LAW

# Get the status of Azure Monitor logs integration on an HDInsight cluster.
az hdinsight azure-monitor show --name $cluster --resource-group $resourceGroup

若要禁用,请使用 az hdinsight monitor disable 命令。

az hdinsight azure-monitor disable --name $cluster --resource-group $resourceGroup

使用 HDInsight 中现成的见解来监视单个群集

HDInsight 提供特定于工作负载的工作簿来帮助你快速获取见解。 此工作簿从 HDInsight 群集收集重要性能指标,并为最常用的方案提供可视化效果和仪表板。 现成的见解提供单个 HDInsight 群集的完整视图,包括资源利用率和应用程序状态。

可用的 HDInsight 工作簿:

  • HDInsight Spark 工作簿
  • HDInsight Kafka 工作簿
  • HDInsight HBase 工作簿
  • HDInsight Hive/LLAP 工作簿

Spark 工作簿的屏幕截图 Spark workbook screenshot.

配置性能计数器

Azure monitor 支持收集并分析群集中节点的性能指标。 有关详细信息,请参阅 Azure Monitor 中的 Linux 性能数据源

群集审核

HDInsight 支持通过导入以下日志类型进行 Azure Monitor 日志的群集审核:

  • log_gateway_audit_CL - 此表提供来自群集网关节点的审核日志,其中显示了成功和失败的登录尝试。
  • log_auth_CL - 此表提供 SSH 日志,其中显示了成功和失败的登录尝试。
  • log_ambari_audit_CL - 此表提供了 Ambari 中的审核日志。
  • log_ranger_audti_CL此表提供了针对 ESP 群集的 Apache Ranger 审核日志。

更新 HDInsight Azure Monitor 集成使用的 Log Analytics (OMS) 代理

在群集上启用 Azure Monitor 集成后,Log Analytics 代理或 Operations Management Suite (OMS) 代理将安装在群集上,除非你禁用再重新启用 Azure Monitor 集成,否则该代理不会更新。 如果需要更新群集上的 OMS 代理,请完成以下步骤。 如果你在防火墙后操作,可能需要先满足防火墙后的群集的先决条件,然后再完成这些步骤。

  1. Azure 门户中,选择群集。 群集将在新的门户页面中打开。
  2. 从左侧的“监视”下,选择“Azure Monitor”。
  3. 记下当前 Log Analytics 工作区的名称。
  4. 在主视图中的“Azure Monitor 集成”下,禁用切换开关,然后选择“保存” 。
  5. 保存设置后,重新启用“Azure Monitor 集成”切换开关,并确保选择相同的 Log Analytics 工作区,然后选择“保存” 。

如果已在群集上启用 Azure Monitor 集成,则更新 OMS 代理也会更新开放管理基础结构 (OMI) 版本。 可运行以下命令检查群集上的 OMI 版本:

 sudo /opt/omi/bin/omiserver –version

后续步骤