

• AWS Systems Manager CloudWatch 控制面板在 2026 年 4 月 30 日之后将不再可用。客户可以像现在一样继续使用 Amazon CloudWatch 控制台来查看、创建和管理其 Amazon CloudWatch 控制面板。有关更多信息，请参阅 [Amazon CloudWatch 控制面板文档](https://docs.aws.amazon.com/AmazonCloudWatch/latest/monitoring/CloudWatch_Dashboards.html)。

# 在混合 Windows Server 节点上安装 SSM Agent
<a name="hybrid-multicloud-ssm-agent-install-windows"></a>

本主题介绍如何在[混合和多云](operating-systems-and-machine-types.md#supported-machine-types)环境中的 Windows Server 计算机上安装 AWS Systems Manager SSM Agent。有关在适用于 Windows Server 的 EC2 实例上安装 SSM Agent 的信息，请参阅[在适用于 Windows Server 的 EC2 实例上手动安装和卸载 SSM Agent](manually-install-ssm-agent-windows.md)。

开始之前，请找到在混合激活过程中生成的激活码和激活 ID，如 [创建混合激活以将节点注册到 Systems Manager](hybrid-activation-managed-nodes.md) 中所述。按照以下流程指定激活代码和 ID。

**在混合和多云环境中的非 EC2 Windows Server 计算机上安装 SSM Agent**

1. 登录混合和多云环境中的服务器或虚拟机。

1. 如果使用 HTTP 或 HTTPS 代理，则必须在当前 Shell 会话中设置 `http_proxy` 或 `https_proxy` 环境变量。如果您不使用代理，则可跳过此步骤。

   对于 HTTP 代理服务器，请设置以下变量：

   ```
   http_proxy=http://hostname:port
   https_proxy=http://hostname:port
   ```

   对于 HTTPS 代理服务器，请设置以下变量：

   ```
   http_proxy=http://hostname:port
   https_proxy=https://hostname:port
   ```

   对于 PowerShell，请配置 WinINet 代理设置：

   ```
   [System.Net.WebRequest]::DefaultWebProxy
   
   $proxyServer = "http://hostname:port"
   $proxyBypass = "169.254.169.254"
   $WebProxy = New-Object System.Net.WebProxy($proxyServer,$true,$proxyBypass)
   
   [System.Net.WebRequest]::DefaultWebProxy = $WebProxy
   ```
**注意**  
PowerShell 操作需要 WiniNet 代理配置。有关更多信息，请参阅 [SSM Agent 代理设置和 Systems Manager 服务](configure-proxy-ssm-agent-windows.md#ssm-agent-proxy-services)。

1. 在提升（管理）模式下打开 Windows PowerShell。

1. 将以下命令块复制并粘贴到 Windows PowerShell 中。将每个*示例资源占位符*替换为您自己的信息。例如，在创建混合激活时生成的激活代码和激活 ID，以及带有您要从中下载 SSM Agent 的 AWS 区域 标识符的激活代码和激活 ID。
**重要**  
请注意以下重要详细信息：  
`ssm-setup-cli` 用于非 EC2 安装可最大程度提高 Systems Manager 安装和配置的安全性。
`ssm-setup-cli` 支持 `manifest-url` 选项，该选项可用来确定代理的下载来源。除非您的组织要求，否则请勿为此选项指定任何值。
您可以使用[此处](https://github.com/aws/amazon-ssm-agent/blob/mainline/Tools/src/setupcli_data_integrity_windows.ps1)提供的脚本来验证 `ssm-setup-cli` 的签名。
注册实例时，请仅使用为 `ssm-setup-cli` 提供的下载链接。`ssm-setup-cli` 不应另行存放以供将来使用。

   *region* 表示 AWS Systems Manager 支持的 AWS 区域 的标识符，例如 `us-east-2` 对应美国东部（俄亥俄州）区域。有关支持的 *region* 值的列表，请参阅*《Amazon Web Services 一般参考》*中的 [Systems Manager service endpoints](https://docs.aws.amazon.com/general/latest/gr/ssm.html#ssm_region) 的 **Region** 列。

   此外，`ssm-setup-cli` 包括以下选项：
   + `version` –有效值为 `latest` 和 `stable`。
   + `downgrade` – 将代理恢复到早期版本。
   + `skip-signature-validation` – 在下载和安装代理期间跳过签名验证。

------
#### [ 64-bit ]

   ```
   [System.Net.ServicePointManager]::SecurityProtocol = 'TLS12'
   $code = "activation-code"
   $id = "activation-id"
   $region = "us-east-1"
   $dir = $env:TEMP + "\ssm"
   New-Item -ItemType directory -Path $dir -Force
   cd $dir
   (New-Object System.Net.WebClient).DownloadFile("https://amazon-ssm-$region.s3.$region.amazonaws.com/latest/windows_amd64/ssm-setup-cli.exe", $dir + "\ssm-setup-cli.exe")
   ./ssm-setup-cli.exe -register -activation-code="$code" -activation-id="$id" -region="$region"
   Get-Content ($env:ProgramData + "\Amazon\SSM\InstanceData\registration")
   Get-Service -Name "AmazonSSMAgent"
   ```

------

1. 按 `Enter`。

**注意**  
如果命令失败，确认运行的是否是最新版本的 AWS Tools for PowerShell。

此命令执行以下操作：
+ 下载并在计算机上安装 SSM Agent。
+ 向 Systems Manager 服务注册计算机。
+ 返回类似以下内容的请求响应：

  ```
      Directory: C:\Users\ADMINI~1\AppData\Local\Temp\2
  
  
  Mode                LastWriteTime         Length Name
  ----                -------------         ------ ----
  d-----       07/07/2018   8:07 PM                ssm
  {"ManagedInstanceID":"mi-008d36be46EXAMPLE","Region":"us-east-2"}
  
  Status      : Running
  Name        : AmazonSSMAgent
  DisplayName : Amazon SSM Agent
  ```

该计算机现在已是*托管节点*。现在，这些托管式节点带有前缀“mi-”作为标识。您可以使用 AWS CLI 命令 [https://docs.aws.amazon.com/cli/latest/reference/ssm/describe-instance-information.html](https://docs.aws.amazon.com/cli/latest/reference/ssm/describe-instance-information.html) 或使用 API 命令 [https://docs.aws.amazon.com/systems-manager/latest/APIReference/API_DescribeInstanceInformation.html](https://docs.aws.amazon.com/systems-manager/latest/APIReference/API_DescribeInstanceInformation.html)，在 Fleet Manager 中的**托管式节点**页面上查看托管式节点。

## 设置私有密钥自动轮换
<a name="ssm-agent-hybrid-private-key-rotation-windows"></a>

为了加强安全状况，您可以将 AWS Systems Manager 代理（SSM Agent）配置为自动轮换混合和多云环境私有密钥。您可以使用 SSM Agent 版本 3.0.1031.0 或更高版本来访问此功能。使用以下过程开启此功能。

**将 SSM Agent 配置为轮换混合和多云环境私有密钥**

1. 在 Linux 计算机上导航到 `/etc/amazon/ssm/`，或者在 Windows Server 计算机上导航到 `C:\Program Files\Amazon\SSM`。

1. 将 `amazon-ssm-agent.json.template` 的内容复制到名为 `amazon-ssm-agent.json` 的新文件中。Save`amazon-ssm-agent.json`在同一目录中，其中`amazon-ssm-agent.json.template`位于中。

1. 找到 `Profile`、`KeyAutoRotateDays`。输入您希望自动轮换私有密钥的间隔天数。

1. 重新启动 SSM Agent。

每次更改配置时，请重新启动 SSM Agent。

您可以按照相同的过程自定义 SSM Agent 的其他功能。有关可用配置属性及其默认值的最新列表，请参阅[配置属性定义](https://github.com/aws/amazon-ssm-agent#config-property-definitions)。

## 取消注册及重新注册托管式节点（Windows Server）
<a name="systems-manager-install-managed-win-deregister-reregister"></a>

您可以从 AWS CLI 或借助适用于 Windows PowerShell 的工具来调用 [DeregisterManagedInstance](https://docs.aws.amazon.com/systems-manager/latest/APIReference/API_DeregisterManagedInstance.html) API 操作，以取消注册托管节点。以下是一个示例 CLI 命令：

`aws ssm deregister-managed-instance --instance-id "mi-1234567890"`

要移除代理的其余注册信息，请移除 `amazon-ssm-agent.json` 文件中的 `IdentityConsumptionOrder` 键。然后运行以下命令：

`amazon-ssm-agent -register -clear`

**注意**  
只要未达到指定激活码和 ID 的实例限制，就可以使用相同的激活码和 ID 重新注册本地服务器、边缘设备或虚拟机。您可以使用 AWS CLI 调用 [describe-activations](https://docs.aws.amazon.com/cli/latest/reference/ssm/describe-activations.html) API 来验证激活码和 ID 的实例限制。运行命令后，请验证 `RegistrationCount` 的值是否未超过 `RegistrationLimit`。如果超过，则必须使用不同的激活码和 ID。

**在 Windows Server 混合计算机上重新注册托管节点**

1. 连接到您的计算机。

1. 运行如下命令。请务必将占位符的值替换为在创建混合激活时生成的激活码和激活 ID，以及要从中下载 SSM Agent 的区域标识符。

   ```
   $dir = $env:TEMP + "\ssm"
   cd $dir
   Start-Process ./ssm-setup-cli.exe -ArgumentList @(
       "-register",
       "-activation-code=$code",
       "-activation-id=$id",
       "-region=$region"
   ) -Wait -NoNewWindow
   ```