# Linux

服务器最低要求：2C 8G （注：2C 4G 也可以）

使用的系统：Ubuntu 20.04

## 1. 安装 Docker 和 docker-compose

{% hint style="info" %}
如果你已经安装过，可以跳过本步骤。
{% endhint %}

依次执行如下命令安装 Docker 和 docker-compose。

```shell
# 安装 Docker
wget -O get-docker.sh https://get.docker.com 
sudo sh get-docker.sh
rm -f get-docker.sh

# 安装 docker-compose
sudo curl -L "https://github.com/docker/compose/releases/download/1.29.2/docker-compose-$(uname -s)-$(uname -m)" -o /usr/local/bin/docker-compose
sudo chmod +x /usr/local/bin/docker-compose
```

检查 Docker 和 docker-compose 是否安装：

```
docker -v
docker-compose -v
```

![Check docker and docker-compose](/files/6youjTVWH6nyeeqIBGw1)

## 2. 下载 Aptos 节点运行所需文件

依次执行如下命令：

```shell
# 创建 aptos-node 目录并进入该目录，之后的操作都会在该目录下进行
mkdir -p ~/aptos-node && cd ~/aptos-node
# 下载 docker-compose 编排文件
wget -O ./docker-compose.yaml https://raw.githubusercontent.com/jiangydev/aptos-node/main/docker-compose.yaml
# 下载 全节点配置文件
wget -O ./public_full_node.yaml https://raw.githubusercontent.com/jiangydev/aptos-node/main/public_full_node.yaml
# 下载 创世节点文件
wget -O ./genesis.blob https://devnet.aptoslabs.com/genesis.blob
# 下载 waypoint（可验证检查点）文件
wget -O ./waypoint.txt https://devnet.aptoslabs.com/waypoint.txt
```

下载完成后，使用命令 `ls -al` 查看目录下的文件：

![](/files/lT2QRatzrA0zcXlCvY5F)

## 3. 创建静态身份

创建静态身份的目的是，每次启动都使用这个身份。

### 3.1 生成私钥、公钥和 Peer ID

在之前的目录下，执行命令生成私钥：

```powershell
# 更新镜像
sudo docker pull aptoslabs/tools:devnet
# 生成
sudo docker run --rm aptoslabs/tools:devnet sh -c "echo '开始生成私钥...' && aptos key generate --encoding hex --key-type x25519 --output-file /root/private-key.txt && echo '\n\n开始生成公钥和 Peer ID...' && aptos key extract-peer --encoding hex --private-key-file /root/private-key.txt --output-file /root/peer-info.yaml && echo '\n\n您的私钥：' && cat /root/private-key.txt && echo '\n\n您的公钥和 Peer ID 信息如下：' && cat /root/peer-info.yaml"

```

运行的结果如下：

```
开始生成私钥...
{
  "Result": "Success"
}


开始生成公钥和 Peer ID...
{
  "Result": {
    "92c826d2733c391a4f8ee6d4e573b764": {
      "addresses": [],
      "keys": [
        "3129d20a6ebb3a92be794db60416e6eb92c826d2733c391a4f8ee6d4e573b764"
      ],
      "role": "Downstream"
    }
  }
}


您的私钥：


您的公钥和 Peer ID 信息如下：
---
3129d20a6ebb3a92be794db60416e6eb92c826d2733c391a4f8ee6d4e573b764:
  addresses: []
  keys:
    - 3129d20a6ebb3a92be794db60416e6eb92c826d2733c391a4f8ee6d4e573b764
  role: Downstream
```

* `08500EDFBE94721A8D5614529AAC4E1AF427BB47498EC0E1A65815057137516A` 就是私钥；
* `3129d20a6ebb3a92be794db60416e6eb92c826d2733c391a4f8ee6d4e573b764` 是 Peer ID，也是公钥；

### 3.2 修改全节点的静态身份

编辑 public full node.yaml 文件，并修改私钥和 Peer ID：

{% hint style="info" %}
提醒：

* 请使用上一步自己生成的私钥和 Peer ID，以下示例仅供参考。
* 请妥善保存好私钥；（公钥和 Peer ID 是由私钥生成的）
* 请一定要按如下格式修改。
  {% endhint %}

{% hint style="info" %}
如何编辑文件？

1. 在命令行界面使用 vi 编辑打开文件，命令：`vi public`\_`full_node.yaml`
2. 进入后，键盘上按下英文字母 `i`，即可开始编辑；（注：输入法切换到英文半角）
3. 编辑完成后，键盘上按下 esc 键，退出编辑；
4. 输入 `:wq!`，保存并退出。
   {% endhint %}

