部署以太坊全节点教程系列之一:运行全节点

本系列将系统介绍如何在谷歌云服务器上部署以太坊节点。

在以太坊完成合并之后,原来的以太坊eth1只负责执行,而共识层则由信标链(beacon chain)完成。

部署以太坊节点需要完成3个步骤:

  1. 运行执行层客户端,可以选择Geth,Nethermind,Besu 等

  2. 运行共识层客户端,可以选择Prysm, Lighthouse, Teku 等

  3. 运行验证节点(下一篇文章会进行分享)

以太坊节点的部署总览可以参考下面这张图(来自Somer Esat的medium):

post image

步骤一:

运行节点的硬件要求
运行节点的硬件要求

本文将以运行CentOS 8的Linux系统为例,使用Geth作为执行层客户端,Prysm作为共识层客户端进行演示。主要原因是它们都是各自使用最多的客户端程序(下图),意味着相关文档和话题也最多。

post image

步骤二:安装Prysm

在/home/master目录下创建ethereum文件夹,以及consensus和execution两个子文件夹。

前往consensus文件夹并运行以下命令下载Prysm客户端:

mkdir prysm && cd prysm
curl https://raw.githubusercontent.com/prysmaticlabs/prysm/master/prysm.sh --output prysm.sh && chmod +x prysm.sh

使用客户端创建jwt token。jwt token将用来帮助验证共识层和执行层的客户端的数据交互。

./prysm.sh beacon-chain generate-auth-secret

将生成的jwt.hex文件放在consensus文件目录下。

步骤三:运行执行层客户端

安装geth:

  1. 通过以下命令更新服务器

    yum update
    
  2. 前往下面的网址查找最新的linux版本geth安装包

    https://geth.ethereum.org/downloads/,截至2022年10月10日,最新的安装包地址为:

    https://gethstore.blob.core.windows.net/builds/geth-linux-amd64-1.10.25-69568c55.tar.gz

  3. 前往ethereum/execution/目录,使用wget 命令下载geth安装包

wget https://gethstore.blob.core.windows.net/builds/geth-linux-amd64-1.10.25-69568c55.tar.gz

4. 使用tar -xvf 解压缩

tar -xvf geth-linux-amd64-1.10.25-69568c55.tar.gz

5. 将文件移至 /usr/bin 目录下,从而令全系统都可以使用geth命令

cp geth-linux-amd64-1.10.25-69568c55/geth /usr/bin/

6. 检查版本

此时,运行以下命令,令执行层节点在goerli测试网上的运行:

geth --goerli --http --http.api eth,net,engine,admin --authrpc.jwtsecret /home/master/ethereum/consensus/jwt.hex 

至此,执行层的客户端安装已经完成。

步骤四:使用Prysm运行共识层节点

  1. 将goerli测试网的原始状态数据下载到 /ethereum/consensus/prysm 目录下

wget https://github.com/eth-clients/eth2-networks/raw/master/shared/prater/genesis.ssz

2. 运行Prysm启动共识层客户端

./prysm.sh beacon-chain --execution-endpoint=http://localhost:8551 --prater --jwt-secret=/home/master/ethereum/consensus/jwt.hex --genesis-state=genesis.ssz

为了保证程序在窗口关闭后仍能保持运行,这里使用nohup,并将log存入/ethereum/log目录下:

nohup geth --goerli --http --http.api eth,net,engine,admin --authrpc.jwtsecret /home/master/ethereum/consensus/jwt.hex > /home/master/ethereum/log/geth.txt 2>&1 &

nohup ./prysm.sh beacon-chain --execution-endpoint=http://localhost:8551 --prater --jwt-secret=/home/master/ethereum/consensus/jwt.hex --genesis-state=genesis.ssz > /home/master/ethereum/log/prysm.txt  2>&1 &

恭喜,你已经完成了以太坊全节点的部署和运行,同步到beacon chain的区块需要大概2天时间。

参考资料:

  1. Prysm教程

https://docs.prylabs.network/docs/install/install-with-script

2. 安装geth

https://www.cyberithub.com/how-to-install-geth-go-ethereum-on-rhel-centos-and-rocky-linux/