Azure 虚拟机代理概述Azure Virtual Machine Agent overview

Azure 虚拟机代理(VM 代理)是受保护的轻型进程,用于管理虚拟机 (VM) 与 Azure 结构控制器的交互。The Azure Virtual Machine Agent (VM Agent) is a secure, lightweight process that manages virtual machine (VM) interaction with the Azure Fabric Controller. VM 代理有一个主要角色,目的是启用和执行 Azure 虚拟机扩展。The VM Agent has a primary role in enabling and executing Azure virtual machine extensions. VM 扩展可用于对 VM 进行部署后配置,例如安装和配置软件。VM Extensions enable post-deployment configuration of VM, such as installing and configuring software. VM 扩展还可启用恢复功能,例如重置 VM 的管理密码。VM extensions also enable recovery features such as resetting the administrative password of a VM. 没有 Azure VM 代理,VM 扩展将无法运行。Without the Azure VM Agent, VM extensions cannot be run.

本文详细介绍如何安装和检测 Azure 虚拟机代理。This article details installation and detection of the Azure Virtual Machine Agent.

安装 VM 代理Install the VM Agent

Azure 市场映像Azure Marketplace image

Azure VM 代理默认安装在任何通过 Azure 市场映像部署的 Windows VM 上。The Azure VM Agent is installed by default on any Windows VM deployed from an Azure Marketplace image. 通过门户、PowerShell、命令行接口或 Azure 资源管理器模板部署 Azure 市场映像时,也会安装 Azure VM 代理。When you deploy an Azure Marketplace image from the portal, PowerShell, Command Line Interface, or an Azure Resource Manager template, the Azure VM Agent is also installed.

Windows 来宾代理包分为两个部分:The Windows Guest Agent Package is broken into two parts:

  • 预配代理 (PA)Provisioning Agent (PA)
  • Windows 来宾代理 (WinGA)Windows Guest Agent (WinGA)

若要启动 VM,VM 上必须已安装 PA,但无需安装 WinGA。To boot a VM you must have the PA installed on the VM, however the WinGA does not need to be installed. 部署 VM 时,可以选择不安装 WinGA。At VM deploy time, you can select not to install the WinGA. 下面的示例演示如何选择 Azure 资源管理器模板的 provisionVmAgent 选项:The following example shows how to select the provisionVmAgent option with an Azure Resource Manager template:

