在脱机模式下安装 Azure 虚拟机代理Install the Azure Virtual Machine Agent in offline mode

Azure 虚拟机代理(VM 代理)可提供多种有用的功能,例如本地管理员密码重置和脚本推送。The Azure Virtual Machine Agent (VM Agent) provides useful features, such as local administrator password reset and script pushing. 本文演示如何为脱机的 Windows 虚拟机 (VM) 安装 VM 代理。This article shows you how to install the VM Agent for an offline Windows virtual machine (VM).

何时在脱机模式下使用 VM 代理When to use the VM Agent in offline mode

如有以下情况,可在脱机模式下安装 VM 代理:Install the VM Agent in offline mode in the following scenarios:

  • 已部署的 Azure VM 未安装 VM 代理,或代理不能正常工作。The deployed Azure VM doesn't have the VM Agent installed or the agent isn't working.
  • 忘记了 VM 的管理员密码,或无法访问 VM。You forgot the administrator password for the VM or you can't access the VM.

如何在脱机模式下安装 VM 代理How to install the VM Agent in offline mode

可以使用以下步骤,在脱机模式下安装 VM 代理。Use the following steps to install the VM Agent in offline mode.

步骤 1:将 VM 的 OS 磁盘作为数据磁盘附加到另一 VMStep 1: Attach the OS disk of the VM to another VM as a data disk

  1. 为受影响的 VM 的 OS 磁盘拍摄快照,从快照创建磁盘,然后将该磁盘附加到故障排除 VM。Take a snapshot for the OS disk of the affected VM, create a disk from the snapshot, and then attach the disk to a troubleshoot VM. 有关详细信息,请参阅通过使用 Azure 门户将 OS 磁盘附加到恢复 VM 来对 Windows VM 进行故障排除For more information, see Troubleshoot a Windows VM by attaching the OS disk to a recovery VM using the Azure portal. 对于经典 VM,请删除 VM 并保留 OS 磁盘,然后将 OS 磁盘附加到故障排除 VM。For the classic VM, delete the VM and keep the OS disk, and then attach the OS disk to the troubleshoot VM.

  2. 连接到故障排除 VM。Connect to the troubleshooter VM. 转到“计算机管理” > “磁盘管理”。 Open Computer management > Disk management. 确认 OS 磁盘处于联机状态,并且已将驱动器号分配到磁盘分区。Confirm that the OS disk is online and that drive letters are assigned to the disk partitions.

