1.服務器
需要1T SSD(建議NVMe)硬盤,最好是裸硬盤,不可以用機械盤,否則會永遠無法同步完成。
2.帶寬
建議國外服務器,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左右。