PlatON在CentOS上編譯部署

本文做者爲萬向區塊鏈CTO羅榮閣。


目錄

1. CentOS 環境準備
1.1. 使用rpm 安裝devtoolset-7
1.2. 使用rpm 安裝dos2unix
1.3. 準備PlatON代碼
1.4. 確保build腳本正常
1.5. 準備mpclib
1.6. 編譯PlatON
1.7. 從新編譯前的清理工做
2. 初始化和運行PlatON
2.1. PlatON節點初始化
2.1.1. 生成 account 和 key pair
2.1.2. 配置初始化文件
2.1.3. 初始化PlatON
2.2. 啓動 PlatON 節點
2.3. PlatON help 信息
2.4. 從新初始化PlatON節點
3. CentOS升級gcc原始步驟
3.1. 安裝CentOS-release-scl
3.2. 使用yum 安裝devtoolset-7
3.3. 編譯得到靜態庫libstdc++.so.6html


PlatON在CentOS上編譯部署

PlatON官網上主要支持在 Ubuntu 和 Windows 環境中編譯部署,可是也會有在CentOS上編譯部署的須要。本文主要介紹了在CentOS上的環境準備、編譯生成可執行文件和運行節點程序的過程。PlatON 官方代碼庫更新速度較快,有可能官方代碼作出了一些設置變化,若是有步驟不能正確執行,能夠參考 PlatON 官網具體信息。node


1. CentOS 環境準備

Ubuntu在社區中很流行,但CentOS在企業級市場中佔有較大優點。目前,CentOS在AWS、阿里雲、UCloud 雲服務商中可以使用的最高官方版本是CentOS 7.5。linux

本文就在CentOS 7.5下編譯部署PlatON。c++


1.1. 使用rpm 安裝devtoolset-7

由於PlatON的WASM庫和MPC庫依賴,開發和編譯環境須要支持C++14。GCC 6.1版本以上是默認支持C++14。 https://www.gnu.org/software/gcc/projects/cxx-status.html#cxx14git

CentOS 7.5的默認GCC版本爲4.8.5,開發和編譯PlatON須要升級GCC。Redhat官方的升級方法是經過devtoolset。github

• 2018年1月,devtoolset 6 發佈。golang

• 2018年5月,CentOS 7.5 發佈。web

• 2018年9月,devtoolset 7 發佈。 編程

https://access.redhat.com/solutions/19458 http://mirror.centos.org/centos/7/sclo/x86_64/rh/devtoolset-7/ https://www.softwarecollections.org/en/scls/rhscl/devtoolset-7/json

考慮以上的發佈時間順序、相互具體版本要求,選擇在CentOS 7.5中安裝devtoolset 7。

將如下33個rpm拷貝到一個目錄中,再執行:

