# 在 AWS 上运行

这是在 AWS 上安装 Aptos 节点的分步指南。这些步骤将在不同的机器上配置一个验证者节点和一个全节点。

### 在继续之前

确保在继续之前完成这些先决条件步骤：

1. 设置您的 AWS 账户。
2. 确保在您的本地计算机上安装了以下内容：
   * **Aptos CLI 0.3.1**：<https://aptos.dev/cli-tools/aptos-cli-tool/install-aptos-cli>
   * **Terraform 1.2.4**：<https://www.terraform.io/downloads.html>
   * **Kubernetes CLI**：<https://kubernetes.io/docs/tasks/tools/>
   * **AWS CLI**：<https://aws.amazon.com/cli/>

### 安装

1. 为您的节点配置工作创建一个工作目录

   * 选择一个工作空间的名字，例如： `测试网`\*\*注意：\*\*这决定了 Terraform 工作空间名称，该名称也用于形成资源名称。

   ```
   export WORKSPACE=testnet
   ```

   * 为工作区创建一个目录。

     ```
     mkdir -p ~/$WORKSPACE
     ```
   * 为您的节点选择一个用户名，例如：`alice`.

     ```
     export USERNAME=alice
     ```
2. 创建一个 S3 桶式存储器，用于在 AWS 上存储 Terraform 状态。您可以在 AWS UI 上或通过以下命令执行此操作：

   ```
   aws s3 mb s3://<bucket name> --region <region name>
   ```
3. 创建一个名为 Terraform 的文件 `main.tf` 在您的工作目录中：

   ```
   cd ~/$WORKSPACE
   vi main.tf
   ```
4. 修改 `main.tf`文件以配置 Terraform 并从 Terraform 模块创建 Aptos 全节点。请参阅下面的 `main.tf` 示例内容：

   ```
   terraform {
     required_version = "~> 1.2.0"
     backend "s3" {
       bucket = "terraform.aptos-node"
       key    = "state/aptos-node"
       region = <aws region>
     }
   }

   provider "aws" {
     region = <aws region>
   }

   module "aptos-node" {
     # Download Terraform module from aptos-labs/aptos-core repo
     source        = "github.com/aptos-labs/aptos-core.git//terraform/aptos-node/aws?ref=testnet"
     region        = <aws region>  # Specify the region
     # zone_id     = "<Route53 zone id>"  # zone id for Route53 if you want to use DNS
     era           = 1              # bump era number to wipe the chain
     chain_id      = 43
     image_tag     = "testnet" # Specify the image tag to use
     validator_name = "<Name of your Validator>"
   }
   ```

   有关完整的自定义选项，请参阅：

   * Terraform 变量文件<https://github.com/aptos-labs/aptos-core/blob/main/terraform/aptos-node/aws/variables.tf>，和
   * YAML 文件的值<https://github.com/aptos-labs/aptos-core/blob/main/terraform/helm/aptos-node/values.yaml>.
5. 在您创建 `main.tf` 文件的 `$WORKSPACE` 目录中初始化 Terraform。

   ```
   terraform init
   ```

   这会将所有 Terraform 依赖项下载到当前工作目录中的 `.terraform` 文件夹中。
6. 创建一个新的 Terraform 工作区来隔离您的环境：

   ```
   terraform workspace new $WORKSPACE
   # This command will list all workspaces
   terraform workspace list
   ```
7. 应用配置。

   ```
   terraform apply
   ```

   这可能需要一段时间才能完成（约 20 分钟）。 Terraform 将在您的 AWS 云帐户上创建所有资源。
8. 在 `terraform apply` 完成后，您可以检查这些资源是否已创建：
   * `aws eks update-kubeconfig --name aptos-$WORKSPACE`：为您的 k8s 集群配置访问权限。
   * `kubectl get pods`：这应该有 haproxy、验证者和全节点，以及验证器和 fullnode pod `pending`（需要在后面的步骤中进一步操作）。
   * `kubectl get svc`：这应该有 `validator-lb` 和 `fullnode-lb`，您可以稍后共享一个外部 IP 以进行连接。
9. 将您的节点 IP 信息整合进您的环境中：

   ```
   export VALIDATOR_ADDRESS="$(kubectl get svc ${WORKSPACE}-aptos-node-0-validator-lb --output jsonpath='{.status.loadBalancer.ingress[0].hostname}')"

   export FULLNODE_ADDRESS="$(kubectl get svc ${WORKSPACE}-aptos-node-0-fullnode-lb --output jsonpath='{.status.loadBalancer.ingress[0].hostname}')"
   ```
10. 在您的工作目录中生成密钥对（节点所有者、投票者、操作员密钥、共识密钥和网络密钥）。

    ```
    aptos genesis generate-keys --output-dir ~/$WORKSPACE/keys
    ```

    这将在 `~/$WORKSPACE/keys` 目录下创建 4 个密钥文件：

    * `public-keys.yaml`
    * `private-keys.yaml`
    * `validator-identity.yaml`，和
    * `validator-full-node-identity.yaml`.

      重要

      将您的私钥文件备份到安全的地方。这些关键文件对于您建立节点的所有权很重要。**永远不要与任何人共享私钥。**
