Welcome to Elvin's blog

EOS主网节点部署

EOS主网节点部署

环境 ubuntu 16.4
EOS编译安装
EOS主网节点部署
eos区块查询、进程监控shell

#EOS编译安装

#环境 ubuntu 16.4 
# EOS安装部
# 以下代码保存为install.eos.sh文件
# 执行 sudo bash install.eos.sh

#!/bin/bash
#install.eos.sh
# By Elven,2018-11-9
#EOS 安装

#从github克隆主网代码
cd /opt
git clone https://github.com/EOS-Mainnet/eos.git --recursive

#查看mainnet ,切换最新版本
cd /opt/eos
git tag
git tag |grep mainnet |tail -n 1
git checkout `git tag |grep mainnet |tail -n 1`
git branch

#更新子模块
git submodule update --init --recursive

#查询得shell脚本里的MongoDB下载地址失效,修改如下
sed -i 's#https://fastdl.mongodb.org#http://downloads.mongodb.org#'  scripts/*.sh

#运行编译
./eosio_build.sh -s "EOS"

#编译完成后,安装
./eosio_install.sh

#eos加入主网并启动

#下载节点配置
#主要用到genesis.json和config.ini
#主网创世区块文件genesis.json
#默认配置config.ini

#download and  Configuring
mkdir /opt/EOSmainNet
cd /opt/EOSmainNet
git clone https://github.com/CryptoLions/EOS-MainNet.git ./ 
chmod +x ./*.sh   
chmod +x ./Wallet/*.sh 

#设置当前用户ubuntu权限(可选)
sudo chown ubuntu:ubuntu -R /opt/EOSmainNet

#修改区块储存限制(已超过默认存储大小)
sudo sed -i 's/chain-state-db-size-mb =.*/chain-state-db-size-mb = 1024000/'  /opt/EOSmainNet/config.ini

#更换nodeos编译路径
sudo sed -i 's#/home/eos-sources/eos#/opt/eos#' *.sh

#首次启动,清除现有区块并加入主网
sudo /opt/EOSmainNet/start.sh --genesis-json /opt/EOSmainNet/genesis.json --delete-all-blocks

#再次启动,不需指定genesis.json
sudo /opt/EOSmainNet/start.sh
 #关闭 sudo /opt/EOSmainNet/stop.sh

#基本查询

#查看区块同步
sudo /opt/EOSmainNet/cleos.sh get info

#查看区块高度
/opt/EOSmainNet/cleos.sh get info |awk -F'[ |,]' '/head_block_num/{print $4}'

#curl 访问rpc api查看区块
#sudo apt install jq #格式化josn文件
#查看区块同步
[ -f /usr/bin/jq ] || { sudo apt updata;sudo apt install jq; }
curl -s  http://127.0.0.1:8888/v1/chain/get_info |jq

#获取区块高度
curl -s  http://localhost:8888/v1/chain/get_info |awk -F'[,:]*' '{print $6}'

#查看日志
tailf /opt/EOSmainNet/stderr.txt

nodeos进程异常关闭,再次启动要区块回放--replay-blockchain很耗时间
eos不适合docker方式部署,eosio/eos镜像停止维护
通过备份文件重放区块中信息,区块超过3千万后区块回放很慢,不如直接同步
区块备份文件下载(个人实测后不推荐) https://eosnode.tools/blocks

为加快同步速度,添加一些物理距离近的同步节点
当前的网络p2p-peer-address 地址可以从下面地址获得
https://eosnodes.privex.io/?config=1

#同步节点p2p-peer-address不可用时,会一直报错,最好注释掉

#var
EosLog=/opt/EOSmainNet/stderr.txt
Config=/opt/EOSmainNet/config.ini

# 注释掉不可用的 p2p-peer-address
#Connection refused
List=`awk -F '[ :]*' '/Connection refused/{print $(NF-3)}'  $EosLog |sort -u`
for N in $List; do sed -i "s/^p2p-peer.*${N}/#&/"  $Config ; done
#Host not found
List=`awk -F '[ :]*' '/Host not found/{print $(NF-5)}'  $EosLog |sort -u`
for N in $List; do sed -i "s/^p2p-peer.*${N}/#&/"  $Config ; done

# 重启EOS
sudo /opt/EOSmainNet/start.sh

#查看eos区块同步速度,监控并重启,shell

#!/bin/bash
#check.eos.sh
# By Elven , 2018-11-18

#eos check and restart
#*/3 * * * * bash /opt/shell/check.eos.sh 1 60 s

#var
Nu=${Nu:-1}
Time=${Time:-10}
[[ $1 -ge 1 ]] && { Nu=$1 ; }
[[ $2 -ge 1 ]] && { Time=$2 ; }
Start=/opt/EOSmainNet/start.sh

CHECK() {
eos_block=`curl -s  http://localhost:8888/v1/chain/get_info |awk -F'[,:]*' '{print $6}'`
}

Restart() {
CHECK
Block1=$eos_block
sleep $Time
CHECK
Block2=$eos_block
[ $Block2 -gt $Block1 ] || { echo "restart eos at $(date +%F" "%T) $Block2" >>/tmp/eos.restart.log;$Start; }
}

if [[ $3 == "s" ]];then
    Restart
elif [ $Nu -gt 1 ];then
    for((i=1;i<=$1;i++));do
        CHECK
        echo "eosblock  $eos_block"
        [ $i -lt $1 ] && { echo "wait $Time s";sleep $Time ; }
    done
else
    CHECK
    echo "eosblock  $eos_block"
fi

EOS区块链浏览器
https://eospark.com
EOS中文白皮书
https://github.com/EOSIO/Documentation/blob/master/zh-CN/TechnicalWhitePaper.md

posted @ 2019-01-01 20:25  blog-elvin-vip  阅读(2999)  评论(1编辑  收藏  举报