EOS主網節點部署

EOS主網節點部署

#環境 ubuntu 16.4
EOS編譯安裝
EOS主網節點部署
eos區塊查詢、進程監控shellnode

#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
git

#爲加快同步速度,添加一些物理距離近的同步節點
#當前的網絡p2p-peer-address 地址能夠從下面地址得到
# https://eosnodes.privex.io/?config=1github

#同步節點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.mdmongodb

相關文章
相關標籤/搜索