azure - 如何使用 PowerShell 安装和配置 Microsoft Monitoring Agent 以与 OMS 网关(代理)一起使用

标签 azure azure-devops azure-powershell azure-monitoring azure-rm-template

如何使用 Powershell 安装和配置 Microsoft Monitoring Agent (MMA) 以与 OMS 网关配合使用? 没有任何自动化示例告诉您如何使用 OMS 网关来完成此操作。

我发现这是手动执行此操作的演练: http://azurepost.com/oms-gateway-ga-installation-configuration-walkthrough/

还有这个: https://learn.microsoft.com/en-us/azure/azure-monitor/platform/gateway

自动化:

此模板适用于 ARM 模板,但不支持 OMS 网关: Enabling the Microsoft Monitoring Agent in Windows JSON Templates

这个适用于 Powershell,但不支持 OMS 网关 oms-windows.md

所有自动化示例都没有告诉您如何使用 OMS 网关来完成此操作。 事实上,来自 Property values 的文档看来不可能。仅记录的属性是workspaceId 和workspaceKey。未列出 OMS 网关配置所需的其他属性(即代理、用户 ID、密码)。

最佳答案

解决方案:通过 ARM 或 PS 部署和配置 MMA 以与 OMS 网关一起使用。 这些属性适用于 ARM 和 PS。 PS 通常在底层构建 ARM 模板。 完整的属性集是:

记录的扩展属性

  • 工作空间ID
  • 工作区 key

未记录的扩展属性

控制面板;Microsoft Monitoring Agent 应用程序,用于确定大多数这些值的含义。

  • enableAutomaticManagement:相当于“选项卡:‘操作管理器’,自动更新 AD DS 的管理组分配”

  • proxyUri:相当于“选项卡:‘代理设置’、代理服务器”

  • proxyUser:相当于“选项卡:‘代理设置’、用户名”
  • proxyPassword:#相当于“选项卡:‘代理设置’、密码”
  • azureRegionId:不确定,但我认为这可能与 Log Analytics 位于不同区域有关。使用 Get-AzureRMLocation、Location 确定有效值

  • stopOnMultipleConnections:???

  • azureResourceId:???

通过 Powershell 部署:

Import-Module Az.Compute
Connect-AzAccount 
Set-AzContext -Subscription  $subscriptionId

$settings = @{ `
    "workspaceId" = $workspaceId; `
    "proxyUri" = $proxyUri; `
    "azureRegionId" = $azureRegionId `
}
$protectedSettings = @{"workspaceKey" = $workspaceKey}

$extensions = Get-AzVMExtension `
    -ResourceGroupName $resourceGroupName `
    -VMName $vmName 

