以太坊主网 PoS 节点搭建指南

发布于:2025-03-29 ⋅ 阅读:(70) ⋅ 点赞:(0)

以太坊主网 PoS 节点搭建指南

1. 以太坊节点架构概述

自从以太坊在2022年9月完成"合并"(The Merge)升级后,以太坊网络已从工作量证明(PoW)转变为权益证明(PoS)共识机制。现代以太坊节点由两个主要层组成:

1.1 执行层 (Execution Layer)

  • 负责处理交易、执行智能合约、维护状态
  • 原来的以太坊1.0客户端,如Geth、Nethermind、Besu、Erigon等
  • 管理以太坊虚拟机(EVM)

1.2 共识层 (Consensus Layer)

  • 负责区块生成、验证和网络共识
  • 原来的以太坊2.0信标链客户端,如Lighthouse、Prysm、Nimbus、Teku等
  • 实现权益证明(PoS)机制

这两层需要通过引擎API进行通信,共同维护以太坊网络。

2. 节点类型

2.1 全节点

  • 存储完整的区块链数据
  • 验证所有交易和区块
  • 不参与区块生成
  • 不需要质押ETH

2.2 验证者节点

  • 全节点的所有功能
  • 参与区块生成和验证
  • 需要质押32 ETH
  • 获得质押奖励

2.3 归档节点

  • 存储完整的历史状态
  • 占用更多存储空间
  • 可以查询任何历史状态

3. 硬件要求

3.1 全节点最低配置

  • CPU: 4核心 / 8线程
  • 内存: 16GB RAM
  • 存储: 2TB SSD (NVMe SSD推荐)
  • 网络: 稳定的互联网连接,至少25Mbps上传/下载速度

3.2 验证者节点推荐配置

  • CPU: 8核心 / 16线程
  • 内存: 32GB RAM
  • 存储: 4TB NVMe SSD
  • 网络: 100Mbps以上的稳定连接
  • 电源: UPS备份电源

4. 软件准备

4.1 操作系统

推荐使用Ubuntu 22.04 LTS或更高版本。

4.2 系统更新与基础软件安装

sudo apt update && sudo apt upgrade -y
sudo apt install -y build-essential git curl software-properties-common

5. 执行层客户端安装

以太坊有多种执行层客户端可供选择,以下是几种主流客户端:

5.1 客户端对比

客户端 语言 资源占用 同步速度 特点
Geth Go 中等 最流行,稳定
Nethermind C# 较高 较快 功能丰富
Besu Java 较高 中等 企业级
Erigon Go 较低 非常快 高效存储

5.2 安装Geth (Go Ethereum)

5.2.1 安装Geth
sudo add-apt-repository -y ppa:ethereum/ethereum
sudo apt update
sudo apt install -y geth
5.2.2 创建服务账户
sudo useradd --no-create-home --shell /bin/false geth
sudo mkdir -p /var/lib/geth
sudo chown -R geth:geth /var/lib/geth
5.2.3 创建JWT密钥

执行层和共识层之间需要JWT密钥进行安全通信:

sudo mkdir -p /var/lib/ethereum
openssl rand -hex 32 | sudo tee /var/lib/ethereum/jwtsecret > /dev/null
sudo chmod 644 /var/lib/ethereum/jwtsecret
5.2.4 配置Geth服务

创建systemd服务文件:

sudo nano /etc/systemd/system/geth.service

添加以下内容:

[Unit]
Description=Go Ethereum Client
After=network.target
Wants=network.target

[Service]
User=geth
Group=geth
Type=simple
Restart=always
RestartSec=5
ExecStart=/usr/bin/geth \
    --mainnet \
    --http \
    --http.api eth,net,engine,admin \
    --http.addr 127.0.0.1 \
    --http.corsdomain "*" \
    --http.vhosts "*" \
    --authrpc.jwtsecret=/var/lib/ethereum/jwtsecret \
    --datadir /var/lib/geth \
    --metrics \
    --metrics.addr 127.0.0.1 \
    --metrics.port 6060