11. 配置验证器信息。这是您稍后在 Aptos 社区网站上注册所需的所有信息。

    ```
    aptos genesis set-validator-configuration \\
      --local-repository-dir ~/$WORKSPACE \\
      --username $USERNAME \\
      --owner-public-identity-file ~/$WORKSPACE/keys/public-keys.yaml \\
      --validator-host $VALIDATOR_ADDRESS:6180 \\
      --full-node-host $FULLNODE_ADDRESS:6182 \\
      --stake-amount 100000000000000
    ```

    这将在 `~/$WORKSPACE/$USERNAME`  目录中创建两个 YAML 文件：`owner.yaml` 和 `operator.yaml`。
12. 创建一个布局模板文件，该文件用于定义 Aptos `validatorSet` 中的节点。

    ```
    aptos genesis generate-layout-template --output-file ~/$WORKSPACE/layout.yaml
    ```

    编辑`layout.yaml`，添加 `root_key`、验证点节点用户名和 `chain_id`：

    ```
    root_key: "D04470F43AB6AEAA4EB616B72128881EEF77346F2075FFE68E14BA7DEBD8095E"
    users: ["<username you specified from previous step>"]
    chain_id: 43
    allow_new_validators: false
    epoch_duration_secs: 7200
    is_test: true
    min_stake: 100000000000000
    min_voting_threshold: 100000000000000
    max_stake: 100000000000000000
    recurring_lockup_duration_secs: 86400
    required_proposer_stake: 100000000000000
    rewards_apy_percentage: 10
    voting_duration_secs: 43200
    voting_power_increase_limit: 20
    ```

    请确保您使用与示例中所示相同的根公钥和链 ID，这些配置将在注册期间用于验证您的节点。
13. 将 AptosFramework Move 包下载到 `~/$WORKSPACE` 目录中作为 `framework.mrb`

    ```
    wget <https://github.com/aptos-labs/aptos-core/releases/download/aptos-framework-v0.3.0/framework.mrb> -P ~/$WORKSPACE
    ```
14. Compile the genesis blob and waypoint.编译创世和航路点。

    ```
    aptos genesis generate-genesis --local-repository-dir ~/$WORKSPACE --output-dir ~/$WORKSPACE
    ```

    这将在您的工作目录中创建两个文件：`genesis.blob` 和 `waypoint.txt`。
15. 总而言之，在您的工作目录中，您应该有一个文件列表：
    * `main.tf`：用于安装 `aptos-node` 模块的 Terraform 文件（来自步骤 3 和 4）。
    * `keys` 文件夹，其中包括：
      * `public-keys.yaml`：用于所有者帐户、共识、网络的公钥（从第 10 步开始）。
      * `private-keys.yaml`：用于所有者帐户、共识、网络的私钥（从第 10 步开始）。
      * `validator-identity.yaml`：用于设置验证者身份的私钥（从第 10 步开始）。
      * `validator-full-node-identity.yaml`：用于设置验证者完整节点身份的私钥（从第 10 步开始）。
    * `username` 文件夹，其中包括：
      * `owner.yaml`：定义所有者、操作员和选民映射。它们在测试模式下都是同一个帐户（从第 11 步开始）。
      * `operator.yaml`：将用于验证者和全节点的节点信息（来自第 11 步）。
    * `layout.yaml`：包含根键、验证器用户和链 ID 的键值的布局文件（来自第 12 步）。
    * `framework.mrb`：AptosFramework Move 包（从第 13 步开始）。
    * `waypoint.txt`：创世交易的航点（来自第 14 步）。
    * `genesis.blob` 包含有关框架、validatorSet 等所有信息的 genesis 二进制文件（来自第 14 步）。
16. 将`genesis.blob`、`waypoint.txt`和身份文件作为插件k8s。

```
kubectl create secret generic ${WORKSPACE}-aptos-node-0-genesis-e1 \\
    --from-file=genesis.blob=genesis.blob \\
    --from-file=waypoint.txt=waypoint.txt \\
    --from-file=validator-identity.yaml=keys/validator-identity.yaml \\
    --from-file=validator-full-node-identity.yaml=keys/validator-full-node-identity.yaml
```

{% hint style="info" %}
💡 注意

`e1` 后缀是时代编号。如果您更改了时代编号，请确保在创建密钥时将它匹配。
{% endhint %}

1. 检查所有 pod 是否都在运行。

   ```
   kubectl get pods

   NAME                                        READY   STATUS    RESTARTS   AGE
   node1-aptos-node-0-fullnode-e9-0              1/1     Running   0          4h31m
   node1-aptos-node-0-haproxy-7cc4c5f74c-l4l6n   1/1     Running   0          4h40m
   node1-aptos-node-0-validator-0                1/1     Running   0          4h30m
   ```

现在您已成功完成在测试模式下设置节点。您现在可以前往 [Aptos 社区平台网站](https://community.aptoslabs.com/)进行注册。


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://gushi10546.gitbook.io/aptos-kai-fa-zhe-wen-dang/jie-dian/validators/zai-aws-shang-yun-xing.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
