使用 SAC 连接到 Windows 虚拟机


本文档介绍如何连接到 Windows Special Administrative Console (SAC)。SAC 使用到 Windows 虚拟机实例的串行端口连接,并且不依赖于网络连接,这有助于对 Windows 虚拟机实例进行问题排查或恢复。通过连接到虚拟机的串行控制台并使用 SAC,您可以中断虚拟机的启动过程,或者访问 CMD 或 PowerShell 终端以执行问题排查。如需获得除问题排查之外的通用远程桌面体验,请使用 RDP 连接到 Windows 虚拟机

准备工作

  • 您必须先为虚拟机启用交互式访问权限,然后才能使用交互式串行控制台连接到虚拟机。如需了解详情,请参阅启用对串行控制台的交互式访问
  • 设置身份验证(如果尚未设置)。身份验证是通过其进行身份验证以访问 Google Cloud 服务和 API 的过程。如需从本地开发环境运行代码或示例,您可以按如下方式向 Compute Engine 进行身份验证。

    选择标签页以了解您打算如何使用本页面上的示例:

    控制台

    当您使用 Google Cloud 控制台访问 Google Cloud 服务和 API 时,无需设置身份验证。

    gcloud

    1. 安装 Google Cloud CLI,然后通过运行以下命令初始化 Google Cloud CLI:

      gcloud init
    2. 设置默认区域和可用区

连接到串行控制台

如需使用交互式串行控制台连接到 Windows 实例,请完成以下任一标签页中的步骤:

控制台

  1. 在 Google Cloud 控制台中,转到虚拟机实例页面。

    转到虚拟机实例

  2. 点击要连接到的虚拟机的名称。

  3. 点击连接到串行控制台以打开交互式控制台。

系统会打开交互式串行控制台。当您看到以下输出时,则表明可以开始使用:

Computer is booting, SAC started and initialized.

Use the "ch -?" command for information about using channels.
Use the "?" command for general help.

SAC>

如果交互式串行控制台是带有闪烁光标的空白屏幕,则可能是因为紧急管理服务已关闭。请参阅排查交互式串行控制台问题,了解如何解决此问题。

gcloud

使用 gcloud compute connect-to-serial-port 命令连接到启用串行端口访问权限的虚拟机实例:

gcloud compute connect-to-serial-port VM_NAME \
    --port=2 \
    --zone=ZONE \
    --project=PROJECT_ID

替换以下内容:

  • PROJECT_ID:包含虚拟机的项目 ID。
  • ZONE:虚拟机所在区域的名称
  • VM_NAME:虚拟机的名称

系统会打开交互式串行控制台。当您看到以下输出时,即可使用:

Computer is booting, SAC started and initialized.

Use the "ch -?" command for information about using channels.
Use the "?" command for general help.

SAC>

如果交互式串行控制台是带有闪烁光标的空白屏幕,则可能是因为紧急管理服务已关闭。请参阅排查交互式串行控制台问题,了解如何解决此问题。

如需了解如何使用交互式串行控制台,请参阅 Microsoft SAC 命令文档

在 Windows SAC 中打开命令提示符

如需在 SAC 中打开命令提示符,请执行以下操作:

  1. 输入 cmd,然后按 Enter 键。您将看到以下输出内容:

    SAC>cmd
    The Command Prompt session was successfully launched.
    SAC>
    EVENT:   A new channel has been created.  Use "ch -?" for channel help.
    Channel: Cmd0001
    SAC>
    
  2. 使用 ch -sn CHANNEL_NAME 命令,然后按 Enter 键。

    ch -sn CHANNEL_NAME
    

    CHANNEL_NAME 替换为您在上一步中创建的渠道的名称。

    输出类似于以下内容:

    Name:                  Cmd0001
    Description:           Command
    Type:                  VT-UTF8
    Channel GUID:          28de7392-5413-11ea-bb03-c9656a2ed613
    Application Type GUID: 63d02271-8aa4-11d5-bccf-00b0d014a2d0
    
    Press <esc><tab> for next channel.
    Press <esc><tab>0 to return to the SAC channel.
    Use any other key to view this channel.
    
  3. 空格键,然后使用系统中注册的本地凭据登录。

    Please enter login credentials.
    Username: USERNAME
    Domain: DOMAIN (leave blank if no domain)
    Password: PASSWORD
    

    连接后,即可使用命令提示符 shell。

    Microsoft Windows [Version 10.0.14393]
    (c) 2016 Microsoft Corporation. All rights reserved.
    
    C:\Windows\system32>
    
  4. 可选:如需进入 Powershell 提示符,请输入 powershell.exe,然后按 Enter 键。

后续步骤