EOS环境搭建



MongoDB下载

本篇教程适用于以下系统,但是不论你的电脑是 windows 还是 mac,都强烈建议安装一个虚拟机,在 Ubuntu 上搞,因为 Mac 上有很多坑。安装 Ubuntu 虚拟机有关教程大家可以在网上搜到。
•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).

配置要求:
•8GB 内存
•20GB 硬盘空余空间

如果机器内存不够 8G,自动编译脚本会报错。

运行 EOS 需要一点 linux 和 github 基础,不过不要嫌麻烦,以后开发 EOS 合约需要大量这方面的知识。推荐你先按步骤搞起来,有不明白的可以参考以下文章。别怕,谁也不是生下来就什么都会的。

linux 命令基础: https://linux.cn/article-6160-1.html

github 基础: http://www.runoob.com/w3cnote/git-guide.html

下载 EOS 代码

如果你是 Mac,需要先下载 git,可以搜索 “Mac git” 就能找的各种文章教你在 Mac 上安装 git。

首先使用 cd命令进入你想安装的文件夹,我一般就是根目录了,执行以下命令下载 EOS 代码:
git clone https://github.com/EOSIO/eos --recursive

注意要加后面这个 --recursive命令,因为 EOS 有几个子模块,这样就能全部下载下来,如果忘了这个命令,使用下面的命令可以补救:
git submodule update --init --recursive

有了源代码,我们就可以构建我们本地的 EOS 程序了,EOS 官方非常体贴地为我们准备了自动构建的脚本,使用这个脚本可以大大简化,首先我们进入刚刚下载的 eos 目录,并执行构建脚本:
cd eos
./eosio_build.sh

坑1:使用的是虚拟机Ubuntu系统的话,虽然扩展空间很大,但是在运行该命令时会出现 磁盘空间不够20G,可以修改该脚本中的  DISK_MIN=20  限制,另外,最小的内存要大于7G,可以修改./scripts/eosio_build_ubuntu.sh中的  ${MEM_MEG}" -lt 7000 限制

坑2:在执行过程中可能会遇到MongoDB无法下载的情况,可以自己去下载MongoDB,将下载的mongodb-linux-x86_64-3.6.3放入linux的~/opt/下面。然后修改./scripts/eosio_build_ubuntu.sh,如下:

  #STATUS=$(curl -LO -w '%{http_code}' --connect-timeout 30 https://fastdl.mongodb.org/linux/mongodb-linux-x86_64-3.6.3.tgz)
  #if [ "${STATUS}" -ne 200 ]; then
   #printf "
\\tUnable to download MongoDB at this time.\\n"
   #printf "
\\n\\tExiting now.\\n\\n"
   #exit 1;
  #fi

根据网速和机器性能的不同,可能要用 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
...

说明本地的单节点已经开始正常出块了。

如果你不满足于以上,可以对节点配置进行修改,配置文件位于:
•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命令重新指定数据文件夹。

猜你喜欢

转载自blog.csdn.net/nsh119/article/details/80613027