如何通过 Azure ARM 模板启用 Windows 故障转储

如何通过 Azure ARM 模板启用 Windows 故障转储

我们有一个在 Azure VMSS 中的大约 140 个虚拟机上运行的解决方案。

如何通过 ARM 模板启用这些内存转储选项?

除此之外,我如何使用 PowerShell 脚本启用它?

启用故障转储

答案1

是的,您可以使用 DSC 或 CSE 将信息添加到 ARM 模板,但 ksy 是脚本中的内容。以下是脚本中应包含的示例信息,enableDump.ps1

# Setup the Guest OS to collect a kernel dump on an OS crash event
Set-ItemProperty -Path 'HKLM:\SYSTEM\CurrentControlSet\Control\CrashControl' -name CrashDumpEnabled -Type DWord -force -Value 2
Set-ItemProperty -Path 'HKLM:\SYSTEM\CurrentControlSet\Control\CrashControl' -name DumpFile -Type ExpandString -force -Value "%SystemRoot%\MEMORY.DMP"
Set-ItemProperty -Path 'HKLM:\SYSTEM\CurrentControlSet\Control\CrashControl' -name NMICrashDump -Type DWord -force -Value 1

引用脚本中的值; https://support.microsoft.com/en-us/help/254649/overview-of-memory-dump-file-options-for-windows

Arm Template 中的 CustomScript 设置可以简单如下;

  {
    "type": "extensions",
    "name": "CustomScriptExtension",
    "apiVersion": "2017-03-30",
    "location": "[parameters('location')]",
    "dependsOn": [
      "[variables('vmName')]"
    ],
    "properties": {
      "publisher": "Microsoft.Compute",
      "type": "CustomScriptExtension",
      "typeHandlerVersion": "1.8",
      "autoUpgradeMinorVersion": true,
      "settings": {
        "fileUris": [
          "https://xxxxxxx.blob.core.windows.net/buildServer1/enableDump.ps1"
        ],
        "commandToExecute": "powershell -ExecutionPolicy Unrestricted -File ./EnableCrashDump.ps1"
      }
    }
  }

希望这可以帮助。

答案2

您无法使用 ARM 模板执行此操作,但是,您可以使用脚本或 powershell dsc 扩展(作为 arm 模板的一部分)来配置它。这些扩展的示例:

{
    "type": "Microsoft.Compute/virtualMachines/extensions",
    "name": "[concat(variables('vmName'),'/installcustomscript')]",
    "apiVersion": "2015-05-01-preview",
    "location": "[parameters('location')]",
    "properties": {
        "publisher": "Microsoft.Azure.Extensions",
        "type": "CustomScript",
        "typeHandlerVersion": "2.0",
        "autoUpgradeMinorVersion": true,
        "settings": {
            "fileUris": [
                "[concat(parameters('_artifactsLocation'), '/scripts/hello.sh')]"
            ],
            "commandToExecute": "[parameters('commandToExecute')]"
        }
    }
},
{
    "apiVersion": "2015-05-01-preview",
    "type": "Microsoft.Compute/virtualMachines/extensions",
    "name": "[concat(parameters('vmName'),'/enabledsc')]",
    "location": "[parameters('location')]",
    "properties": {
        "publisher": "Microsoft.Powershell",
        "type": "DSC",
        "typeHandlerVersion": "2.0",
        "settings": {
            "Mode": "[parameters('mode')]",
            "FileUri": "[parameters('fileUri')]"
        },
        "protectedSettings": {
            "StorageAccountName": "[parameters('storageAccountName')]",
            "StorageAccountKey": "[parameters('storageAccountKey')]",
            "RegistrationUrl": "[parameters('registrationUrl')]",
            "RegistrationKey": "[parameters('registrationKey')]"
        }
    }
}

阅读:
https://docs.microsoft.com/en-us/azure/virtual-machines/extensions/custom-script-windows
https://docs.microsoft.com/en-us/azure/virtual-machines/extensions/dsc-overview

相关内容