步驟 4:在混合多雲端環境 (Windows) 中安裝 SSM Agent - AWS Systems Manager

本文為英文版的機器翻譯版本,如內容有任何歧義或不一致之處,概以英文版為準。

步驟 4:在混合多雲端環境 (Windows) 中安裝 SSM Agent

本主題說明如何在混合多雲端環境中的 Windows Server 機器上安裝 SSM Agent。如果您計劃在混合多雲端環境中使用非 EC2 Linux 機器,請參閱上一個步驟:步驟 3:在混合多雲端環境 (Linux) 中安裝 SSM Agent

重要

此程序適用於在混合多雲端環境中的非 EC2 (Amazon Elastic Compute Cloud) 機器。若要在 Windows Server 的 EC2 執行個體上下載並安裝 SSM Agent,請參閱在 Windows Server 專用 EC2 執行個體使用 SSM Agent

開始之前,請找出您稍早在 步驟 2:為混合多雲環境建立混合啟用 中完成混合啟用後傳送給您的啟用代碼和啟用 ID。您會在以下程序中指定代碼和 ID。

在混合多雲端環境中的非 EC2 Windows Server 機器上安裝 SSM Agent
  1. 登入混合多雲端環境中的伺服器或虛擬機器。

  2. 如果您使用 HTTP 或 HTTPS 代理伺服器,則必須在目前的 Shell 工作階段中設定 http_proxyhttps_proxy 環境變數。如果您不使用代理伺服器,則可以略過此步驟。

    對於 HTTP 代理伺服器,請設定此變數:

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

    對於 HTTPS 代理伺服器,請設定此變數:

    http_proxy=http://hostname:port https_proxy=https://hostname:port
  3. 以高階 (管理) 模式開啟 Windows PowerShell。

  4. 複製以下命令區塊並貼到 Windows PowerShell。將每個範例資源預留位置取代為您自己的資訊。例如,當您建立混合式啟動時產生的「啟動碼」和「啟動 ID」,以及 AWS 區域 您要SSM Agent從中下載的識別碼。

    注意

    請注意以下重要詳細資訊:

    • ssm-setup-cli 支援用於確定代理程式下載來源的 manifest-url 選項。除非您的組織需要,否則請勿為此選項指定值。

    • 您可以使用此處提供的指令碼來驗證的簽章ssm-setup-cli

    • 註冊執行個體時,請僅使用為 ssm-setup-cli 提供的下載連結。ssm-setup-cli 不應單獨存放以供日後使用。

    地區代表 AWS 區域 支援的識別碼 AWS Systems Manager,us-east-2例如美國東部 (俄亥俄) 區域。如需支援的 region 值的清單,請參閱《Amazon Web Services 一般參考》Systems Manager 服務端點一節的區域資料欄。

    此外,ssm-setup-cli 還包括下列選項:

    • version:有效值為 lateststable

    • 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"
    32-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_386/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"
  5. Enter 鍵。

命令會執行下列動作:

  • 將 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-" 進行標識。您可以使用指令或使用 API AWS CLI 命令 Fleet Manager describe-instance-information,在中的 [受管節點] 頁面上檢視受管節點DescribeInstanceInformation

設定私有金鑰自動輪換

若要強化您的安全狀態,您可以將 AWS Systems Manager Agent (SSM Agent) 設定為自動輪替混合式和多雲端環境的私密金鑰。您可以使用 SSM Agent 3.0.1031.0 版或更新版本來存取此功能。使用下列程序開啟此功能。

設定 SSM Agent 以輪換混合多雲端環境的私有金鑰
  1. 在 Linux 機器中導覽至 /etc/amazon/ssm/,或在 Windows Server 機器中導覽至 C:\Program Files\Amazon\SSM

  2. amazon-ssm-agent.json.template 的內容複製到名為 amazon-ssm-agent.json 的新檔案。將 amazon-ssm-agent.json 儲存在 amazon-ssm-agent.json.template 所在的相同目錄中。

  3. 查找 ProfileKeyAutoRotateDays。輸入您想要的自動私有金鑰輪換之間的天數。

  4. 重新啟動 SSM Agent。

每次變更組態時,請重新啟動 SSM Agent。

您可以使用相同的程序來自訂 SSM Agent 的其他功能。如需可用組態屬性及其預設值的 up-to-date 清單,請參閱組 Config 屬性定義

取消註冊並重新註冊受管節點

您可以從 AWS CLI 或 Windows PowerShell 工具呼叫 DeregisterManagedInstanceAPI 作業,以取消註冊受管理節點。以下是範例 CLI 命令:

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

若要移除代理程式的剩餘註冊資訊,請移除 amazon-ssm-agent.json 檔案中的 IdentityConsumptionOrder 索引鍵。然後執行以下命令:

amazon-ssm-agent -register -clear

您可以在取消註冊機器之後重新註冊它。使用以下程序來將機器重新註冊為受管節點。完成程序後,您的受管節點會再次顯示在受管節點清單中。

若要在 Windows 混合機器中重新註冊受管節點
  1. 連線至您的機器。

  2. 執行下列命令。確保將預留位置值替換為您在建立混合啟用時產生的啟用碼和啟用 ID,以及替換為您想要從中下載 SSM Agent 的區域識別符。

    'yes' | & Start-Process ./ssm-setup-cli.exe -ArgumentList @("-register", "-activation-code=$code", "-activation-id=$id", "-region=$region") -Wait Get-Content ($env:ProgramData + "\Amazon\SSM\InstanceData\registration") Get-Service -Name "AmazonSSMAgent"