"resources": [{
"name": "[parameters('virtualMachineName')]",
"type": "Microsoft.Compute/virtualMachines",
"apiVersion": "2016-04-30-preview",
"location": "[parameters('location')]",
"dependsOn": ["[concat('Microsoft.Network/networkInterfaces/', parameters('networkInterfaceName'))]"],
"properties": {
    "osProfile": {
    "computerName": "[parameters('virtualMachineName')]",
    "adminUsername": "[parameters('adminUsername')]",
    "adminPassword": "[parameters('adminPassword')]",
    "windowsConfiguration": {
        "provisionVmAgent": "false"
}

如果没有安装代理,则无法使用某些 Azure 服务,例如 Azure 备份或 Azure 安全。If you do not have the Agents installed, you cannot use some Azure services, such as Azure Backup or Azure Security. 这些服务需要安装扩展。These services require an extension to be installed. 如果已在没有 WinGA VM 的情况下部署 VM,稍后可以安装最新版本的代理。If you have deployed a VM without the WinGA, you can install the latest version of the agent later.

手动安装Manual installation

可以使用 Windows 安装程序包手动安装 Windows VM 代理。The Windows VM agent can be manually installed with a Windows installer package. 创建部署到 Azure 的自定义 VM 映像时,可能需要手动安装。Manual installation may be necessary when you create a custom VM image that is deployed to Azure. 若要手动安装 Windows VM 代理,下载 VM 代理安装程序To manually install the Windows VM Agent, download the VM Agent installer. VM 代理在 Windows Server 2008 (64 bit) 和更高版本上受支持。The VM Agent is supported on Windows Server 2008 (64 bit) and later.

备注

未启用 ProvisionVMAgent 的情况下,在从映像部署的 VM 上手动安装 VMAgent 之后,请务必更新 AllowExtensionOperations 选项。It is important to update the AllowExtensionOperations option after manually installing the VMAgent on a VM that was deployed from image without ProvisionVMAgent enable.

$vm.OSProfile.AllowExtensionOperations = $true
$vm | Update-AzVM

先决条件Prerequisites

  • Windows VM 代理至少需要 Windows Server 2008(64 位)才能与 .NET Framework 4.0 一起运行。The Windows VM Agent needs at least Windows Server 2008 (64-bit) to run, with the .NET Framework 4.0. 请参阅 Azure 中的虚拟机代理的最低版本支持See Minimum version support for virtual machine agents in Azure

  • 确保 VM 可以访问 IP 地址 168.63.129.16。Ensure your VM has access to IP address 168.63.129.16. 有关详细信息,请参阅什么是 IP 地址 168.63.129.16For more information see What is IP address 168.63.129.16.

  • 确保在来宾 VM 内启用 DHCP。Ensure that DHCP is enabled inside the guest VM. 必须这样做,才能从 DHCP 获取主机或构造地址,以便 IaaS VM 代理和扩展可以正常工作。This is required to get the host or fabric address from DHCP for the IaaS VM Agent and extensions to work. 如果需要静态专用 IP,则应通过 Azure 门户或 PowerShell 进行配置,同时确保启用 VM 内的 DHCP 选项。If you need a static private IP, you should configure it through the Azure portal or PowerShell, and make sure the DHCP option inside the VM is enabled. 详细了解如何通过 PowerShell 设置静态 IP 地址。Learn more about setting up a static IP address with PowerShell.

检测 VM 代理Detect the VM Agent

PowerShellPowerShell

可以使用 Azure 资源管理器 PowerShell 模块检索有关 Azure VM 的信息。The Azure Resource Manager PowerShell module can be used to retrieve information about Azure VMs. 若要查看有关 VM 的信息,如 Azure VM 代理的预配状态,请使用 Get-AzVMTo see information about a VM, such as the provisioning state for the Azure VM Agent, use Get-AzVM:

Get-AzVM

以下浓缩版示例输出演示了嵌套在 OSProfile 中的 ProvisionVMAgent 属性。The following condensed example output shows the ProvisionVMAgent property nested inside OSProfile. 此属性可以用来确定 VM 代理是否已部署到 VM:This property can be used to determine if the VM agent has been deployed to the VM:

OSProfile                  :
  ComputerName             : myVM
  AdminUsername            : myUserName
  WindowsConfiguration     :
    ProvisionVMAgent       : True
    EnableAutomaticUpdates : True

可以使用以下脚本返回一个简明列表,其中包含 VM 名称以及 VM 代理的状态:The following script can be used to return a concise list of VM names and the state of the VM Agent:

$vms = Get-AzVM

foreach ($vm in $vms) {
    $agent = $vm | Select -ExpandProperty OSProfile | Select -ExpandProperty Windowsconfiguration | Select ProvisionVMAgent
    Write-Host $vm.Name $agent.ProvisionVMAgent
}

手动检测Manual Detection

登录到 Windows VM 后,可以使用任务管理器检查正在运行的进程。When logged in to a Windows VM, Task Manager can be used to examine running processes. 要查看 Azure VM 代理,请打开任务管理器 > 单击“详细信息”选项卡,并查找名为 WindowsAzureGuestAgent.exe 的进程。To check for the Azure VM Agent, open Task Manager, click the Details tab, and look for a process name WindowsAzureGuestAgent.exe. 存在该进程表示 VM 代理已安装。The presence of this process indicates that the VM agent is installed.

升级 VM 代理Upgrade the VM Agent

适用于 Windows 的 Azure VM 代理会在从 Azure 市场部署的映像上自动升级。The Azure VM Agent for Windows is automatically upgraded on images deployed from the Azure marketplace. 新 VM 部署到 Azure 后,会在 VM 预配时获得最新 VM 代理。As new VMs are deployed to Azure, they receive the latest VM agent at VM provision time. 如果已手动安装了代理或正在部署自定义 VM 映像,则需要在创建映像时进行手动更新以包括新的 VM 代理。If you have installed the agent manually or are deploying custom VM images you will need to manually update to include the new VM agent at image creation time.

Windows 来宾代理自动日志收集Windows Guest Agent Automatic Logs Collection

Windows 来宾代理具有自动收集一些日志的功能。Windows Guest Agent has a feature to automatically collect some logs. 此功能由 CollectGuestLogs.exe 进程控制。This feature is controller by the CollectGuestLogs.exe process. 它同时适用于 PaaS 云服务和 IaaS 虚拟机,其目标是快速自动地从 VM 收集一些诊断日志 - 以便将它们用于脱机分析。It exists for both PaaS Cloud Services and IaaS Virtual Machines and its goal is to quickly & automatically collect some diagnostics logs from a VM - so they can be used for offline analysis. 收集的日志包括事件日志、OS 日志、Azure 日志和一些注册表项。The collected logs are Event Logs, OS Logs, Azure Logs and some registry keys. 它将生成一个 ZIP 文件,该文件将传输到 VM 的主机。It produces a ZIP file that is transferred to the VM's Host. 然后,工程团队和支持专业人员可以查看此 ZIP 文件,以根据拥有 VM 的客户的请求调查问题。This ZIP file can then be looked at by Engineering Teams and Support professionals to investigate issues on request of the customer owning the VM.

后续步骤Next steps

有关 VM 扩展的详细信息,请参阅 Azure 虚拟机扩展和功能概述For more information about VM extensions, see Azure virtual machine extensions and features overview.