#If extension was already installed and the ExtensionName is not 'MicrosoftMonitoringAgent',
#re-install will fail. Therefore, we need to remove extension before proceeding.
foreach($extension in $extensions)
{
    if ($extension.ExtensionType -eq "MicrosoftMonitoringAgent")
    {
        Remove-AzVMExtension `
            -ResourceGroupName $resourceGroupName `
            -VMName $vmName `
            -Name $extension.Name `
            -Confirm:$false `
            -Force:$true
    }

}

#install MMA Extension
$guid = New-Guid 
Set-AzVMExtension `
    -ResourceGroupName $resourceGroupName `
    -VMName $vmName `
    -ExtensionType "MicrosoftMonitoringAgent" `
    -ExtensionName "MicrosoftMonitoringAgent" `
    -Publisher "Microsoft.EnterpriseCloud.Monitoring" `
    -TypeHandlerVersion 1.0 `
    -ForceRerun $guid `
    -Settings $settings `
    -ProtectedSettings $protectedSettings `
    -Location $azureRegionId 

通过 ARM 模板部署

{
  "$schema": "http://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json",
  "contentVersion": "1.0.0.0",
  "parameters": {
    "location": {
      "type": "string"
    },
    "serverName": {
      "type": "string"
    },
    "workspaceId": {
      "type": "string",
      //from the blob's etag property; changes each time update occurs
      "defaultValue": "guid-guid-guid-guid",
      "metadata": {
        "description": "To be provided from keyvault; equivalent to Tab: 'Azure Log Analytics (OMS)', Add or Edit Popup"
      }
    },
    "proxyUri": {
      "type": "string",
      "defaultValue": "101.102.103.104:8080",
      "metadata": {
        "description": "To be provided from keyvault; equivalent to Tab: 'Proxy Settings', Proxy Server"
      }
    },
    "workspaceKey": {
      "type": "securestring",
      "defaultValue": "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx==",
      "metadata": {
        "description": "To be provided from keyvault; equivalent to Tab: 'Azure Log Analytics (OMS)', Add or Edit Popup"
      }
    },

    "forceUpdateTag": {
      "defaultValue": "[newGuid()]",
      "type": "string",
      "metadata": {
        "description": "Forces extension to deploy every time."
      }
    }
  },
  "resources": [
    {
      "type": "Microsoft.Compute/virtualMachines/extensions",
      "apiVersion": "2018-10-01",
      "name": "[concat(parameters('serverName'),'/MicrosoftMonitoringAgent')]",
      "location": "[parameters('location')]",
      "properties": {
        "publisher": "Microsoft.EnterpriseCloud.Monitoring",
        "type": "MicrosoftMonitoringAgent",
        "typeHandlerVersion": "1.0",
        "autoUpgradeMinorVersion": "true",
        "forceUpdateTag": "[parameters('forceUpdateTag')]",
        "settings": {
          "workspaceId": "[parameters('workspaceId')]",
          "proxyUri": "[parameters('proxyUri')]",
          "azureRegionId": "[parameters('location')]"
        },
        "protectedSettings": {
          "workspaceKey": "[parameters('workspaceKey')]"
        }
      }
    }
  ]
}

(请有人告诉我,我浪费了时间,并且某处有一个“Interogate Extension”powershell 命令...) 我是怎么想出来的?我使用该门户来部署 MMA 扩展。我转到虚拟机并在以下位置找到了已安装的扩展: C:\Packages\Plugins\Microsoft.EnterpriseCloud.Monitoring.MicrosoftMonitoringAgent

我反编译了: Microsoft.EnterpriseCloud.Monitoring.MicrosoftMonitoringAgent.ExtensionShared.dll 并查找确切的字符串:workspaceIdworkspaceKey。我找到了这些类:MMAExtensionPublicSettings、MMAExtensionProtectedSettings。这些类包含有效的扩展属性。

using Newtonsoft.Json;
using System;
using System.Runtime.CompilerServices;

namespace Microsoft.EnterpriseCloud.Monitoring.MicrosoftMonitoringAgent.Extension.MMADataModels
{
    public class MMAExtensionPublicSettings
    {
        [JsonProperty(PropertyName = "azureRegionId")]
        public string AzureRegionId{ get; set; }

        [JsonProperty(PropertyName = "azureResourceId")]
        public string AzureResourceId { get; set; }

        [JsonProperty(PropertyName = "enableAutomaticManagement")]
        public bool EnableAutomaticManagement { get; set; }

        [JsonProperty(PropertyName = "proxyUri")]
        public string ProxyUri { get; set; }

        [JsonProperty(PropertyName = "proxyUser")]
        public string ProxyUser { get; set; }

        [JsonProperty(PropertyName = "stopOnMultipleConnections")]
        public bool StopOnMultipleConnections { get; set; }

        [JsonProperty(PropertyName = "workspaceId")]
        public string WorkspaceId { get; set; }
        public MMAExtensionPublicSettings()
        {
        }
    }
}

** - MMAExtensionProtectedSettings

using Newtonsoft.Json;
using System;
using System.Runtime.CompilerServices;    
namespace Microsoft.EnterpriseCloud.Monitoring.MicrosoftMonitoringAgent.Extension.MMADataModels
{
    public class MMAExtensionProtectedSettings
    {
        [JsonProperty(PropertyName="proxyPassword")]
        public string ProxyPassword
        {
            get;
            set;
        }

        [JsonProperty(PropertyName="workspaceKey")]
        public string WorkspaceKey
        {
            get;
            set;
        }

        public MMAExtensionProtectedSettings()
        {
        }
    }
}

关于azure - 如何使用 PowerShell 安装和配置 Microsoft Monitoring Agent 以与 OMS 网关(代理)一起使用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58019220/

相关文章:

Azure ApplicationGateWay requestRoutingRules 在已定义时不会被引用

azure - Azure 数据工厂的发布流程是否支持导出 ARM 模板?

azure - 如何使用 AzCopy 工具将数据从 Azure CosmosDb 复制到本地?

node.js - 尝试将站点部署到 Azure 时出现应用程序错误

azure-devops - Azure YAML 管道条件插入不起作用

azure - 如何获取我的订阅中显示 CPU 核心的 Azure VMS 列表?

azure - Azure 中的 "You do not have permission to view this directory or page"错误

azure - 将 Azure 连接传递到 Azure DevOps 管道中的控制台应用程序

azure - Powershell Azure Save-AzureWebsiteLog 引发 MaxReceivedMessageSize 错误

azure - 使用 ARM Powershell 或门户在 Azure 订阅中查找可用的虚拟机大小