

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

# 啟動 CloudWatch 代理程式
<a name="start-CloudWatch-Agent-on-premise-SSM-onprem"></a>

您可以使用 Systems Manager 執行命令或命令列啟動 CloudWatch 代理程式。

如需在已啟用安全增強型 Linux (SELinux) 的系統上設定代理程式的資訊，請參閱 [使用安全增強型 Linux (SELinux) 設定 CloudWatch 代理程式](CloudWatch-Agent-SELinux.md)。

## 在 Amazon EC2 上使用命令列啟動 CloudWatch 代理程式
<a name="start-CloudWatch-Agent-EC2-commands-fleet"></a>

遵循下列步驟，使用命令列在 Amazon EC2 上啟動 CloudWatch 代理程式。

如需在已啟用安全增強型 Linux (SELinux) 的系統上設定代理程式的資訊，請參閱 [使用安全增強型 Linux (SELinux) 設定 CloudWatch 代理程式](CloudWatch-Agent-SELinux.md)。

**使用命令列在 Amazon EC2 上啟動 CloudWatch 代理程式**

1. 將您希望使用的代理程式組態檔案複製到您要執行代理程式的伺服器。請注意您複製的目標路徑名稱。

1. 在此命令中，`-a fetch-config` 會使代理程式載入最新版的 CloudWatch 代理程式組態檔案，而 `-s` 會啟動代理程式。

   輸入以下其中一個命令。將 *configuration-file-path* 取代為代理程式組態檔案的路徑。如果您使用精靈建立，則這個檔案稱為 `config.json`；如果您以手動方式建立，則可能稱為 `amazon-cloudwatch-agent.json`。

   在執行 Linux 的 EC2 執行個體上，輸入以下命令：

   ```
   sudo /opt/aws/amazon-cloudwatch-agent/bin/amazon-cloudwatch-agent-ctl -a fetch-config -m ec2 -s -c file:configuration-file-path
   ```

   在執行 Linux 的現場部署伺服器上，輸入以下內容：

   ```
   sudo /opt/aws/amazon-cloudwatch-agent/bin/amazon-cloudwatch-agent-ctl -a fetch-config -m onPremise -s -c file:configuration-file-path
   ```

   在執行 Windows Server 的 EC2 執行個體上，從 PowerShell 主控台輸入以下內容：

   ```
   & "C:\Program Files\Amazon\AmazonCloudWatchAgent\amazon-cloudwatch-agent-ctl.ps1" -a fetch-config -m ec2 -s -c file:configuration-file-path
   ```

   在執行 Windows Server 的現場部署伺服器上，從 PowerShell 主控台輸入以下內容：

   ```
   & "C:\Program Files\Amazon\AmazonCloudWatchAgent\amazon-cloudwatch-agent-ctl.ps1" -a fetch-config -m onPremise -s -c file:configuration-file-path
   ```

## 在內部部署伺服器上啟動 CloudWatch 代理程式
<a name="start-CloudWatch-Agent-on-premises"></a>

請依循下列步驟，使用命令列在內部部署伺服器上啟動 CloudWatch 代理程式。

**若要在內部部署伺服器上使用 SSM Agent 啟動 CloudWatch 代理程式**

1. 在 https：//[https://console.aws.amazon.com/systems-manager/](https://console.aws.amazon.com/systems-manager/) 開啟 Systems Manager 主控台。

1. 在導覽窗格中，選擇 **執行命令**。

   -或-

   如果 AWS Systems Manager 首頁開啟，請向下捲動並選擇**探索執行命令**。

1. 選擇**執行命令**。

1. 在 **Command document (命令文件)** 清單中，選取 **AmazonCloudWatch-ManageAgent** 旁的按鈕。

1. 在 **Targets (目標)** 區域中，選取您安裝代理程式的執行個體。

1. 在 **Action (動作)** 清單中，選擇 **configure (設定)**。

1. 在 **Mode (模式)** 清單中，選擇 **onPremise (現場部署)**。

1. 在 **Optional Configuration Location** (選用組態位置) 方塊中，輸入您使用精靈建立並存放於參數存放區的代理程式組態檔案名稱。

1. 選擇**執行**。

   代理程式以您在組態檔案中指定的組態進行啟動。

**若要在內部部署伺服器上使用命令列啟動 CloudWatch 代理程式**
+ 在此命令中，`-a fetch-config` 會使代理程式載入最新版的 CloudWatch 代理程式組態檔案，而 `-s` 會啟動代理程式。

  Linux：如果您已將組態檔案儲存於 Systems Manager 參數存放區，請輸入以下內容：

  ```
  sudo /opt/aws/amazon-cloudwatch-agent/bin/amazon-cloudwatch-agent-ctl -a fetch-config -m onPremise -s -c ssm:configuration-parameter-store-name
  ```

  Linux：如果您已將組態檔案儲存於本機電腦，請輸入以下命令：將 *configuration-file-path* 取代為代理程式組態檔案的路徑。如果您使用精靈建立，則這個檔案稱為 `config.json`；如果您以手動方式建立，則可能稱為 `amazon-cloudwatch-agent.json`。

  ```
  sudo /opt/aws/amazon-cloudwatch-agent/bin/amazon-cloudwatch-agent-ctl -a fetch-config -m onPremise -s -c file:configuration-file-path
  ```

  Windows Server：如果您已將代理程式組態檔案儲存於 Systems Manager 參數存放區，請從 PowerShell 主控台輸入以下內容：

  ```
  & "C:\Program Files\Amazon\AmazonCloudWatchAgent\amazon-cloudwatch-agent-ctl.ps1" -a fetch-config -m onPremise -s -c ssm:configuration-parameter-store-name
  ```

  Windows Server：如果您已將代理程式組態檔案儲存於本機電腦，請從 PowerShell 主控台輸入以下內容：將 *configuration-file-path* 取代為代理程式組態檔案的路徑。如果您使用精靈建立，則這個檔案稱為 `config.json`；如果您以手動方式建立，則可能稱為 `amazon-cloudwatch-agent.json`。

  ```
  & "C:\Program Files\Amazon\AmazonCloudWatchAgent\amazon-cloudwatch-agent-ctl.ps1" -a fetch-config -m onPremise -s -c file:configuration-file-path
  ```