$ sudo rpm -ivh boost-date-time-1.53.0-27.el7.x86_64.rpm efivar-libs-31-4.el7.x86_64.rpm kernel-debug-devel-3.10.0-862.el7.x86_64.rpm libgfortran4-7.2.1-1.1.1.el7.x86_64.rpm libquadmath-4.8.5-28.el7.x86_64.rpm mokutil-12-1.el7.centos.x86_64.rpm scl-utils-20130529-18.el7_4.x86_64.rpm devtoolset-7-7.1-4.el7.x86_64.rpm devtoolset-7-binutils-2.28-11.el7.x86_64.rpm devtoolset-7-dwz-0.12-1.1.el7.x86_64.rpm devtoolset-7-dyninst-9.3.2-3.el7.x86_64.rpm devtoolset-7-elfutils-0.170-5.el7.x86_64.rpm devtoolset-7-elfutils-libelf-0.170-5.el7.x86_64.rpm devtoolset-7-elfutils-libs-0.170-5.el7.x86_64.rpm devtoolset-7-gcc-7.3.1-5.13.el7.x86_64.rpm devtoolset-7-gcc-c++-7.3.1-5.13.el7.x86_64.rpm devtoolset-7-gcc-gfortran-7.3.1-5.13.el7.x86_64.rpm devtoolset-7-gdb-8.0.1-36.el7.x86_64.rpm devtoolset-7-libquadmath-devel-7.3.1-5.13.el7.x86_64.rpm devtoolset-7-libstdc++-devel-7.3.1-5.13.el7.x86_64.rpm devtoolset-7-ltrace-0.7.91-2.el7.x86_64.rpm devtoolset-7-make-4.2.1-3.el7.x86_64.rpm devtoolset-7-memstomp-0.1.5-5.1.el7.x86_64.rpm devtoolset-7-oprofile-1.2.0-2.el7.1.x86_64.rpm devtoolset-7-perftools-7.1-4.el7.x86_64.rpm devtoolset-7-runtime-7.1-4.el7.x86_64.rpm devtoolset-7-strace-4.17-7.el7.x86_64.rpm devtoolset-7-systemtap-3.1-4s.el7.x86_64.rpm devtoolset-7-systemtap-client-3.1-4s.el7.x86_64.rpm devtoolset-7-systemtap-devel-3.1-4s.el7.x86_64.rpm devtoolset-7-systemtap-runtime-3.1-4s.el7.x86_64.rpm devtoolset-7-toolchain-7.1-4.el7.x86_64.rpm devtoolset-7-valgrind-3.13.0-11.el7.x86_64.rpm
複製代碼


1.2. 使用rpm 安裝dos2unix

$ sudo rpm -ivh dos2unix-6.0.3-7.el7.x86_64.rpm
複製代碼


1.3. 準備PlatON代碼

PlatON git倉庫代碼

$ go get github.com/PlatONnetwork/PlatON-Go
複製代碼

更新代碼

$ go get -u github.com/PlatONnetwork/PlatON-Go
複製代碼


1.4. 確保build腳本正常

$ cd build

$ dos2unix *.sh

$ chmod 755 *.sh複製代碼


1.5. 準備mpclib

下載地址 https://download.platon.network/mpclib.tar.gz

$ tar xf mpclib.tar.gz

$ mv mpclib $GOPATH/src/github.com/PlatONnetwork/PlatON-Go/
複製代碼


1.6. 編譯PlatON

每次進bash須要手動切換GCC版本到 7.3.1

$ scl enable devtoolset-7 bash
複製代碼

或者直接設置在環境配置中,這樣每次打開bash默認是GCC 7.3.1

$ vi ~/.bashrc

source scl_source enable devtoolset-7
複製代碼

添加mpclib中的依賴包

$ export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:$GOPATH/src/github.com/PlatONnetwork/PlatON-Go/mpclib

$ echo $LD_LIBRARY_PATH

/opt/rh/devtoolset-7/root/usr/lib64:/opt/rh/devtoolset-7/root/usr/lib:/opt/rh/devtoolset-7/root/usr/lib64/dyninst:/opt/rh/devtoolset-7/root/usr/lib/dyninst:/opt/rh/devtoolset-7/root/usr/lib64:/opt/rh/devtoolset-7/root/usr/lib:/home/wxuser/work/golang/src/github.com/PlatONnetwork/PlatON-Go/mpclib$ cd PlatON-Go/複製代碼

• 帶mpc編譯

$ make platon-with-mpc > ~/temp/make_platon.txt

$ make all-with-mpc > ~/temp/make_all.txt
複製代碼

編譯後生成的可執行程序在 build/bin/ 中。

將生成的可執行程序拷貝到節點啓動目錄

$ cd build
$ cp -R bin/ ~/platon-node
複製代碼


1.7. 從新編譯前的清理工做

$ make clean

