> ## Documentation Index
> Fetch the complete documentation index at: https://docs.monad.xyz/llms.txt
> Use this file to discover all available pages before exploring further.

# 配置 RPC 以使用归档数据

<Warning title="这不适用于验证者节点">
  与归档服务的集成是为提供 RPC 服务的全节点设计的,**不适用于验证者节点**。
</Warning>

<Note title="启用调用跟踪">
  建议为 **RPC** 节点启用 `--trace_calls`。
  这将保留调用跟踪(例如 `debug_traceTransaction`)所需的详细错误信息。
  如需进行此覆盖,请运行 `sudo systemctl edit monad-execution`,并将 `--trace_calls` CLI 参数添加到 `ExecStart` 定义中(可能需要行延续符 `\`):

  ```sh theme={null}
  sudo systemctl edit monad-execution
  ```

  ```toml theme={null}
  [Service]
  Type=simple
  ExecStart=
  ExecStart=/usr/local/bin/monad \
      [... existing cli commands, see comment at the bottom of the systemctl editor ...]
      --trace_calls
  ```
</Note>

## 配置 `monad-rpc` 使用归档服务器备份

1. 配置一个地理位置靠近该全节点的[归档服务器](/zh/node-ops/archive-data/running-an-archive-server)。

2. 将以下变量添加到您的 `/home/monad/.env`:

   ```sh theme={null}
   # Replace <db username>, <db pwd> and <db hostname> with your values from Step (1)
   MONGO_URL="mongodb://<db username>:<db pwd>@<db hostname>:27017"
   MONGO_DB_NAME="archive-db"
   DB_HOST=<db hostname>
   DB_PWD=<db pwd>
   DB_USERNAME=<db username>
   ```

3. 验证连接:

   ```sh theme={null}
   source /home/monad/.env

   nc -vz $DB_HOST 27017
   mongosh "$MONGO_URL" --quiet --eval '
       try {
       db.adminCommand({ping: 1});
       const archiveDb = db.getSiblingDB("archive-db");
       const hasCollection = archiveDb.getCollectionNames().includes("block_level");
       print(hasCollection ? "OK: Collection exists" : "FAIL: Collection missing");
       quit(hasCollection ? 0 : 1);
       } catch(e) {
       print("FAIL: " + e.message);
       quit(1);
       }
   '
   ```

4. 为 `monad-rpc` 添加以下 systemd 覆盖配置:

   ```sh theme={null}
   sudo systemctl edit monad-rpc
   ```

   ```toml theme={null}
   [Service]
   ExecStart=
   ExecStart=/usr/local/bin/monad-rpc \
       [... existing cli commands, see comment at the bottom of the systemctl editor ...]
       --mongo-url ${MONGO_URL} \
       --mongo-db-name ${MONGO_DB_NAME} \
       --use-eth-get-logs-index
   ```

5. 重新加载并重启:

   ```sh theme={null}
   sudo systemctl daemon-reload
   sudo systemctl restart monad-rpc
   ```

6. 检查本地保留范围之外的一个早期区块:

   ```sh theme={null}
   curl -X POST -H "Content-Type: application/json" --data '{
           "jsonrpc": "2.0",
           "method": "eth_getBlockByNumber",
           "params": ["0x1", false],
           "id": 1
       }'  http://localhost:8080
   ```

## 配置 `monad-rpc` 使用 AWS 备份

1. 确保机器上具备 AWS 身份和凭证。

   * 运行 `aws configure` 以在全节点上设置您的 AWS 凭证和配置。这应会在 `/home/monad/.aws/` 目录下生成 `config` 和 `credentials` 文件。请参阅 [AWS CLI 文档](https://docs.aws.amazon.com/cli/latest/userguide/cli-configure-files.html)。
   * 在 systemd 中运行时,需要在 `monad` 用户下创建 AWS 权限。请参阅通用的验证者或全节点文档以获得运行 RPC 的更完整说明,但请确保 `monad` 用户拥有可访问该存储桶的 AWS 凭证。

2. 使用此[用户指南](https://docs.aws.amazon.com/IAM/latest/UserGuide/access_policies_create-console.html#access_policies_create-json-editor)以及下列示例 JSON 创建一个 AWS IAM 策略:

   ```json theme={null}
   {
       "Version": "2012-10-17",
       "Statement": [
           {
               "Effect": "Allow",
               "Action": [
                   "s3:GetObject",
                   "s3:ListBucket",
                   "s3:GetBucketRequestPayment",
                   "execute-api:Invoke"
               ],
               "Resource": [
                   "arn:aws:s3:::*/*",
                   "arn:aws:s3:::*",
                   "arn:aws:execute-api:*:*:*"
               ],
               "Condition": {
                   "StringEquals": {
                       "aws:ResourceOrgID": "o-sq9ayub2wk"
                   }
               }
           }
       ]
   }
   ```

3. 若要获取一个免费层级的 API key,请向 `https://9df09fanz1.execute-api.us-east-2.amazonaws.com/prod/free-tier-key` 发送一个 AWS Signature v4 签名请求。

   * 示例,使用 `awscurl` 工具:

     ```bash theme={null}
     awscurl https://9df09fanz1.execute-api.us-east-2.amazonaws.com/prod/free-tier-key --region us-east-2
     ```

4. 将以下变量添加到您的 `/home/monad/.env`:

   ```sh theme={null}
   ARCHIVE_API_KEY=<key from step 3>
   # Replace with appropriate mainnet, localnet or testnet bucket
   # Below is the public testnet bucket maintained by Category Labs
   ARCHIVE_BUCKET="testnet-can-004-0-aavn9ll"
   # Below is the public mainnet bucket maintained by Category Labs
   ARCHIVE_BUCKET="mainnet-deu-010-0" # mainnet-deu-009-0 is a sibling bucket you can also use
   ```

5. 为 `monad-rpc` 添加以下 systemd 覆盖配置:

   ```sh theme={null}
   sudo systemctl edit monad-rpc
   ```

   ```toml theme={null}
   [Service]
   ExecStart=
   ExecStart=/usr/local/bin/monad-rpc \
       [... existing cli commands, see comment at the bottom of the systemctl editor ...]
       --s3-bucket ${ARCHIVE_BUCKET} \
       --region "us-east-2" \
       --archive-url "https://9df09fanz1.execute-api.us-east-2.amazonaws.com/prod" \
       --archive-api-key ${ARCHIVE_API_KEY}
   ```

6. 重新加载并重启:

   ```sh theme={null}
   sudo systemctl daemon-reload
   sudo systemctl restart monad-rpc
   ```

7. 检查本地保留范围之外的一个早期区块:

   <Note>
     如果您已经启用了 MongoDB 后端,默认情况下此操作不会真正测试任何内容。若要进行测试,请暂时移除 MongoDB 后端,运行以下命令,然后恢复 MongoDB 配置。
   </Note>

   ```sh theme={null}
   curl -X POST -H "Content-Type: application/json" --data '{
           "jsonrpc": "2.0",
           "method": "eth_getBlockByNumber",
           "params": ["0x1", false],
           "id": 1
       }'  http://localhost:8080
   ```
