9

ETH 以太坊RPC节点部署搭建说明-mainnet(开发用,替代infura,非挖矿)

 2 years ago
source link: http://www.blogjava.net/fangw/archive/2021/11/14/436045.html
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
neoserver,ios ssh client

ETH 以太坊RPC节点部署搭建说明-mainnet(开发用,替代infura,非挖矿)

方伟的博客 j2ee技术、网络、web等,同名的人真多,我的QQ是20025404

posts - 20,comments - 14,trackbacks - 0

1.服务器

需要1T SSD(建议NVMe)硬盘,最好是裸硬盘,不可以用机械盘,否则会永远无法同步完成。

建议国外服务器,100M非cn2线路即可

3.操作系统

建议centos7/8,或ubuntu,这里均以centos为例

4.准备环境:

yum update -y

yum install screen iftop iotop -y

4.1.安装golang

yum install golang -y

或编译安装

*注意:如果使用的 Go 版本是 1.13 及以上 (推荐),如果不设置以下命令编译ETH源码时可能会出错
go env -w GO111MODULE=on
go env -w GOPROXY=https://goproxy.io,direct

5.创建一个screen

screen -S eth

*注意1:最后退出时用ctrl+ad(顺序按a和d字母即可),不要用exit或ctrl+d退出会话。

*注意2:退出会话后,可以用screen -x eth重新连接到会话。

6.安装eth客户端

#这里我的数据目录,可以根据需要自行更改

mkdir -p /data/eth/data

#下载最新版本并编译

cd /root
wget -O go-ethereum-1.10.12.tar.gz https://github.com/ethereum/go-ethereum/archive/refs/tags/v1.10.12.tar.gz
tar -xvf go-ethereum-1.10.12.tar.gz
cd /root/go-ethereum-1.10.12
make all

7.检查安装是否成功

/root/go-ethereum-1.10.12/build/bin/geth version

8.设置防火墙
firewall-cmd --permanent --zone=public --add-port=30303/tcp
firewall-cmd --permanent --zone=public --add-port=8545/tcp
firewall-cmd --reload
不懂防火墙配置的,可以先禁用防火墙,关于firewalld的使用技巧,之后会单独写一篇教程

9.启动节点

ulimit -n 65535

/root/go-ethereum-1.10.12/build/bin/geth --datadir /data/eth/data --syncmode "fast" --cache=2048 --maxpeers 200 --http --http.addr=0.0.0.0 --http.port=8545 --http.api "web3,eth,debug,personal,net,admin" --http.corsdomain "*" --allow-insecure-unlock

*然后按ctrl+ad回到主会话即可

10.测试验证

curl -H "Content-Type: application/json" -X POST --data '{"jsonrpc":"2.0","method":"eth_syncing","params":[],"id":1}' http://127.0.0.1:8545

(如果已经追上最新高度,result会返回false,这样以后就不用受infura调用频率的限制了)

curl -H "Content-Type: application/json" -X POST --data '{"jsonrpc":"2.0","method":"eth_blockNumber","params":[],"id":1}' http://127.0.0.1:8545

(节点未同步完成会返回0)

11.停止节点

方式1:(建议,毕竟停止后还要启动不是)

screen -r eth

按ctrl+c,等待一会即可看到节点停止

12.接口文档参考

RPC接口文档,如:

以太坊JSON RPC手册 / eth_call - 汇智网

其它参考:

ETH链github地址:https://github.com/ethereum/go-ethereum

主网浏览器:https://etherscan.io

13.注意事项

*同步到最高区块所需时间:

需要看网络带宽和磁盘io性能,用NVMe的硬盘,读写1000到2000左右,100M的国外非cn2带宽,从0开始同步,大概需要半天到一天。

*如果2、3天还没有追上,或者最后100个块始终追不上,极有可能是服务器磁盘io存在瓶颈,再次强调,不可以用机械盘,不建议用虚拟机(磁盘不能做虚拟化),否则io速度不够,就永远无法同步完成,因为最后还有一步需要很高的IO速度才可以完成。

*硬盘最好1T空间,目前实际会占用584G左右。

posted on 2021-11-14 23:36 方伟的博客 阅读(3) 评论(0)  编辑  收藏 所属分类: 区块链

About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK