Skip to content

Eth节点部署

在ubuntu22.04上部署Eth区块链。需要两种客户端,即执行层 (EL) 客户端和共识层 (CL) 客户端。

Docker环境下安装与配置以太坊节点指南

节点类型定义数据存储特点适用场景存储占用注意事项
归档节点(Archive Node)具有从创世区块开始的所有历史数据,可查询和追踪每一个历史区块的状态存储全部历史数据需要查询历史区块状态的场景占用2.14TB首次运行节点时选择的类型不能在初始同步后更改
修剪节点(Pruned Node)历史数据部分或完全被修剪,具体取决于用户自定义配置存储的数据量较少只需要最新状态数据的应用场景占用1.5TB不支持转换为全节点或归档节点
全节点(Full Node)仅保留最新状态和最近10064个区块的历史数据,可像归档节点一样进行查询存储最新状态和近10064个区块的历史数据需要查询近期区块数据和最新状态的场景占用1.13TB不支持转换为归档节点或修剪节点

一、Docker安装步骤

  1. 获取Docker安装脚本
Terminal window
curl -fsSL https://get.docker.com -o get-docker.sh
  1. 执行安装脚本
Terminal window
bash ./get-docker.sh

二、执行客户端(Nethermind)配置

1. 版本选择与拉取

从Docker Hub获取指定版本的Nethermind镜像:

Terminal window
docker pull nethermind/nethermind:1.31.11-chiseled

2. 数据目录准备

Terminal window
sudo mkdir -p /data/nethermind/db /data/nethermind/keystore /data/nethermind/logs
cd /data/nethermind/db
sudo wget https://raw.githubusercontent.com/NethermindEth/nethermind/refs/heads/master/src/Nethermind/Nethermind.Runner/configs/mainnet.json
chown -R 1654:1654 /data/nethermind/

3. 容器启动命令

Terminal window
sudo docker run -d --name nethermind --network host \
-v /data/nethermind/db:/nethermind/nethermind_db \
-v /data/nethermind/logs:/nethermind/logs \
-v /data/nethermind/keystore:/nethermind/keystore \
nethermind/nethermind:1.31.11-chiseled -c mainnet --healthchecks-enabled true --jsonrpc-enginehost 0.0.0.0

4. 关键参数说明

参数功能描述
--healthchecks-enabled true启用健康检查接口
--jsonrpc-enginehost 0.0.0.0开放引擎API服务

5. 监控命令

Terminal window
curl -s localhost:8545/health|jq

6. 端口映射

端口协议用途
8545TCPJSON-RPC接口
8551TCP共识客户端通信接口
30303TCP+UDPP2P网络通信

三、共识客户端(Lighthouse)配置

1. 版本选择与拉取

Terminal window
sudo docker pull sigp/lighthouse:v7.0.1

2. 容器启动命令

Terminal window
sudo docker run -d --name lighthouse --network host \
-v /data/lighthouse:/root/.lighthouse \
-v /data/nethermind/keystore:/root/keystore \
sigp/lighthouse:v7.0.1 \
lighthouse bn --network mainnet --execution-endpoint http://localhost:8551 \
--execution-jwt /root/keystore/jwt-secret --checkpoint-sync-url https://mainnet.checkpoint.sigp.io \
--http --http-address 0.0.0.0

3. 关键参数说明

参数功能描述
--execution-endpoint指定执行客户端的连接地址
--execution-jwtJWT认证文件路径
--checkpoint-sync-url检查点同步服务地址
--http --http-address 0.0.0.0启用HTTP API服务

4. 监控命令

Terminal window
curl -s -X GET "http://localhost:5052/lighthouse/syncing" -H "accept: application/json" | jq
curl -s -X GET "http://localhost:5052/lighthouse/eth1/syncing" -H "accept: application/json" | jq
curl -s "http://localhost:5052/lighthouse/database/info" | jq

四、配置注意事项

  1. 数据目录权限:确保容器内用户(UID 1654)对挂载目录有读写权限
  2. JWT密钥:执行客户端与共识客户端需共享相同的JWT密钥文件
  3. 防火墙设置:开放必要端口以确保节点间通信正常
  4. 存储规划:根据节点类型(归档/全量/修剪)预留足够存储空间

查看同步

sudo add-apt-repository ppa:ethereum/ethereum
sudo apt update
apt install ethereum -y
geth attach http://127.0.0.1:8545
eth.syncing
eth.blockNumber
exit
echo $(($(curl -s -d '{"id":0,"jsonrpc":"2.0","method":"eth_getBlockByNumber","params":["latest",false]}' \
-H "Content-Type: application/json" https://eth-rpc.gaojinbo.com/fa33401ffb204164c2d15c5e52ce8035/|jq .result.number|awk -F'"' '{print $2}')))
echo $(($(curl -s -d '{"id":0,"jsonrpc":"2.0","method":"eth_getBlockByNumber","params":["latest",false]}' \
-H "Content-Type: application/json" http://localhost:8545|jq .result.number|awk -F'"' '{print $2}')))

caddy代理(推荐)自动更新SSL证书

apt install caddy -y
vi /etc/caddy/Caddyfile
eth-rpc.gaojinbo.com {
reverse_proxy http://127.0.0.1:8545 {
header_up Host localhost
}
}
beacon-rpc.gaojinbo.com {
reverse_proxy http://127.0.0.1:5052 {
header_up Host localhost
}
}
systemctl restart caddy

nginx代理

server {
listen 443 ssl;
server_name eth-rpc.gaojinbo.com;
keepalive_timeout 70;
ssl_certificate ssl/new/eth-rpc.gaojinbo.com.pem;
ssl_certificate_key ssl/new/eth-rpc.gaojinbo.com.key;
ssl_protocols TLSv1 TLSv1.1 TLSv1.2 TLSv1.3;
ssl_ciphers HIGH:!aNULL:!MD5;
#location / {
location ^~/fa33401ffb204164c2d15c5e52ce8035/ {
proxy_redirect off;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header Host $host;
#以下代码使支持WebSocket
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
proxy_pass http://52.76.65.24:8545/;
}
location / {
return 404;
}
location /123 {
return 200;
}
}

TOP