步骤 2:修改 OS 磁盘以安装 Azure VM 代理Step 2: Modify the OS disk to install the Azure VM Agent

  1. 远程桌面连接到故障排除 VM。Make a remote desktop connection to the troubleshooter VM.

  2. 在疑难解答 VM 中,浏览到附加的 OS 磁盘,打开 \windows\system32\config 文件夹。In the troubleshooter VM, browse to the OS disk that you attached, open the \windows\system32\config folder. 将此文件夹中的所有文件复制为备份,以备回滚之需。Copy all of the files in this folder as a backup, in case a rollback is required.

  3. 启动注册表编辑器 (regedit.exe)。Start the Registry Editor (regedit.exe).

  4. 选择“HKEY_LOCAL_MACHINE”项。Select the HKEY_LOCAL_MACHINE key. 在菜单上,选择“文件” > “加载配置单元”:On the menu, select File > Load Hive:

    加载配置单元

  5. 浏览到已附加 OS 磁盘上的 \windows\system32\config\SYSTEM 文件夹。Browse to the \windows\system32\config\SYSTEM folder on the OS disk that you attached. 输入“BROKENSYSTEM”作为配置单元名称。For the name of the hive, enter BROKENSYSTEM. 新的注册表配置单元将显示在“HKEY_LOCAL_MACHINE”项之下。The new registry hive is displayed under the HKEY_LOCAL_MACHINE key.

  6. 浏览到已附加 OS 磁盘上的 \windows\system32\config\SOFTWARE 文件夹。Browse to the \windows\system32\config\SOFTWARE folder on the OS disk that you attached. 输入“BROKENSOFTWARE”作为配置单元软件。For the name of the hive software, enter BROKENSOFTWARE.

  7. 如果附加的 OS 磁盘中已安装 VM 代理,请执行当前配置的备份。If the Attached OS disk has the VM agent installed, perform a backup of the current configuration. 如果该磁盘中未安装 VM 代理,请转到下一步骤。If it does not have VM agent installed, move to the next step.

    1. 将 \windowsazure 文件夹重命名为 \windowsazure.old。Rename the \windowsazure folder to \windowsazure.old.

    2. 导出以下注册表:Export the following registries:

      • HKEY_LOCAL_MACHINE\BROKENSYSTEM\ControlSet001\Services\WindowsAzureGuestAgentHKEY_LOCAL_MACHINE\BROKENSYSTEM\ControlSet001\Services\WindowsAzureGuestAgent
      • HKEY_LOCAL_MACHINE\BROKENSYSTEM\ControlSet001\Services\WindowsAzureTelemetryServiceHKEY_LOCAL_MACHINE\BROKENSYSTEM\ControlSet001\Services\WindowsAzureTelemetryService
      • HKEY_LOCAL_MACHINE\BROKENSYSTEM\ControlSet001\Services\RdAgentHKEY_LOCAL_MACHINE\BROKENSYSTEM\ControlSet001\Services\RdAgent
  8. 将故障排除 VM 上的现有文件用作 VM 代理安装的存储库。Use the existing files on the troubleshooter VM as a repository for the VM Agent installation. 请完成下列步骤:Complete the following steps:

    1. 从故障排除 VM 中,以注册表格式 (.reg) 导出以下子项:From the troubleshooter VM, export the following subkeys in registry format (.reg):

      • HKEY_LOCAL_MACHINE \SYSTEM\ControlSet001\Services\WindowsAzureGuestAgentHKEY_LOCAL_MACHINE \SYSTEM\ControlSet001\Services\WindowsAzureGuestAgent

      • HKEY_LOCAL_MACHINE \SYSTEM\ControlSet001\Services\WindowsAzureTelemetryServiceHKEY_LOCAL_MACHINE \SYSTEM\ControlSet001\Services\WindowsAzureTelemetryService

      • HKEY_LOCAL_MACHINE \SYSTEM\ControlSet001\Services\RdAgentHKEY_LOCAL_MACHINE \SYSTEM\ControlSet001\Services\RdAgent

        导出注册表子项

    2. 编辑注册表文件。Edit the registry files. 在每个文件中,将项值 SYSTEM改为 BROKENSYSTEM(如下图所示)并保存该文件。In each file, change the entry value SYSTEM to BROKENSYSTEM (as shown in the following images) and save the file. 请记住当前 VM 代理的 ImagePathRemember the ImagePath of the current VM agent. 需将相应的文件夹复制到附加的 OS 磁盘。We will need to copy the corresponding folder to the attached OS disk.

      更改注册表子项值

    3. 双击每个注册表文件,将注册表文件导入存储库。Import the registry files into the repository by double-clicking each registry file.

    4. 确认将以下三个子项成功导入 BROKENSYSTEM 配置单元:Confirm that the following three subkeys are successfully imported into the BROKENSYSTEM hive:

      • WindowsAzureGuestAgentWindowsAzureGuestAgent
      • WindowsAzureTelemetryServiceWindowsAzureTelemetryService
      • RdAgentRdAgent
    5. 将当前 VM 代理的安装文件夹复制到附加的 OS 磁盘:Copy the installation folder of the current VM Agent to the attached OS disk:

      1. 在附加的 OS 磁盘上的根路径中创建名为 WindowsAzure 的文件夹。On the OS disk that you attached, create a folder named WindowsAzure in the root path.

      2. 转到故障排除 VM 上的 C:\WindowsAzure,找到名为 C:\WindowsAzure\GuestAgent_X.X.XXXX.XXX 的任何文件夹。Go to C:\WindowsAzure on the troubleshooter VM, look for any folder with the name C:\WindowsAzure\GuestAgent_X.X.XXXX.XXX. 将 C:\WindowsAzure 中包含最新版本号的 GuestAgent 文件夹,复制到附加的 OS 磁盘中的 WindowsAzure 文件夹。Copy the GuestAgent folder that has latest version number from C:\WindowsAzure to the WindowsAzure folder in the attached OS disk. 如果不确定要复制哪个文件夹,请复制所有 GuestAgent 文件夹。If you are not sure which folder should be copied, copy all GuestAgent folders. 下图显示了已复制到附加的 OS 磁盘的 GuestAgent 文件夹示例。The following image shows an example of the GuestAgent folder that is copied to the attached OS disk.

        复制 GuestAgent 文件夹

  9. 选择“BROKENSYSTEM”。Select BROKENSYSTEM. 在菜单上,选择“文件” > “卸载配置单元”From the menu, select File > Unload Hive.

  10. 选择“BROKENSOFTWARE”。Select BROKENSOFTWARE. 在菜单上,选择“文件” > “卸载配置单元”From the menu, select File > Unload Hive.

  11. 分离 OS 磁盘,然后更改受影响 VM 的 OS 磁盘Detach the OS disk, and then change the OS disk for the affected VM. 对于经典 VM,请使用修复的 OS 磁盘创建新的 VM。For the classic VM, create a new VM by using the repaired OS disk.

  12. 访问 VM。Access the VM. 请注意,RdAgent 正在运行,并且正在生成日志。Notice that the RdAgent is running and the logs are being generated.