[Install]
WantedBy=default.target
5.2.5 启动Geth服务
sudo systemctl daemon-reload
sudo systemctl enable geth
sudo systemctl start geth
sudo systemctl status geth

6. 共识层客户端安装

以太坊有多种共识层客户端可供选择,以下是几种主流客户端:

6.1 客户端对比

客户端 语言 资源占用 特点
Lighthouse Rust 中等 高效,安全
Prysm Go 中等 用户友好
Nimbus Nim 轻量级
Teku Java 较高 企业级

6.2 安装Lighthouse

6.2.1 安装Rust和依赖
# 添加Rust
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh
source $HOME/.cargo/env

# 安装依赖
sudo apt install -y cmake pkg-config libssl-dev git gcc build-essential
6.2.2 编译Lighthouse
git clone https://github.com/sigp/lighthouse.git
cd lighthouse
git checkout stable
make
6.2.3 创建服务账户
sudo useradd --no-create-home --shell /bin/false lighthouse
sudo mkdir -p /var/lib/lighthouse
sudo chown -R lighthouse:lighthouse /var/lib/lighthouse
6.2.4 配置Lighthouse信标节点服务

创建systemd服务文件:

sudo nano /etc/systemd/system/lighthouse-beacon.service

添加以下内容:

[Unit]
Description=Lighthouse Ethereum Consensus Client Beacon Node
After=network.target
Wants=network.target

[Service]
User=lighthouse
Group=lighthouse
Type=simple
Restart=always
RestartSec=5
ExecStart=/path/to/lighthouse/target/release/lighthouse bn \
    --network mainnet \
    --datadir /var/lib/lighthouse \
    --http \
    --execution-endpoint http://127.0.0.1:8551 \
    --execution-jwt /var/lib/ethereum/jwtsecret \
    --checkpoint-sync-url https://mainnet.checkpoint.sigp.io \
    --metrics \
    --metrics-address 127.0.0.1 \
    --metrics-port 5054 \
    --port 9000 \
    --discovery-port 9000

[Install]
WantedBy=default.target
6.2.5 启动Lighthouse信标节点服务
sudo systemctl daemon-reload
sudo systemctl enable lighthouse-beacon
sudo systemctl start lighthouse-beacon
sudo systemctl status lighthouse-beacon

7. 验证者节点设置 (可选)

如果您想成为验证者并质押32 ETH,需要完成以下额外步骤:

7.1 生成验证者密钥

7.1.1 安装以太坊质押CLI
mkdir -p ~/staking-deposit-cli
cd ~/staking-deposit-cli
curl -LO https://github.com/ethereum/staking-deposit-cli/releases/download/v2.5.0/staking_deposit-cli-76ed782-linux-amd64.tar.gz
tar -xzf staking_deposit-cli-76ed782-linux-amd64.tar.gz
cd staking_deposit-cli-76ed782-linux-amd64
7.1.2 生成助记词和验证者密钥
./deposit new-mnemonic --num_validators 1 --chain mainnet

按照提示完成操作,保存好助记词和密码。这将生成两个重要文件:

  • deposit_data-*.json: 用于提交质押存款
  • validator_keys/: 包含验证者密钥

7.2 提交质押存款

  1. 访问官方质押启动板: https://launchpad.ethereum.org/
  2. 按照指引上传deposit_data-*.json文件
  3. 连接钱包并存入32 ETH

7.3 导入验证者密钥到Lighthouse

sudo mkdir -p /var/lib/lighthouse/validators
sudo chown -R lighthouse:lighthouse /var/lib/lighthouse/validators

# 导入验证者密钥
lighthouse account validator import \
  --network mainnet \
  --datadir /var/lib/lighthouse \
  --directory ~/staking-deposit-cli/validator_keys

7.4 配置验证者服务

创建systemd服务文件:

sudo nano /etc/systemd/system/lighthouse-validator.service

添加以下内容:

