【許曉笛】從零開始運行EOS系統

成爲最先一批運行EOS的人

複習一下上次文章的內容,EOS 系統主要有三個應用程序:html

  • nodeos: EOS 系統的核心進程,也就是所謂的「節點」。
  • cleos:本地的命令行工具,經過命令行與真人用戶交互,並與節點(nodeos)和錢包(keosd)通訊。是用戶或者開發者與節點進程交互的橋樑。
  • keosd:本地錢包工具。能夠管理多個含有私鑰的錢包並加密。

要求

本篇教程適用於如下系統,可是不論你的電腦是 windows 仍是 mac,都強烈建議安裝一個虛擬機,在 Ubuntu 上搞,由於 Mac 上有不少坑。安裝 Ubuntu 虛擬機有關教程你們能夠在網上搜到。node

  • Amazon 2017.09 and higher.
  • Centos 7.
  • Fedora 25 and higher (Fedora 27 recommended).
  • Mint 18.
  • Ubuntu 16.04 (Ubuntu 16.10 recommended).
  • MacOS Darwin 10.12 and higher (MacOS 10.13.x recommended).

配置要求:linux

  • 8GB 內存
  • 20GB 硬盤空餘空間

若是機器內存不夠 8G,自動編譯腳本會報錯。git

運行 EOS 須要一點 linux 和 github 基礎,不過不要嫌麻煩,之後開發 EOS 合約須要大量這方面的知識。推薦你先按步驟搞起來,有不明白的能夠參考如下文章。別怕,誰也不是生下來就什麼都會的。github

linux 命令基礎: https://linux.cn/article-6160...mongodb

github 基礎: http://www.runoob.com/w3cnote...json

下載 EOS 代碼

若是你是 Mac,須要先下載 git,能夠搜索 「Mac git」 就能找的各類文章教你在 Mac 上安裝 git。segmentfault

首先使用 cd 命令進入你想安裝的文件夾,我通常就是根目錄了,執行如下命令下載 EOS 代碼:windows

git clone https://github.com/EOSIO/eos --recursive

注意要加後面這個 --recursive 命令,由於 EOS 有幾個子模塊,這樣就能所有下載下來,若是忘了這個命令,使用下面的命令能夠補救:api

git submodule update --init --recursive

構建 EOS

有了源代碼,咱們就能夠構建咱們本地的 EOS 程序了,EOS 官方很是體貼地爲咱們準備了自動構建的腳本,使用這個腳本能夠大大簡化,首先咱們進入剛剛下載的 eos 目錄,並執行構建腳本:

cd eos
./eosio_build.sh

根據網速和機器性能的不一樣,可能要用 30 分鐘 - 1 小時的時間,請耐心等待。構建完成後須要對構建的產物進行驗證:

  • Linux 系(Ubuntu等):
~/opt/mongodb/bin/mongod -f ~/opt/mongodb/mongod.conf &
  • Mac:
/usr/local/bin/mongod -f /usr/local/etc/mongod.conf &

而後全部操做系統再執行如下命令:

cd build
make test

爲了方便開發智能合約,還須要在 build 目錄進行 make install:
若是已經進入 build 目錄請去掉 cd build。

cd build
sudo make install

創建本地單節點測試網絡

構建完成後,咱們進入 eos/build/programs/nodeos 目錄(使用 cd 和 cd .. 命令),運行 nodeos 節點程序:

./nodeos -e -p eosio --plugin eosio::wallet_api_plugin --plugin eosio::chain_api_plugin --plugin eosio::account_history_api_plugin

命令中, -p 參數表示使用了 eosio 帳戶的權限,這是本地測試系統提供的原始帳戶。後面的各個 plug in 參數是選擇加載的插件。

成功後,若是看到相似下面的輸出,就是成功創建了一個本地單節點測試網絡:

1575001ms thread-0   chain_controller.cpp:235      _push_block          ] initm #1 @2017-09-04T04:26:15  | 0 trx, 0 pending, exectime_ms=0
1575001ms thread-0   producer_plugin.cpp:207       block_production_loo ] initm generated block #1 @ 2017-09-04T04:26:15 with 0 trxs  0 pending
1578001ms thread-0   chain_controller.cpp:235      _push_block          ] initc #2 @2017-09-04T04:26:18  | 0 trx, 0 pending, exectime_ms=0
1578001ms thread-0   producer_plugin.cpp:207       block_production_loo ] initc generated block #2 @ 2017-09-04T04:26:18 with 0 trxs  0 pending
...
eosio generated block 046b9984... #101527 @ 2018-04-01T14:24:58.000 with 0 trxs
eosio generated block 5e527ee2... #101528 @ 2018-04-01T14:24:58.500 with 0 trxs
...

說明本地的單節點已經開始正常出塊了。

如上次文章所講,咱們創建的本地測試網絡以下,並無單獨的 keosd 錢包,而是使用了 nodeos 程序裏的錢包插件。

![pic1]("")

高級設置

若是你不知足於以上,能夠對節點配置進行修改,配置文件位於:

  • Mac OS: ~/Library/Application Support/eosio/nodeos/config
  • Linux: ~/.local/share/eosio/nodeos/config

上述文件夾中默認有 genesis.json 配置文件,能夠直接修改它,或者在別的文件裏再寫一個新的配置文件,不過運行 nodeos 時,就要經過 --config-dir 命令指出新配置文件的位置。

配置文件夾還默認有一個 config.ini 文件。若是沒有的話,nodeos 啓動時會自動建立一個,但自動建立的 config.ini 文件是不讓節點出塊的,此時你須要使用 Ctrl-C 中止 nodeos,並編輯這個文件:

# 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 = eosio
   # 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
   # This will be used by the validation step below, to view account history
   plugin = eosio::account_history_api_plugin

這樣配置好後,從新啓動 nodeos,就會順利出塊了。

nodeos 的運行數據文件夾(log和共享存儲等數據)位於如下文件夾:

  • Mac OS: ~/Library/Application Support/eosio/nodeos/data
  • Linux: ~/.local/share/eosio/nodeos/data

但也可使用 nodeos 的 --data-dir 命令從新指定數據文件夾。


相關文章和視頻推薦

【許曉笛】EOS 區塊數據結構

圓方圓學院聚集大批區塊鏈名師,打造精品的區塊鏈技術課程。 在各大平臺都長期有優質免費公開課,歡迎報名收看。

公開課地址:https://ke.qq.com/course/345101

相關文章
相關標籤/搜索