如果使用资源管理器部署模型创建了 VM,则操作现已完成。If you created the VM by using the Resource Manager deployment model, you're done.

对于经典 VM,使用 ProvisionGuestAgent 属性Use the ProvisionGuestAgent property for classic VMs

重要

经典 VM 将于 2023 年 3 月 1 日停用。Classic VMs will be retired on March 1, 2023.

如果从 ASM 使用 IaaS 资源,请在 2023 年 3 月 1 日之前完成迁移。If you use IaaS resources from ASM, please complete your migration by March 1, 2023. 我们建议你尽快进行切换,以利用 Azure 资源管理器中的许多增强功能。We encourage you to make the switch sooner to take advantage of the many feature enhancements in Azure Resource Manager.

有关详细信息,请参阅在 2023 年 3 月 1 日之前将 IaaS 资源迁移到 Azure 资源管理器For more information, see Migrate your IaaS resources to Azure Resource Manager by March 1, 2023.

如果使用经典模型创建了 VM,请使用 Azure PowerShell 模块更新 ProvisionGuestAgent 属性。If you created the VM by using the classic model, use the Azure PowerShell module to update the ProvisionGuestAgent property. 该属性会通知 Azure 该 VM 已安装 VM 代理。The property informs Azure that the VM has the VM Agent installed.

若要设置 ProvisionGuestAgent 属性,请在 Azure PowerShell 中运行以下命令:To set the ProvisionGuestAgent property, run the following commands in Azure PowerShell:

$vm = Get-AzureVM -ServiceName <cloud service name> -Name <VM name>
$vm.VM.ProvisionGuestAgent = $true
Update-AzureVM -Name <VM name> -VM $vm.VM -ServiceName <cloud service name>

然后运行 Get-AzureVM 命令。Then run the Get-AzureVM command. 请注意,GuestAgentStatus 属性现已得到数据填充:Notice that the GuestAgentStatus property is now populated with data:

Get-AzureVM -ServiceName <cloud service name> -Name <VM name>
GuestAgentStatus:Microsoft.WindowsAzure.Commands.ServiceManagement.Model.PersistentVMModel.GuestAgentStatus

后续步骤Next steps