$ rm -rf build/_workspace/*
複製代碼


2. 初始化和運行PlatON

2.1. PlatON節點初始化

2.1.1. 生成 account 和 key pair

$ ./platon --datadir ./data account new

INFO [01-09|17:25:14.269] Maximum peer count ETH=50 LES=0 total=50
Your new account is locked with a password. Please give a password. Do not forget this password.
Passphrase: 
Repeat passphrase: 
Address: {60208c048e7eb8e38b0fac40406b819ce95aa7af}
複製代碼

本次操做密碼設成了「0」。

$ ll data/keystore/

-rw------- 1 wxuser wxuser 491 Jan 9 17:25 UTC--2019-01-09T09-25-28.487164507Z--60208c048e7eb8e38b0fac40406b819ce95aa7af$ ./ethkey genkeypair

Address : 0xC71433b47f1b0053f935AEf64758153B24cE7445
PrivateKey: b428720a89d003a1b393c642e6e32713dd6a6f82fe4098b9e3a90eb38e23b6bb
PublicKey : 68bb049008c7226de3188b6376127354507e1b1e553a2a8b988bb99b33c4d995e426596fc70ce12f7744100bc69c5f0bce748bc298bf8f0d0de1f5929850b5f4複製代碼

將節點私鑰存儲在 ./data/platon/nodekey中,私鑰來自上一步PrivateKey。

$ mkdir -p ./data/platon

$ echo "b428720a89d003a1b393c642e6e32713dd6a6f82fe4098b9e3a90eb38e23b6bb" > ./data/platon/nodekey

$ cat ./data/platon/nodekey

b428720a89d003a1b393c642e6e32713dd6a6f82fe4098b9e3a90eb38e23b6bb
複製代碼


2.1.2. 配置初始化文件

將initialNodes改成節點公鑰,alloc爲帳戶地址分配金額。

$ vi genesis.json

{
"config": {
"chainId": 300,
"homesteadBlock": 1,
"eip150Block": 2,
"eip150Hash": "0x0000000000000000000000000000000000000000000000000000000000000000",
"eip155Block": 3,
"eip158Block": 3,
"byzantiumBlock": 4,
"cbft": {
"initialNodes": ["enode://68bb049008c7226de3188b6376127354507e1b1e553a2a8b988bb99b33c4d995e426596fc70ce12f7744100bc69c5f0bce748bc298bf8f0d0de1f5929850b5f4@127.0.0.1:16789"]
}
},
"nonce": "0x0",
"timestamp": "0x5c074288",
"extraData": "0x00000000000000000000000000000000000000000000000000000000000000007a9ff113afc63a33d11de571a679f914983a085d1e08972dcb449a02319c1661b931b1962bce02dfc6583885512702952b57bba0e307d4ad66668c5fc48a45dfeed85a7e41f0bdee047063066eae02910000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000",
"gasLimit": "0x47b77760",
"difficulty": "0x40000",
"mixHash": "0x0000000000000000000000000000000000000000000000000000000000000000",
"coinbase": "0x60208c048e7eb8e38b0fac40406b819ce95aa7af",
"alloc": {
"0x60208c048e7eb8e38b0fac40406b819ce95aa7af": {
"balance": "999000000000000000000"
}
},
"number": "0x0",
"gasUsed": "0x0",
"parentHash": "0x0000000000000000000000000000000000000000000000000000000000000000"
}
複製代碼


2.1.3. 初始化PlatON

$ ./platon --datadir ./data init genesis.json

INFO [01-09|17:31:58.832] Maximum peer count ETH=50 LES=0 total=50
INFO [01-09|17:31:58.833] Allocated cache and file handles database=/home/wxuser/manual-Platon/build/bin/data/platon/chaindata cache=16 handles=16
INFO [01-09|17:31:58.839] Writing custom genesis block 
INFO [01-09|17:31:58.840] Persisted trie from memory database nodes=1 size=150.00B time=34.546µs gcnodes=0 gcsize=0.00B gctime=0s livenodes=1 livesize=0.00B
INFO [01-09|17:31:58.840] Successfully wrote genesis state database=chaindata hash=4fe06b…382a26
INFO [01-09|17:31:58.840] Allocated cache and file handles database=/home/wxuser/manual-Platon/build/bin/data/platon/lightchaindata cache=16 handles=16
INFO [01-09|17:31:58.848] Writing custom genesis block 
INFO [01-09|17:31:58.848] Persisted trie from memory database nodes=1 size=150.00B time=238.177µs gcnodes=0 gcsize=0.00B gctime=0s livenodes=1 livesize=0.00B
INFO [01-09|17:31:58.848] Successfully wrote genesis state database=lightchaindata hash=4fe06b…382a26
複製代碼


2.2. 啓動 PlatON 節點

$ ./platon --identity "node1" --rpc --rpcaddr 0.0.0.0 --datadir ./data --rpcapi "db,eth,net,web3,admin,personal,miner" --networkid 300 --mine --verbosity 3 --miner.etherbase 0x60208c048e7eb8e38b0fac40406b819ce95aa7af

INFO [01-09|17:42:01.165] Maximum peer count ETH=50 LES=0 total=50
INFO [01-09|17:42:01.166] Starting peer-to-peer node instance=Geth/node1/v1.8.16-stable-7ee6fe39/linux-amd64/go1.11.4
INFO [01-09|17:42:01.166] Allocated cache and file handles database=/home/wxuser/manual-Platon/build/bin/data/platon/chaindata cache=768 handles=512
INFO [01-09|17:42:01.183] Initialised chain configuration config="{ChainID: 300 Homestead: 1 DAO: <nil> DAOSupport: false EIP150: 2 EIP155: 3 EIP158: 3 Byzantium: 4 Constantinople: <nil> Engine: &{0 0 0 0 0 [{127.0.0.1 16789 16789 68bb049008c7226de3188b6376127354507e1b1e553a2a8b988bb99b33c4d995e426596fc70ce12f7744100bc69c5f0bce748bc298bf8f0d0de1f5929850b5f4 [149 178 250 27 246 47 49 86 100 108 50 3 199 20 51 180 127 27 0 83 249 53 174 246 71 88 21 59 36 206 116 69] {0 0 <nil>}}] 00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000 <nil>}}"
INFO [01-09|17:42:01.183] Initialising Ethereum protocol versions="[63 62]" network=300
INFO [01-09|17:42:01.184] Loaded most recent local header number=0 hash=4fe06b…382a26 age=1mo5d6h
INFO [01-09|17:42:01.184] Loaded most recent local full block number=0 hash=4fe06b…382a26 age=1mo5d6h
INFO [01-09|17:42:01.184] Loaded most recent local fast block number=0 hash=4fe06b…382a26 age=1mo5d6h
INFO [01-09|17:42:01.184] Read the StateDB instance from the cache map sealHash=bbbae7…30dbfb
INFO [01-09|17:42:01.184] Loaded local transaction journal transactions=0 dropped=0
INFO [01-09|17:42:01.185] Regenerated local transaction journal transactions=0 accounts=0
INFO [01-09|17:42:01.185] Loaded local mpc transaction journal mpc transactions=0 dropped=0
INFO [01-09|17:42:01.185] Init mpc processor success osType=linux icepath= httpEndpoint=http://127.0.0.1:6789
INFO [01-09|17:42:01.185] commitDuration commitDuration=950.000
INFO [01-09|17:42:01.185] Set the block time at the end of the last round of consensus startTimeOfEpoch=1543979656
INFO [01-09|17:42:01.185] Starting P2P networking 
INFO [01-09|17:42:03.298] UDP listener up self=enode://aa18a88c1463c1f1026c6cb0b781027d898d19ed9c11b10ad7a3a9ee2d0c09ab607d9b24bc4580bd816c0194215461cd88bf65955e0d87cf69e0157d464c582b@[::]:16789
INFO [01-09|17:42:03.299] Transaction pool price threshold updated price=1000000000
INFO [01-09|17:42:03.300] IPC endpoint opened url=/home/wxuser/manual-Platon/build/bin/data/platon.ipc
INFO [01-09|17:42:03.300] RLPx listener up self=enode://aa18a88c1463c1f1026c6cb0b781027d898d19ed9c11b10ad7a3a9ee2d0c09ab607d9b24bc4580bd816c0194215461cd88bf65955e0d87cf69e0157d464c582b@[::]:16789
INFO [01-09|17:42:03.300] HTTP endpoint opened url=http://0.0.0.0:6789 cors= vhosts=localhost
INFO [01-09|17:42:03.300] Transaction pool price threshold updated price=1000000000
複製代碼


2.3. PlatON help 信息

$ ./platon --help
複製代碼


2.4. 從新初始化PlatON節點

確保PlatON進程已經被殺死,再刪除data目錄。

$ cd build/bin

$ rm -rf data/platon
複製代碼

而後能夠再從新初始化。


3. CentOS升級gcc原始步驟

CentOS 7.5升級GCC的原始步驟。


3.1. 安裝CentOS-release-scl

$ sudo yum install centos-release-scl

================================================================================
Package Arch Version Repository Size
================================================================================
Installing:
centos-release-scl noarch 2-2.el7.centos extras 12 k
Installing for dependencies:
centos-release-scl-rh noarch 2-2.el7.centos extras 12 k

Transaction Summary
================================================================================
Install 1 Package (+1 Dependent package)

Total download size: 24 k
Installed size: 39 k
複製代碼


3.2. 使用yum 安裝devtoolset-7

$ sudo yum install devtoolset-7

==============================================================================
Package Arch Version Repository Size
==============================================================================
Installing:
devtoolset-7 x86_64 7.1-4.el7 centos-sclo-rh 6.2 k
Installing for dependencies:
boost-date-time x86_64 1.53.0-27.el7 CentOS-7_Local 52 k
devtoolset-7-binutils x86_64 2.28-11.el7 centos-sclo-rh 5.3 M
devtoolset-7-dwz x86_64 0.12-1.1.el7 centos-sclo-rh 99 k
devtoolset-7-dyninst x86_64 9.3.2-3.el7 centos-sclo-rh 3.6 M
devtoolset-7-elfutils x86_64 0.170-5.el7 centos-sclo-rh 390 k
devtoolset-7-elfutils-libelf x86_64 0.170-5.el7 centos-sclo-rh 194 k
devtoolset-7-elfutils-libs x86_64 0.170-5.el7 centos-sclo-rh 280 k
devtoolset-7-gcc x86_64 7.3.1-5.13.el7 centos-sclo-rh 29 M
devtoolset-7-gcc-c++ x86_64 7.3.1-5.13.el7 centos-sclo-rh 11 M
devtoolset-7-gcc-gfortran x86_64 7.3.1-5.13.el7 centos-sclo-rh 11 M
devtoolset-7-gdb x86_64 8.0.1-36.el7 centos-sclo-rh 3.2 M
devtoolset-7-libquadmath-devel x86_64 7.3.1-5.13.el7 centos-sclo-rh 154 k
devtoolset-7-libstdc++-devel x86_64 7.3.1-5.13.el7 centos-sclo-rh 2.6 M
devtoolset-7-ltrace x86_64 0.7.91-2.el7 centos-sclo-rh 148 k
devtoolset-7-make x86_64 1:4.2.1-3.el7 centos-sclo-rh 485 k
devtoolset-7-memstomp x86_64 0.1.5-5.1.el7 centos-sclo-rh 442 k
devtoolset-7-oprofile x86_64 1.2.0-2.el7.1 centos-sclo-rh 1.8 M
devtoolset-7-perftools x86_64 7.1-4.el7 centos-sclo-rh 3.6 k
devtoolset-7-runtime x86_64 7.1-4.el7 centos-sclo-rh 20 k
devtoolset-7-strace x86_64 4.17-7.el7 centos-sclo-rh 558 k
devtoolset-7-systemtap x86_64 3.1-4s.el7 centos-sclo-rh 141 k
devtoolset-7-systemtap-client x86_64 3.1-4s.el7 centos-sclo-rh 2.1 M
devtoolset-7-systemtap-devel x86_64 3.1-4s.el7 centos-sclo-rh 2.1 M
devtoolset-7-systemtap-runtime x86_64 3.1-4s.el7 centos-sclo-rh 405 k
devtoolset-7-toolchain x86_64 7.1-4.el7 centos-sclo-rh 3.8 k
devtoolset-7-valgrind x86_64 1:3.13.0-11.el7 centos-sclo-rh 7.6 M
efivar-libs x86_64 31-4.el7 CentOS-7_Local 68 k
kernel-debug-devel x86_64 3.10.0-862.el7 CentOS-7_Local 16 M
libgfortran4 x86_64 7.2.1-1.1.1.el7 CentOS-7_Local 676 k
libquadmath x86_64 4.8.5-28.el7 CentOS-7_Local 188 k
mokutil x86_64 12-1.el7.centos CentOS-7_Local 41 k
scl-utils x86_64 20130529-18.el7_4 CentOS-7_Local 24 k

Transaction Summary
==============================================================================
Install 1 Package (+32 Dependent packages)

Total download size: 100 M
Installed size: 289 M
複製代碼


3.3. 編譯得到靜態庫libstdc++.so.6

經過devtoolset 7升級GCC,並不會獲得靜態庫: libstdc++.so.6.0.24。能夠在「另外一個」CentOS 7.5環境中,編譯gcc 7.3.0獲得這個文件。

http://www.netgull.com/gcc/releases/gcc-7.3.0/gcc-7.3.0.tar.gz

ftp://gcc.gnu.org/pub/gcc/infrastructure/gmp-6.1.0.tar.bz2 ftp://gcc.gnu.org/pub/gcc/infrastructure/mpfr-3.1.4.tar.bz2 ftp://gcc.gnu.org/pub/gcc/infrastructure/mpc-1.0.3.tar.gz ftp://gcc.gnu.org/pub/gcc/infrastructure/isl-0.16.1.tar.bz2

$ tar xvf gcc-7.3.0.tar.gz

$ cd gcc-7.3.0

$ ./contrib/download_prerequisites
複製代碼

說明:若是腳本沒法成功經過ftp下載文件,就手動下載以上4個壓縮包,放到 gcc-7.3.0/中,再執行這個腳本,解壓縮並創建link。

$ mkdir build

$ cd build

$ ../configure --enable-checking=release --enable-languages=c,c++ --disable-multilib
複製代碼

說明: --enable-checking=release //增長一些檢查,也能夠–disable-checking生成的編譯器在編譯過程當中不作檢查; --enable-languages=c,c++ //讓gcc支持的編程語言 ; --disable-multilib //取消多目標庫編譯(取消32位庫編譯)。

$ make
複製代碼

libstdc++.so.6.0.24 在 build/x86_64-pc-linux-gnu/libstdc++-v3/src/.libs/libstdc++.so.6.0.24 中。若是須要,能夠把它拷貝到另一個Linux的 /opt/rh/devtoolset-7/root/lib64/ 中。(目前不須要)

$ sudo mv libstdc++.so.6.0.24 /opt/rh/devtoolset-7/root/lib64/ 

$ cd /opt/rh/devtoolset-7/root/lib64/ 

$ sudo chown root.root libstdc++.so.6.0.24 

$ sudo chmod 755 libstdc++.so.6.0.24 

$ sudo ln -s libstdc++.so.6.0.24 libstdc++.so.6
複製代碼


做者簡介:

上海萬向區塊鏈股份公司CTO,產品和研發團隊負責人,ISO TC307 區塊鏈國際標準本體論項目負責人。擁有15 年的IT 技術規劃及管理方面的從業經歷,曾在中國證監會直屬的證券期貨交易所負責技術系統規劃工做,長期與納斯達克交易所、紐約證券交易所、泛歐交易所等國際領先交易所集團共同開展技術項目,與歐美技術架構師進行過深刻合做交流,具備深厚的金融技術背景和全球化視野,撰寫的論文還曾獲評證監會優秀論文。在區塊鏈前沿技術及其在金融行業應用方面具備很強的研究能力。

相關文章
相關標籤/搜索