Skip to content
云间札记
Go back

以太坊主网自建节点部署:Geth 执行客户端 + Prysm 共识客户端

Updated:

背景

为支持 OP Stack L2 Rollup 的 L1 依赖,需要自建以太坊主网全节点,提供稳定的 JSON-RPC 和 Beacon API 服务。

服务器配置

主机配置系统业务
prod-eth-node-10-169-21-218c/32g/100g/1500gUbuntu 22.04自建 ETH 节点

依赖安装

# 基础工具
apt install -y git golang jq

# Go 1.21.3
wget -O /usr/local/src/go1.21.3.linux-amd64.tar.gz   https://studygolang.com/dl/golang/go1.21.3.linux-amd64.tar.gz
cd /usr/local/src/
tar -C /usr/local -xzf go1.21.3.linux-amd64.tar.gz

cat >> /root/.bashrc <<'EOF'
export PATH=$PATH:/usr/local/go/bin
export GO111MODULE=on
export GOPROXY=https://goproxy.cn
EOF
source ~/.bashrc

# 验证
go version
# go version go1.21.3 linux/amd64

Geth 执行客户端

编译安装

mkdir -pv /data/github
cd /data/github
git clone https://github.com/ethereum/go-ethereum.git

cd /data/github/go-ethereum
make geth

# 输出到 build/bin/
cd /data/github/go-ethereum/build/bin
./geth version

数据目录准备

# 1500G 数据盘挂载到 /data
mkdir -pv /data/ethereum/{execution/bin,ethdata,conf,logs}

# 复制二进制
cp /data/github/go-ethereum/build/bin/geth /data/ethereum/execution/bin/

Prysm 共识客户端

安装

mkdir -pv /data/prysm
cd /data/prysm

# 下载安装脚本
curl https://raw.githubusercontent.com/prysmaticlabs/prysm/master/prysm.sh   --output prysm.sh && chmod +x prysm.sh

# 生成 JWT 认证密钥(执行客户端与共识客户端共用)
./prysm.sh beacon-chain generate-auth-secret

复制 JWT 到配置目录

mkdir -pv /data/ethereum/conf
cp /data/prysm/jwt.hex /data/ethereum/conf/

Supervisor 守护进程配置

Geth 执行客户端

cat > /etc/supervisor/conf.d/geth.conf <<'EOF'
[program:geth]
process_name=%(program_name)s
command=/data/ethereum/execution/bin/geth   --mainnet   --datadir /data/ethereum/ethdata   --authrpc.jwtsecret /data/ethereum/conf/jwt.hex   --http   --http.api eth,net,web3   --http.addr 0.0.0.0   --http.vhosts '*'
directory=/data/ethereum/execution/
user=root
stopsignal=Kill
autostart=true
autorestart=true
redirect_stderr=true
startsecs=3
startretries=3
stdout_logfile_maxbytes=50MB
stdout_logfile_backups=10
stdout_logfile=/data/ethereum/logs/geth.log
EOF

关键参数说明:

参数说明
--mainnet连接主网-
--datadir数据目录/data/ethereum/ethdata
--authrpc.jwtsecretJWT 认证密钥路径/data/ethereum/conf/jwt.hex
--http启用 HTTP-RPC-
--http.api开放 APIeth,net,web3
--http.addr监听地址0.0.0.0
--http.vhosts允许访问的域名* (所有)

Prysm 共识客户端

cat > /etc/supervisor/conf.d/beacon-chain.conf <<'EOF'
[program:beacon-chain]
process_name=%(program_name)s
command=/data/ethereum/consensus/bin/beacon-chain   --accept-terms-of-use   --datadir /data/ethereum/ethdata   --checkpoint-sync-url=https://sync.invis.tools   --genesis-beacon-api-url=https://sync.invis.tools   --execution-endpoint=http://localhost:8551   --rpc-host=0.0.0.0   --grpc-gateway-host=0.0.0.0   --jwt-secret=/data/ethereum/conf/jwt.hex
directory=/data/ethereum/consensus/
user=root
stopsignal=Kill
autostart=true
autorestart=true
redirect_stderr=true
startsecs=3
startretries=3
stdout_logfile_maxbytes=50MB
stdout_logfile_backups=10
stdout_logfile=/data/ethereum/logs/beacon-chain.log
EOF

关键参数说明:

参数说明
--accept-terms-of-use同意使用条款(后台启动必需)-
--datadir数据目录/data/ethereum/ethdata
--checkpoint-sync-url检查点同步 URLhttps://sync.invis.tools
--execution-endpoint执行客户端地址http://localhost:8551
--jwt-secretJWT 密钥路径/data/ethereum/conf/jwt.hex

启动与验证

# 重载 Supervisor 配置
supervisorctl reread
supervisorctl update

# 启动服务
supervisorctl start geth
supervisorctl start beacon-chain

# 查看状态
supervisorctl status

共识客户端同步验证

curl http://localhost:3500/eth/v1/node/syncing

同步中:

{"data":{"head_slot":"8516480","sync_distance":"162","is_syncing":true,"is_optimistic":false,"el_offline":true}}

同步完成:

{"data":{"head_slot":"7529920","sync_distance":"0","is_syncing":false,"is_optimistic":true,"el_offline":true}}

执行客户端同步验证

方法1:Console

/data/ethereum/execution/bin/geth attach /data/ethereum/ethdata/geth.ipc
> eth.syncing
# 返回对象表示同步中,返回 false 表示同步完成

方法2:RPC 调用

curl -H "Content-Type: application/json" -X POST   --data '{"jsonrpc":"2.0","method":"eth_syncing","params":[],"id":1}'   http://localhost:8545
# 返回对象表示同步中,返回 false 表示同步完成

磁盘与性能

指标配置备注
数据盘1500G主网全节点约 1.2TB+
内存32GGeth 缓存默认 4GB
CPU8c同步阶段 CPU 密集型
网络100Mbps+初始同步需要高带宽

复盘

问题根因:初始使用默认 --cache 配置,容器内存不足导致 OOM

解决:显式设置 --cache 4096,预留足够内存给 Prysm

改进措施

本文首发于 wr.mrchi.cn,转载请注明出处。



Previous Post
Blockscout L2 浏览器部署:OP Stack 链上数据可视化
Next Post
OP Stack L2 测试网分叉处理:数据同步与流量切换实战