```yaml
base:
    # This is the location Aptos will store its database. It is backed by a dedicated docker volume
    # for persistence.
    data_dir: "/opt/aptos/data"
    role: "full_node"
    waypoint:
        # This is a checkpoint into the blockchain for added security.
        from_file: "/opt/aptos/etc/waypoint.txt"

execution:
    # Path to a genesis transaction. Note, this must be paired with a waypoint. If you update your
    # waypoint without a corresponding genesis, the file location should be an empty path.
    genesis_file_location: "/opt/aptos/etc/genesis.blob"

state_sync:
  state_sync_driver:
    enable_state_sync_v2: true

full_node_networks:
    - network_id: "public"
      discovery_method: "onchain"
      identity:
        type: "from_config"
        key: "这里换成自己生成的私钥"
        peer_id: "这里换成自己生成的PeerID"
      # The network must have a listen address to specify protocols. This runs it locally to
      # prevent remote, incoming connections.
      listen_address: "/ip4/0.0.0.0/tcp/6180"
      # Define the upstream peers to connect to
      seeds:
        bb14af025d226288a3488b4433cf5cb54d6a710365a2d95ac6ffbd9b9198a86a:
            addresses:
            - "/dns4/pfn0.node.devnet.aptoslabs.com/tcp/6182/noise-ik/bb14af025d226288a3488b4433cf5cb54d6a710365a2d95ac6ffbd9b9198a86a/handshake/0"
            role: "Upstream"
        7fe8523388084607cdf78ff40e3e717652173b436ae1809df4a5fcfc67f8fc61:
            addresses:
            - "/dns4/pfn1.node.devnet.aptoslabs.com/tcp/6182/noise-ik/7fe8523388084607cdf78ff40e3e717652173b436ae1809df4a5fcfc67f8fc61/handshake/0"
            role: "Upstream"
        f6b135a59591677afc98168791551a0a476222516fdc55869d2b649c614d965b:
            addresses:
            - "/dns4/pfn2.node.devnet.aptoslabs.com/tcp/6182/noise-ik/f6b135a59591677afc98168791551a0a476222516fdc55869d2b649c614d965b/handshake/0"
            role: "Upstream"

api:
    # This specifies your REST API endpoint. Intentionally on public so that Docker can export it.
    address: 0.0.0.0:8080

```

修改后的结果如下：

![](/files/QS3nt7SK0HuvVuWT8dYV)

## 4. 运行全节点

在前面的目录下，输入如下命令运行节点：

```
# 更新镜像
sudo docker-compose pull

# 运行节点
sudo docker-compose up -d
```

查看节点运行状态：

```
sudo docker ps -a 
```

![node container running](/files/BmEphmeJ0arO5tZfLD4R)

## 5. 检查节点

{% hint style="info" %}
确保节点是运行中，否则执行下面的命令会出错！
{% endhint %}

### 5.1 查看 Peer ID

```
curl 127.0.0.1:9101/metrics 2> /dev/null | grep -m 1 peer_id
```

### 5.2 查看同步状态

```
curl 127.0.0.1:9101/metrics 2> /dev/null | grep aptos_state_sync_version
```

Aptos 网络看板：[https://status.devnet.aptos.dev](https://status.devnet.aptos.dev/)

社区提供的检查节点状态网址：

* [https://aptos-node.info](https://aptos-node.info/)

## 6. 节点更新

{% hint style="info" %}
本节仅用于每周五的节点更新使用。
{% endhint %}

### 6.1 关闭节点

执行如下命令：

```shell
# 进入之前创建的 aptos-node 目录，之后的操作都会在该目录下进行
cd ~/aptos-node
# 关闭节点
sudo docker-compose down
```

![](/files/7kpELXJTMOqzhEDVOpjP)

### 6.2 删除数据文件

执行如下命令：

```shell
# 查看数据卷
sudo docker volume ls

# 删除数据卷（以上一条命令查询到的 Volume Name 结果为准）
sudo docker volume rm aptos-node_db
```

![](/files/PFUe2xh7umm81uZhlgca)

### 6.3 删除 `genesis.blob` 和 `waypoint.txt` 文件并重新下载

执行如下命令即可下载并覆盖原文件：

```shell
# 下载 创世节点文件
wget -O ./genesis.blob https://devnet.aptoslabs.com/genesis.blob
# 下载 waypoint（可验证检查点）文件
wget -O ./waypoint.txt https://devnet.aptoslabs.com/waypoint.txt
```

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

* 2022年6月10日更新：<mark style="color:red;">本周必须更新</mark><mark style="color:red;">`public_full`</mark><mark style="color:red;">\_</mark><mark style="color:red;">`node.yaml`</mark> <mark style="color:red;"></mark><mark style="color:red;">文件</mark>。
  {% endhint %}

### 6.4 更新节点镜像

运行如下命令：

```shell
sudo docker-compose pull
```

![](/files/SCD6sc9vLEEn8DpwwKm8)

### 6.5 启动全节点

在上面的命令行界面中运行如下命令：

```shell
sudo docker-compose up -d
```

![](/files/nkRtnNloYe5EjnC2VRyp)


---

# 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://wiki.aptos.movemove.org/jiao-cheng/kai-fa-wang-devnet/yun-xing-quan-jie-dian-she-qu-jiao-cheng/linux.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.
