本文主要介紹如何在 Ubuntu 16.04 上搭建 EOS 環(huán)境
(噴血吐槽: MMP,從來(lái)沒(méi)有一行代碼沒(méi)寫,搭個(gè)環(huán)境搭了一個(gè)禮拜...)
參考文章:
http://www.itdecent.cn/p/47ea4d11d997
http://www.itdecent.cn/p/c47091d69dde
搭建環(huán)境前注意事項(xiàng):
虛擬機(jī)要求分配至少 8GB 內(nèi)存,貌似是 至少 20GB 可用磁盤空間(記不太清了,最好多分配點(diǎn)), 至于對(duì)已有的虛擬機(jī) 如何擴(kuò)大內(nèi)存或磁盤空間,請(qǐng)自行百度
環(huán)境搭建
- 下載 EOS 代碼
git clone https://github.com/EOSIO/eos.git -b DAWN-2018-02-14 --recursive
下載的版本應(yīng)該是DAWN-2018-02-14版
加入--recursive參數(shù),否則EOS關(guān)聯(lián)的子項(xiàng)目沒(méi)法下載
- 自動(dòng)編譯
cd eos
./build.sh ubuntu full
編譯的時(shí)間巨長(zhǎng)... 我的虛擬機(jī)裝在SSD上都平均至少編譯2+小時(shí)....
./build.sh ubuntu 后面可以跟一個(gè)參數(shù),默認(rèn)值為 full , 也可以是 build。
full用于第一次編譯或完全重新編譯,它會(huì)重新嘗試編譯安裝依賴項(xiàng).
build是僅編譯EOS代碼,在變更代碼后可以使用以下命令重新編譯。
./build.sh ubuntu build
-
編譯遇到的錯(cuò)誤
image.png
google之后,找到 解決方案
解決過(guò)程如下:
- 打開
eos/plugins/db_plugin/CMakeLists.txt(在 master 分支上對(duì)應(yīng)的地址為eos/plugins/mongo_db_plugin/CMakeLists.txt) - 在文件中找到 下面對(duì)應(yīng)的 減號(hào) ‘-‘ 行: 表示將該行從文件中刪除 或者注釋掉 ,加號(hào)'+' 行表示在文件中對(duì)應(yīng)位置 添加相應(yīng)的行
@@ -20,14 +20,22 @@ if (libmongoc-1.0_FOUND)
find_package(libbsoncxx REQUIRED)
message(STATUS "Found bsoncxx headers: ${LIBBSONCXX_INCLUDE_DIRS}")
- find_library(EOS_LIBBSONCXX ${LIBBSONCXX_LIBRARIES}
- PATHS ${LIBBSONCXX_LIBRARY_DIRS} NO_DEFAULT_PATH)
+ if((LIBBSONCXX_VERSION_MAJOR LESS 3) OR ((LIBBSONCXX_VERSION_MAJOR EQUAL 3) AND (LIBBSONCXX_VERSION_MINOR LESS 2)))
+ find_library(EOS_LIBBSONCXX ${LIBBSONCXX_LIBRARIES}
+ PATHS ${LIBBSONCXX_LIBRARY_DIRS} NO_DEFAULT_PATH)
+ else()
+ set(EOS_LIBBSONCXX ${LIBBSONCXX_LIBRARIES})
+ endif()
message(STATUS "Found bsoncxx library: ${EOS_LIBBSONCXX}")
find_package(libmongocxx REQUIRED)
message(STATUS "Found mongocxx headers: ${LIBMONGOCXX_INCLUDE_DIRS}")
- find_library(EOS_LIBMONGOCXX ${LIBMONGOCXX_LIBRARIES}
- PATHS ${LIBMONGOCXX_LIBRARY_DIRS} NO_DEFAULT_PATH)
+ if((LIBMONGOCXX_VERSION_MAJOR LESS 3) OR ((LIBMONGOCXX_VERSION_MAJOR EQUAL 3) AND (LIBMONGOCXX_VERSION_MINOR LESS 2)))
+ find_library(EOS_LIBMONGOCXX ${LIBMONGOCXX_LIBRARIES}
+ PATHS ${LIBMONGOCXX_LIBRARY_DIRS} NO_DEFAULT_PATH)
+ else()
+ set(EOS_LIBMONGOCXX ${LIBMONGOCXX_LIBRARIES})
+ endif()
message(STATUS "Found mongocxx library: ${EOS_LIBMONGOCXX}")
- 修改完重新進(jìn)行編譯,進(jìn)入 eos 目錄運(yùn)行一下命令
./build.sh ubuntu build
等待編譯成功即可
- 最后一步
cd build
make install
該命令會(huì)將編譯好的可執(zhí)行文件、頭文件、庫(kù)文件和模板文件安裝到build下的install目錄下,在該目錄的bin下有所有編譯好的命令,包括eosd、eosc、eoscpp等等。
創(chuàng)建并啟動(dòng)測(cè)試網(wǎng)絡(luò)單節(jié)點(diǎn)
教程
執(zhí)行命令:
cd build/programs/eosd
./eosd
直接使用命令執(zhí)行./eosd 會(huì)得到一個(gè)錯(cuò)誤(注意這一步是要做的,因?yàn)?code>eosd會(huì)在當(dāng)前目錄( eos/build/programs/eosd)產(chǎn)生一個(gè)data-dir的目錄。 如果沒(méi)有報(bào)錯(cuò),始終沒(méi)有停止,使用ctrl+c 停掉 eosd )
進(jìn)入 data-dir目錄修改 config.ini
cd data-dir
sudo gedit config.ini
通過(guò)查找以下 屬性名,找到對(duì)應(yīng)的位置進(jìn)行設(shè)置, 注意去掉注釋(前面有# 號(hào)的去掉# 號(hào))
-
genesis-json設(shè)置為eos目錄下的genesis.json文件所在路徑,在我的系統(tǒng)中路徑為/home/ethan/develop/blockchain/eos
genesis-json = /home/ethan/develop/blockchain/eos
-
enable-stale-production設(shè)置為true
enable-stale-production = true
- 添加以下到文件中
producer-name = inita
producer-name = initb
producer-name = initc
producer-name = initd
producer-name = inite
producer-name = initf
producer-name = initg
producer-name = inith
producer-name = initi
producer-name = initj
producer-name = initk
producer-name = initl
producer-name = initm
producer-name = initn
producer-name = inito
producer-name = initp
producer-name = initq
producer-name = initr
producer-name = inits
producer-name = initt
producer-name = initu
# Load the block producer plugin, so you can produce blocks
plugin = eosio::producer_plugin
# Wallet plugin
plugin = eosio::wallet_api_plugin
# As well as API and HTTP plugins
plugin = eosio::chain_api_plugin
plugin = eosio::http_plugin
配置好之后,保存,進(jìn)入eos/build/programs/eosd 目錄下,重新執(zhí)行 ./eosd, 如果報(bào)錯(cuò) can not run eosd after building:unable to find genesis file, 表示genesis.json文件未配置成功,檢查注釋是否去掉或者 路徑是否正確.
執(zhí)行成功后,如圖所示:

參考文件:
# Load the testnet genesis state, which creates some initial block producers with the default key
genesis-json = /path/to/eos/source/genesis.json
# Enable production on a stale chain, since a single-node test chain is pretty much always stale
enable-stale-production = true
# Enable block production with the testnet producers
producer-name = inita
producer-name = initb
producer-name = initc
producer-name = initd
producer-name = inite
producer-name = initf
producer-name = initg
producer-name = inith
producer-name = initi
producer-name = initj
producer-name = initk
producer-name = initl
producer-name = initm
producer-name = initn
producer-name = inito
producer-name = initp
producer-name = initq
producer-name = initr
producer-name = inits
producer-name = initt
producer-name = initu
# Load the block producer plugin, so you can produce blocks
plugin = eosio::producer_plugin
# Wallet plugin
plugin = eosio::wallet_api_plugin
# As well as API and HTTP plugins
plugin = eosio::chain_api_plugin
plugin = eosio::http_plugin
