配置 SSM Agent以使用 Windows Server 实例的代理 - Amazon Systems Manager
Amazon Web Services 文档中描述的 Amazon Web Services 服务或功能可能因区域而异。要查看适用于中国区域的差异,请参阅 中国的 Amazon Web Services 服务入门 (PDF)

配置 SSM Agent以使用 Windows Server 实例的代理

本主题中的信息适用于在 2016 年 11 月或之后创建但使用 Nano 安装选项的 Windows Server 实例。请注意,如果打算使用 Session Manager,HTTPS 代理服务器不受支持。

如果您实例是在 2016 年 11 月之前创建的 Windows Server 2008-2012 R2 实例,则 EC2Config 将在实例上处理 Amazon Systems Manager 请求。我们建议您升级现有实例以使用最新版本的 EC2Config。可以使用最新的 EC2Config 安装程序并行安装 Amazon Systems Manager Agent (SSM Agent) 与 EC2Config。此并行版本的 SSM Agent 与通过较早的 Windows Amazon Machine Images (AMIs) 创建的实例兼容,允许使用 2016 年 11 月之后发布的 Systems Manager 功能。有关如何安装最新版本的 EC2Config 服务的信息,请参阅适用于 Windows 实例的 Amazon EC2 用户指南中的安装最新版本的 EC2Config。如果不升级到最新版本的 EC2Config 并使用 EC2Config 处理 Systems Manager 请求,则必须为 EC2Config 配置代理设置。有关配置 EC2Config 以使用代理的信息,请参阅适用于 Windows 实例的 Amazon EC2 用户指南中的配置 EC2Config 服务的代理设置

注意

从 2020 年 1 月 14 日开始,Microsoft 不再为 Windows Server 2008 的功能或安全性更新提供支持。原有 Amazon Machine Images (AMIs) for Windows Server 2008 和 2008 R2 仍包含预安装的 SSM Agent 2 版,但 Systems Manager 不再正式支持 2008 版,并且不再针对更新这些 Windows Server 版本更新代理。此外,SSM Agent 版本 3 可能不兼容 Windows Server 2008 和 2008 R2 上的所有操作。适用于 Windows Server 2008 版的最后正式支持的 SSM Agent 版本为 2.3.1644.0。

配置 SSM Agent以使用代理
  1. 使用远程桌面或 Windows PowerShell,连接到您希望配置的实例,以使用代理。

  2. 在 PowerShell 中运行以下命令块。将 hostnameport 替换为有关代理的信息。

    $serviceKey = "HKLM:\SYSTEM\CurrentControlSet\Services\AmazonSSMAgent" $keyInfo = (Get-Item -Path $serviceKey).GetValue("Environment") $proxyVariables = @("http_proxy=hostname:port", "https_proxy=hostname:port", "no_proxy=169.254.169.254") if ($keyInfo -eq $null) { New-ItemProperty -Path $serviceKey -Name Environment -Value $proxyVariables -PropertyType MultiString -Force } else { Set-ItemProperty -Path $serviceKey -Name Environment -Value $proxyVariables } Restart-Service AmazonSSMAgent

运行上述命令后,您可以查看 SSM Agent 日志以确认已应用代理设置。日志中的条目类似于以下内容。有关 SSM Agent 日志的更多信息,请参阅 查看 SSM Agent 日志

2020-02-24 15:31:54 INFO Getting IE proxy configuration for current user: The operation completed successfully.
2020-02-24 15:31:54 INFO Getting WinHTTP proxy default configuration: The operation completed successfully.
2020-02-24 15:31:54 INFO Proxy environment variables:
2020-02-24 15:31:54 INFO http_proxy: hostname:port
2020-02-24 15:31:54 INFO https_proxy: hostname:port
2020-02-24 15:31:54 INFO no_proxy: 169.254.169.254
2020-02-24 15:31:54 INFO Starting Agent: amazon-ssm-agent - v2.3.871.0
2020-02-24 15:31:54 INFO OS: windows, Arch: amd64
重置 SSM Agent的代理配置
  1. 使用远程桌面或 Windows PowerShell,连接到要配置的实例。

  2. 如果使用远程桌面连接,则以管理员的身份启动 PowerShell。

  3. 在 PowerShell 中运行以下命令块。

    Remove-ItemProperty -Path HKLM:\SYSTEM\CurrentControlSet\Services\AmazonSSMAgent -Name Environment Restart-Service AmazonSSMAgent

SSM Agent代理设置优先级

在 Windows Server 实例上为 SSM Agent配置代理设置时,务必了解在启动 SSM Agent 时会评估这些设置并将它们应用于代理配置。您为 Windows Server 实例配置代理设置的方式可以确定其他设置是否可以取代您的预期设置。

重要

SSM Agent 使用 HTTPS 协议进行通信。因此,您必须使用下面的一个设置选项来配置 HTTPS proxy 参数。

SSM Agent 代理设置的评估顺序如下。

  1. AmazonSSMAgent 注册表设置 (HKLM:\SYSTEM\CurrentControlSet\Services\AmazonSSMAgent)

  2. 系统环境变量(http_proxyhttps_proxyno_proxy

  3. LocalSystem 用户帐户环境变量(http_proxyhttps_proxyno_proxy

  4. Internet Explorer 设置(HTTPsecureexceptions

  5. WinHTTP 代理设置(http=https=bypass-list=

SSM Agent 代理设置和 Systems Manager 服务

如果您将 SSM Agent 配置为使用代理,并且正在使用 Amazon Systems Manager 功能(例如,Run Command 和 Patch Manager),而这些功能在 Windows Server 实例上执行期间将使用 PowerShell 或 Windows Update 客户端,则则配置其他代理设置。否则,操作可能会失败,因为 PowerShell 和 Windows Update 客户端使用的代理设置不是从 SSM Agent 代理配置继承的。

对于 Run Command,在 Windows Server 实例上配置 WinINet 代理设置。将按会话提供 [System.Net.WebRequest] 命令。要将这些配置应用于在 Run Command 中运行的后续网络命令,这些命令必须位于同一 aws:runPowershellScript 插件输入中其他 Powershell 命令之前。

以下 PowerShell 命令返回当前 WinINet 代理设置并将您的代理设置应用于 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

对于 Patch Manager,配置系统范围的代理设置,以便 Windows Update 客户端能够扫描和下载更新。建议您使用 Run Command 运行以下命令,因为这些命令会在系统账户上运行,并且这些设置会应用于整个系统范围。以下 netsh 命令返回当前代理设置,并将您的代理设置应用于本地系统。

netsh winhttp show proxy netsh winhttp set proxy proxy-server="hostname:port" bypass-list="169.254.169.254"

有关使用 Run Command 的更多信息,请参阅Amazon Systems Manager Run Command