[Unit]
Description=Lighthouse Ethereum Consensus Client Validator
After=network.target lighthouse-beacon.service
Wants=network.target lighthouse-beacon.service

[Service]
User=lighthouse
Group=lighthouse
Type=simple
Restart=always
RestartSec=5
ExecStart=/path/to/lighthouse/target/release/lighthouse vc \
    --network mainnet \
    --datadir /var/lib/lighthouse \
    --beacon-node http://127.0.0.1:5052 \
    --graffiti "YOUR_GRAFFITI_HERE" \
    --metrics \
    --metrics-address 127.0.0.1 \
    --metrics-port 5064

[Install]
WantedBy=default.target

7.5 启动验证者服务

sudo systemctl daemon-reload
sudo systemctl enable lighthouse-validator
sudo systemctl start lighthouse-validator
sudo systemctl status lighthouse-validator

8. 节点监控设置

8.1 安装Prometheus和Grafana

# 安装Prometheus
sudo apt-get install -y prometheus

# 安装Grafana
sudo apt-get install -y apt-transport-https software-properties-common
wget -q -O - https://packages.grafana.com/gpg.key | sudo apt-key add -
echo "deb https://packages.grafana.com/oss/deb stable main" | sudo tee -a /etc/apt/sources.list.d/grafana.list
sudo apt-get update
sudo apt-get install -y grafana

8.2 配置Prometheus

sudo nano /etc/prometheus/prometheus.yml

添加以下内容:

global:
  scrape_interval: 15s

scrape_configs:
  - job_name: 'geth'
    static_configs:
      - targets: ['localhost:6060']
  
  - job_name: 'lighthouse_beacon'
    static_configs:
      - targets: ['localhost:5054']
  
  - job_name: 'lighthouse_validator'
    static_configs:
      - targets: ['localhost:5064']

8.3 启动监控服务

sudo systemctl restart prometheus
sudo systemctl enable prometheus
sudo systemctl restart grafana-server
sudo systemctl enable grafana-server

访问Grafana: http://your_server_ip:3000 (默认用户名/密码: admin/admin)

9. 节点维护

9.1 查看日志

# 查看Geth日志
sudo journalctl -fu geth

# 查看Lighthouse信标节点日志
sudo journalctl -fu lighthouse-beacon

# 查看Lighthouse验证者日志
sudo journalctl -fu lighthouse-validator

9.2 更新客户端

定期更新客户端以获取最新功能和安全补丁:

更新Geth
sudo apt update
sudo apt upgrade geth
sudo systemctl restart geth
更新Lighthouse
cd lighthouse
git fetch
git checkout stable
git pull
make
sudo systemctl restart lighthouse-beacon
sudo systemctl restart lighthouse-validator

9.3 备份重要数据

定期备份验证者密钥和助记词,存储在安全的离线位置。

10. 常见问题与解决方案

10.1 同步问题

  • 问题: 节点同步缓慢或停滞
  • 解决方案:
    • 检查网络连接
    • 确保SSD性能良好
    • 考虑使用快照同步: geth --syncmode snap

10.2 验证者未激活

  • 问题: 质押后验证者未显示激活
  • 解决方案: 验证者激活需要排队等待,可能需要几天到几周时间

10.3 系统资源不足

  • 问题: 系统内存或CPU使用率过高
  • 解决方案:
    • 增加系统资源
    • 调整客户端参数减少资源使用
    • 考虑使用资源占用更低的客户端

11. 资源链接

12. 安全注意事项

  • 使用强密码和SSH密钥
  • 配置防火墙,只开放必要端口
  • 定期更新系统和客户端
  • 备份验证者密钥和助记词
  • 考虑使用硬件安全模块(HSM)存储验证者密钥
  • 监控节点性能和安全

免责声明: 运行验证者节点需要持续在线,任何离线时间都可能导致惩罚。确保您的系统安全、稳定且有备份电源。质押32 ETH是一项长期承诺,请在开始前充分了解风险和责任。


网站公告

今日签到

点亮在社区的每一天
去签到