Eth节点部署
在ubuntu22.04上部署Eth区块链。需要两种客户端,即执行层 (EL) 客户端和共识层 (CL) 客户端。
Docker环境下安装与配置以太坊节点指南
节点类型 | 定义 | 数据存储特点 | 适用场景 | 存储占用 | 注意事项 |
---|---|---|---|---|---|
归档节点(Archive Node) | 具有从创世区块开始的所有历史数据,可查询和追踪每一个历史区块的状态 | 存储全部历史数据 | 需要查询历史区块状态的场景 | 占用2.14TB | 首次运行节点时选择的类型不能在初始同步后更改 |
修剪节点(Pruned Node) | 历史数据部分或完全被修剪,具体取决于用户自定义配置 | 存储的数据量较少 | 只需要最新状态数据的应用场景 | 占用1.5TB | 不支持转换为全节点或归档节点 |
全节点(Full Node) | 仅保留最新状态和最近10064个区块的历史数据,可像归档节点一样进行查询 | 存储最新状态和近10064个区块的历史数据 | 需要查询近期区块数据和最新状态的场景 | 占用1.13TB | 不支持转换为归档节点或修剪节点 |
一、Docker安装步骤
- 获取Docker安装脚本
curl -fsSL https://get.docker.com -o get-docker.sh
- 执行安装脚本
bash ./get-docker.sh
二、执行客户端(Nethermind)配置
1. 版本选择与拉取
从Docker Hub获取指定版本的Nethermind镜像:
docker pull nethermind/nethermind:1.31.11-chiseled
2. 数据目录准备
sudo mkdir -p /data/nethermind/db /data/nethermind/keystore /data/nethermind/logscd /data/nethermind/dbsudo wget https://raw.githubusercontent.com/NethermindEth/nethermind/refs/heads/master/src/Nethermind/Nethermind.Runner/configs/mainnet.jsonchown -R 1654:1654 /data/nethermind/
3. 容器启动命令
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. 监控命令
curl -s localhost:8545/health|jq
6. 端口映射
端口 | 协议 | 用途 |
---|---|---|
8545 | TCP | JSON-RPC接口 |
8551 | TCP | 共识客户端通信接口 |
30303 | TCP+UDP | P2P网络通信 |
三、共识客户端(Lighthouse)配置
1. 版本选择与拉取
sudo docker pull sigp/lighthouse:v7.0.1
2. 容器启动命令
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-jwt | JWT认证文件路径 |
--checkpoint-sync-url | 检查点同步服务地址 |
--http --http-address 0.0.0.0 | 启用HTTP API服务 |
4. 监控命令
curl -s -X GET "http://localhost:5052/lighthouse/syncing" -H "accept: application/json" | jqcurl -s -X GET "http://localhost:5052/lighthouse/eth1/syncing" -H "accept: application/json" | jqcurl -s "http://localhost:5052/lighthouse/database/info" | jq
四、配置注意事项
- 数据目录权限:确保容器内用户(UID 1654)对挂载目录有读写权限
- JWT密钥:执行客户端与共识客户端需共享相同的JWT密钥文件
- 防火墙设置:开放必要端口以确保节点间通信正常
- 存储规划:根据节点类型(归档/全量/修剪)预留足够存储空间
查看同步
sudo add-apt-repository ppa:ethereum/ethereumsudo apt updateapt install ethereum -ygeth attach http://127.0.0.1:8545eth.syncingeth.blockNumberexit
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/Caddyfileeth-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