

本文属于机器翻译版本。若本译文内容与英语原文存在差异，则一律以英文原文为准。

# 手动安装安全代理
<a name="installing-gdu-security-agent-ec2-manually"></a>

GuardDuty 提供了以下两种在您的 Amazon EC2 实例上安装 GuardDuty 安全代理的方法。在继续操作之前，请务必完成[先决条件 – 手动创建 Amazon VPC 端点](creating-vpc-endpoint-ec2-agent-manually.md)下的步骤。

选择一种您偏好的访问方法，在您的 Amazon EC2 资源中安装安全代理。
+ [方法 1-使用 Amazon Systems Manager](#install-gdu-by-using-sys-runtime-monitoring)— 此方法需要 Amazon Systems Manager 管理您的 Amazon EC2 实例。
+ [方法 2 – 使用 Linux 软件包管理器](#install-gdu-by-rpm-scripts-runtime-monitoring)— 无论您的 Amazon EC2 实例是否处于 Amazon Systems Manager 托管状态，您都可以使用此方法。根据您的[操作系统发行版](https://docs.amazonaws.cn/guardduty/latest/ug/prereq-runtime-monitoring-ec2-support.html#validating-architecture-req-ec2)，您可以选择合适的方法来安装 RPM 脚本或 Debian 脚本。如果您使用 *Fedora* 平台，则必须使用此方法来安装代理。

## 方法 1-使用 Amazon Systems Manager
<a name="install-gdu-by-using-sys-runtime-monitoring"></a>

要使用此方法，请确保您的 Amazon EC2 实例处于 Amazon Systems Manager 托管状态，然后安装代理。

### Amazon Systems Manager 托管 Amazon EC2 实例
<a name="manage-ssm-ec2-instance-runtime-monitoring"></a>

按照以下步骤操作，以确保您的 Amazon EC2 实例由 Amazon Systems Manager 托管。
+ [Amazon Systems Manager](https://docs.amazonaws.cn/systems-manager/latest/userguide/what-is-systems-manager.html)帮助您端到端地管理 Amazon 应用程序和资源，并实现大规模的安全运营。

  要使用管理您的 Amazon EC2 实例 Amazon Systems Manager，请参阅*Amazon Systems Manager 用户指南*中的为 [Amazon EC2 实例设置 Systems Manager](https://docs.amazonaws.cn/systems-manager/latest/userguide/systems-manager-setting-up-ec2.html)。
+ 下表显示了新的 GuardDuty 托管 Amazon Systems Manager 文档：    
[See the AWS documentation website for more details](http://docs.amazonaws.cn/guardduty/latest/ug/installing-gdu-security-agent-ec2-manually.html)

  有关更多信息 Amazon Systems Manager，请参阅《*Amazon Systems Manager 用户指南》*[中的 Amazon EC2 Systems Manager 文档](https://docs.amazonaws.cn/systems-manager/latest/userguide/documents.html)。
**对于 Debian Server**  
提供的适用于 Debian 服务器的 Amazon 系统映像 (AMI) Amazon 要求您安装 Amazon Systems Manager 代理（SSM 代理）。您需要执行额外的步骤来安装 SSM Agent，以确保 Amazon EC2 Debian 服务器实例由 SSM 托管。有关您需要执行的步骤的信息，请参阅《Amazon Systems Manager 用户指南》中的[在 Debian Server 实例上手动安装 SSM Agent](https://docs.amazonaws.cn/systems-manager/latest/userguide/agent-install-deb.html)**。

**要安装适用于 Amazon EC2 实例的 GuardDuty 代理，请使用以下方法 Amazon Systems Manager**

1. 打开 Amazon Systems Manager 控制台，网址为[https://console.aws.amazon.com/systems-manager/](https://console.amazonaws.cn/systems-manager/)。

1. 在导航窗格中，选择**文档**

1. 在**由 Amazon 所有**中，选择 `AmazonGuardDuty-ConfigureRuntimeMonitoringSsmPlugin`。

1. 选择 **Run Command**。

1. 输入以下 Run 命令参数
   + 操作：选择**安装**。
   + 安装类型：选择**安装或卸载**。
   + 名称: `AmazonGuardDuty-RuntimeMonitoringSsmPlugin`
   + 版本：如果此处仍为空，您将获得最新版本 GuardDuty 的安全客户端。有关发行版本的更多信息，请参阅[GuardDuty Amazon EC2 实例的安全代理版本](runtime-monitoring-agent-release-history.md#ec2-gdu-agent-release-history)。

1. 选择目标 Amazon EC2 实例。您可以选择一个或多个 Amazon EC2 实例。有关更多信息，请参阅《Amazon Systems Manager 用户指南》中的[从控制台运行Amazon Systems Manager 命令](https://docs.amazonaws.cn/systems-manager/latest/userguide/running-commands-console.html)**。

1. 验证 GuardDuty 代理安装是否正常。有关更多信息，请参阅 [正在验证 GuardDuty 安全代理安装状态](#validate-ec2-gdu-agent-installation-healthy)。

## 方法 2 – 使用 Linux 软件包管理器
<a name="install-gdu-by-rpm-scripts-runtime-monitoring"></a>

使用此方法，您可以通过运行 RPM 脚本或 Debian 脚本来安装 GuardDuty 安全代理。您可以根据操作系统来选择一种偏好的方法：
+ 使用 RPM 脚本在操作系统发行版 AL2、AL2023 RedHat、CentOS 或 Fedora 上安装安全代理。AL2023
+ 使用 Debian 脚本在 Ubuntu 或 Debian 操作系统发行版上安装安全代理。有关支持的 Ubuntu 和 Debian 操作系统发行版的信息，请参阅 [验证架构要求](prereq-runtime-monitoring-ec2-support.md#validating-architecture-req-ec2)。

------
#### [ RPM installation ]
**重要**  
我们建议先验证 GuardDuty 安全代理 RPM 签名，然后再将其安装到您的计算机上。

1. 验证 GuardDuty 安全代理 RPM 签名

   1. 

**准备模板**

      使用适当的公有密钥、x86\_64 RPM 签名、arm64 RPM 签名以及指向 Amazon S3 存储桶中所托管 RPM 脚本的相应访问链接来准备命令。替换 Amazon Web Services 区域、 Amazon 账户 ID 和 GuardDuty 代理版本的值以访问 RPM 脚本。
      + **公有密钥**：

        ```
        s3://{{694911143906}}-{{eu-west-1}}-guardduty-agent-rpm-artifacts/{{1.9.2}}/publickey.pem
        ```
      + **GuardDuty 安全代理 RPM 签名**：  
x86\_64 RPM 签名  

        ```
        s3://{{694911143906}}-{{eu-west-1}}-guardduty-agent-rpm-artifacts/{{1.9.2}}/x86_64/amazon-guardduty-agent-{{1.9.2}}.x86_64.sig
        ```  
arm64 RPM 签名  

        ```
        s3://{{694911143906}}-{{eu-west-1}}-guardduty-agent-rpm-artifacts/{{1.9.2}}/arm64/amazon-guardduty-agent-{{1.9.2}}.arm64.sig
        ```
      + **Amazon S3 存储桶中 RPM 脚本的访问链接**：  
x86\_64 RPM 访问链接  

        ```
        s3://{{694911143906}}-{{eu-west-1}}-guardduty-agent-rpm-artifacts/{{1.9.2}}/x86_64/amazon-guardduty-agent-{{1.9.2}}.x86_64.rpm
        ```  
arm64 RPM 访问链接  

        ```
        s3://{{694911143906}}-{{eu-west-1}}-guardduty-agent-rpm-artifacts/{{1.9.2}}/arm64/amazon-guardduty-agent-{{1.9.2}}.arm64.rpm
        ```    
[See the AWS documentation website for more details](http://docs.amazonaws.cn/guardduty/latest/ug/installing-gdu-security-agent-ec2-manually.html)

   1. 

**下载模板**

      以下命令用于下载相应的公有密钥、x86\_64 RPM 签名、arm64 RPM 签名以及指向 Amazon S3 存储桶中所托管 RPM 脚本的相应访问链接，务必要将账户 ID 替换为相应 Amazon Web Services 账户 ID，将区域替换为您当前所在的区域。

      ```
      aws s3 cp s3://{{694911143906}}-{{eu-west-1}}-guardduty-agent-rpm-artifacts/{{1.9.2}}/x86_64/amazon-guardduty-agent-{{1.9.2}}.x86_64.rpm ./amazon-guardduty-agent-{{1.9.2}}.x86_64.rpm
      aws s3 cp s3://{{694911143906}}-{{eu-west-1}}-guardduty-agent-rpm-artifacts/{{1.9.2}}/x86_64/amazon-guardduty-agent-{{1.9.2}}.x86_64.sig ./amazon-guardduty-agent-{{1.9.2}}.x86_64.sig
      aws s3 cp s3://{{694911143906}}-{{eu-west-1}}-guardduty-agent-rpm-artifacts/{{1.9.2}}/publickey.pem ./publickey.pem
      ```

   1. 

**导入公有密钥**

      使用以下命令将公有密钥导入到数据库：

      ```
      gpg --import publickey.pem
      ```

      gpg 显示导入成功

      ```
      gpg: key 093FF49D: public key "AwsGuardDuty" imported
      gpg: Total number processed: 1
      gpg:               imported: 1  (RSA: 1)
      ```

   1. 

**验证签名**

      使用以下命令验证签名

      ```
      gpg --verify amazon-guardduty-agent-{{1.9.2}}.x86_64.sig amazon-guardduty-agent-{{1.9.2}}.x86_64.rpm
      ```

      如果通过验证，您将看到类似于以下结果的消息。现在，您可以继续使用 RPM 安装 GuardDuty 安全代理。

      输出示例：

      ```
      gpg: Signature made Fri 17 Nov 2023 07:58:11 PM UTC using ? key ID 093FF49D
      gpg: Good signature from "AwsGuardDuty"
      gpg: WARNING: This key is not certified with a trusted signature!
      gpg:          There is no indication that the signature belongs to the owner.
      Primary key fingerprint: 7478 91EF 5378 1334 4456  7603 06C9 06A7 093F F49D
      ```

      如果验证失败，则意味着 RPM 上的签名可能已被篡改。您必须从数据库中移除该公有密钥并重试验证过程。

      示例：

      ```
      gpg: Signature made Fri 17 Nov 2023 07:58:11 PM UTC using ? key ID 093FF49D
      gpg: BAD signature from "AwsGuardDuty"
      ```

      使用以下命令从数据库中移除公有密钥：

      ```
      gpg --delete-keys AwsGuardDuty
      ```

      现在，再次尝试验证过程。

1. [从 Linux 或 macOS 使用 SSH 连接](https://docs.amazonaws.cn/AWSEC2/latest/UserGuide/connect-linux-inst-ssh.html)。

1. 使用以下命令安装 GuardDuty 安全代理：

   ```
   sudo rpm -ivh amazon-guardduty-agent-{{1.9.2}}.x86_64.rpm
   ```

1. 验证 GuardDuty 代理安装是否正常。有关这些步骤的更多信息，请参阅[正在验证 GuardDuty 安全代理安装状态](#validate-ec2-gdu-agent-installation-healthy)。

------
#### [ Debian installation ]
**重要**  
我们建议先验证 GuardDuty 安全代理 Debian 签名，然后再将其安装到您的计算机上。

1. 验证 GuardDuty 安全代理 Debian 签名

   1. 

**为相应的公有密钥、amd64 Debian 软件包签名、arm64 Debian 软件包签名以及 Amazon S3 存储桶中所托管 Debian 脚本的相应访问链接准备模板**

      在以下模板中，替换 Amazon 账户 ID 和 GuardDuty代理版本的值以访问 Debian 软件包脚本。 Amazon Web Services 区域
      + **公有密钥**：

        ```
        s3://{{694911143906}}-{{eu-west-1}}-guardduty-agent-deb-artifacts/{{1.9.2}}/publickey.pem
        ```
      + **GuardDuty 安全代理 Debian 签名**：  
amd64 签名  

        ```
        s3://{{694911143906}}-{{eu-west-1}}-guardduty-agent-deb-artifacts/{{1.9.2}}/amd64/amazon-guardduty-agent-{{1.9.2}}.amd64.sig
        ```  
arm64 签名  

        ```
        s3://{{694911143906}}-{{eu-west-1}}-guardduty-agent-deb-artifacts/{{1.9.2}}/arm64/amazon-guardduty-agent-{{1.9.2}}.arm64.sig
        ```
      + **Amazon S3 存储桶中 Debian 脚本的访问链接**：  
amd64 访问链接  

        ```
        s3://{{694911143906}}-{{eu-west-1}}-guardduty-agent-deb-artifacts/{{1.9.2}}/amd64/amazon-guardduty-agent-{{1.9.2}}.amd64.deb
        ```  
arm64 访问链接  

        ```
        s3://{{694911143906}}-{{eu-west-1}}-guardduty-agent-deb-artifacts/{{1.9.2}}/arm64/amazon-guardduty-agent-{{1.9.2}}.arm64.deb
        ```    
[See the AWS documentation website for more details](http://docs.amazonaws.cn/guardduty/latest/ug/installing-gdu-security-agent-ec2-manually.html)

   1. 

**下载相应的公有密钥、amd64 签名、arm64 签名以及 Amazon S3 存储桶中所托管 Debian 脚本的相应访问链接**

      在以下命令中，将账户 ID 替换为相应的 Amazon Web Services 账户 ID，将地区替换为您当前的区域。

      ```
      aws s3 cp s3://{{694911143906}}-{{eu-west-1}}-guardduty-agent-deb-artifacts/{{1.9.2}}/amd64/amazon-guardduty-agent-{{1.9.2}}.amd64.deb ./amazon-guardduty-agent-{{1.9.2}}.amd64.deb
      aws s3 cp s3://{{694911143906}}-{{eu-west-1}}-guardduty-agent-deb-artifacts/{{1.9.2}}/amd64/amazon-guardduty-agent-{{1.9.2}}.amd64.sig ./amazon-guardduty-agent-{{1.9.2}}.amd64.sig
      aws s3 cp s3://{{694911143906}}-{{eu-west-1}}-guardduty-agent-deb-artifacts/{{1.9.2}}/publickey.pem ./publickey.pem
      ```

   1. 将公有密钥导入数据库中

      ```
      gpg --import publickey.pem
      ```

      gpg 显示导入成功

      ```
      gpg: key 093FF49D: public key "AwsGuardDuty" imported
      gpg: Total number processed: 1
      gpg:               imported: 1  (RSA: 1)
      ```

   1. 验证签名

      ```
      gpg --verify amazon-guardduty-agent-{{1.9.2}}.amd64.sig amazon-guardduty-agent-{{1.9.2}}.amd64.deb
      ```

      如果验证成功，您将看到与以下结果类似的消息：

      输出示例：

      ```
      gpg: Signature made Fri 17 Nov 2023 07:58:11 PM UTC using ? key ID 093FF49D
      gpg: Good signature from "AwsGuardDuty"
      gpg: WARNING: This key is not certified with a trusted signature!
      gpg:          There is no indication that the signature belongs to the owner.
      Primary key fingerprint: 7478 91EF 5378 1334 4456  7603 06C9 06A7 093F F49D
      ```

      现在，您可以继续使用 Debian 安装 GuardDuty 安全代理。

      但如果验证失败，则意味着 Debian 软件包中的签名可能已被篡改。

      示例：

      ```
      gpg: Signature made Fri 17 Nov 2023 07:58:11 PM UTC using ? key ID 093FF49D
      gpg: BAD signature from "AwsGuardDuty"
      ```

      使用以下命令从数据库中移除公有密钥：

      ```
      gpg --delete-keys AwsGuardDuty
      ```

      现在，重新尝试验证过程。

1. [从 Linux 或 macOS 使用 SSH 连接](https://docs.amazonaws.cn/AWSEC2/latest/UserGuide/connect-linux-inst-ssh.html)。

1. 使用以下命令安装 GuardDuty 安全代理：

   ```
   sudo dpkg -i amazon-guardduty-agent-{{1.9.2}}.amd64.deb
   ```

1. 验证 GuardDuty 代理安装是否正常。有关这些步骤的更多信息，请参阅[正在验证 GuardDuty 安全代理安装状态](#validate-ec2-gdu-agent-installation-healthy)。

------

## 内存不足错误
<a name="out-of-memory-error-ec2-instal-agent-manual"></a>

如果您在手动安装或更新 Amazon EC2 GuardDuty 的安全代理时`out-of-memory`遇到错误，请参阅[内存不足问题的故障排除](troubleshooting-guardduty-runtime-monitoring.md#troubleshoot-ec2-cpu-out-of-memory-error)。

## 正在验证 GuardDuty 安全代理安装状态
<a name="validate-ec2-gdu-agent-installation-healthy"></a>

执行安装 GuardDuty 安全代理的步骤后，请使用以下步骤验证代理的状态：

**验证 GuardDuty 安全代理是否正常**

1. [从 Linux 或 macOS 使用 SSH 连接](https://docs.amazonaws.cn/AWSEC2/latest/UserGuide/connect-linux-inst-ssh.html)。

1. 运行以下命令以检查 GuardDuty 安全代理的状态：

   ```
   sudo systemctl status amazon-guardduty-agent
   ```

要查看安全代理安装日志，可通过路径 `/var/log/amzn-guardduty-agent/` 获取。

要查看日志，请运行 `sudo journalctl -u amazon-guardduty-agent`。