美文网首页666笔记侠EOS开发系列
12月5号 搭建 EOS 开发环境+创建单节点测试网

12月5号 搭建 EOS 开发环境+创建单节点测试网

作者: Ourea无涯社区 | 来源:发表于2018-12-06 04:12 被阅读54次

前言


之前我们进行了开发 EOS 之前的必要准备,因为 EOS 的硬件软件环境要求较高,安装了Ubuntu 16.04 的虚拟机,今天我们的任务是:

  1. 下载源码并成功部署 EOS 开发环境;

  2. 链接 EOS 主网尝试同步几个区块;

  3. 部署一个 EOS 节点,建立单节点测试网。

本文章主要参考了 EOS 的官方文档,任何学习 EOS 的相关还是得看官方的,网上资料的都很乱,并且版本、系统都不尽相同,我还看到有人跑最原始的 EOS 的代码(晕)。这里介绍的是官方的部署方法,并使用了官方的一件部署脚本,很容易操作,希望能帮到你。

注:这虽然不代表windows下不能安装,但官方的文档并未给出windows版本的安装方法。

下载源码,部署 EOS


一、安装 git

我们需要在 GitHub 里拉取EOS的代码,所以需要先安装 git 的工具,就能通过命令来下载项目代码。
首先打开你的终端,输入:

sudo apt-get install git

二、下载 EOS 源代码

利用 git 获取EOS源码及其所有子模块:

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

但是因为众所周知的科学上网,源码的下载速度非常之慢,只有几 kb。因为国内限制了加密链路https的速度,我们只需要改用 http 的方式下载就能加速。接着,我就用:

git clone http://github.com/eosio/eos  --recursive

然后就可以看到下载速度变得很快,我们耐心等上一段时间

如果克隆代码时忘了带–recursive参数,可以切换到项目路径下面执行如下命令来更新子模块。

git submodule update  --init  --recursive

三、运行 EOS 安装脚本

运行自动编译程序:

cd eos
./eosio_build.sh

在准备节点选择Yes开始安装

    Beginning build version: 1.2
    2018年 11月 20日 星期二 08:10:25 UTC
    User: punk
    git head id: 60c8baceb0f5a2ec34cf51ff89e9f08810fbc41d
    Current branch: master

    ARCHITECTURE: Linux

    OS name: Ubuntu
    OS Version: 16.04
    CPU speed: 2701.000Mhz
    CPU cores: 4
    Physical Memory: 8527 Mgb
    Disk install: /dev/sda1
    Disk space total: 77G
    Disk space available: 63G

这个脚本需要运行很久,我用了一个半小时才编译完毕,所以要耐心等待,运行成功会出现以下结果:

ld: warning: PIE disabled. Absolute addressing (perhaps -mdynamic-no-pic) not allowed in code signed PIE, but used in ___gmpn_divexact_1 from /usr/local/lib/libgmp.a(dive_1.o). To fix this warning, don't compile with -mdynamic-no-pic or link with -Wl,-no_pie
[100%] Built target chain_test


     _______  _______  _______ _________ _______
    (  ____ \(  ___  )(  ____ \\__   __/(  ___  )
    | (    \/| (   ) || (    \/   ) (   | (   ) |
    | (__    | |   | || (_____    | |   | |   | |
    |  __)   | |   | |(_____  )   | |   | |   | |
    | (      | |   | |      ) |   | |   | |   | |
    | (____/\| (___) |/\____) |___) (___| (___) |
    (_______/(_______)\_______)\_______/(_______)

    EOS.IO has been successfully built. 0:11:48

    To verify your installation run the following commands:

    /usr/local/bin/mongod -f /usr/local/etc/mongod.conf &
    cd /Users/liyuechun/eos/build; make test

    For more information:
    EOS.IO website: https://eos.io
    EOS.IO Telegram channel @ https://t.me/EOSProject
    EOS.IO resources: https://eos.io/resources/
    EOS.IO wiki: https://github.com/EOSIO/eos/wiki

四、针对内存不够编译失败的

由于本人使用的是 Ubuntu 的虚拟机,在运行自动化脚本过程可能会因为主机物理内存小于 7G,而报错编译失败,这个问题可以通过修改 eos/scripts/eosio_build_ubuntu.sh 脚本中的第27-31行。

先找到并打开 eosio_build_ubuntu.sh 文件:

cd ~/eos/scripts
gedit eosio_build_ubuntu.sh

进入文件后,在第27-31行左右找到 if ["${MERM_MEG}" -lt 7000]; then,并注释掉。

之后在运行第三步的操作。

五、安装可执行文件,并测试

为了方便日后直接调用,我们可以安装可执行程序,这样就不需要每次使用都打开相关目录了!

cd eos
sudo ./eosio_install.sh

同时给出EOS 附带的一些可执行命令:

  • nodeos: 区块链服务器节点生成组建
  • cleos: 和区块链交互的接口命令
  • keosd: EOS 钱包
  • eosio-launcher:节点网络组成和部署的应用

安装结束后可以测试一下是否成功,运行代码:

cd eos
cd build
sudo make test

此时检测结果会出现8个错误在节点 node 部分。

The following tests FAILED:
     36 - nodeos_run_test-mongodb (Failed)
     42 - validate_dirty_db_test (Failed)
     49 - nodeos_voting_bnet_lr_test (Failed)
Errors while running CTest
Makefile:116: recipe for target 'test' failed
make: *** [test] Error 8

不用担心。因为我们还没有部署节点,或链上任何网络。

六、配置 nodeos 与 keosd

1. 先配置 nodeos

上面介绍了,nodeos 是eos中控制节点的部分,先运行nodeos

cd eos/build/programs/nodeos
./nodeos

这时候会报错,纯属正常的,这一步只是为了生成配置文件。我们需要去修改 config.ini 的配置文件。找到 config.ini 文件的位置:

gedit ~/.local/share/eosio/nodeos/config/config.ini

Mac OS:中地址为: ~/Library/Application/Support/eosio/nodeos/config/config.ini

将文中 enable-stale-production 所在行用 # 注释,producer-name 所在行也用 # 注释,然后再在最后面添加如下内容:

# 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
# 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 history
plugin = eosio::history_api_plugin

2. 再配置 keosd

keosd 是一个轻客户端钱包,负责管理钱包,以便在广播到网络之前保护密钥和签署交易,在本地计算机上运行并在本地存储您的私钥。先运行 keosd

cd eos/build/programs/keosd
./keosd

会报错,不用担心,同样是为了生成配置文件,再找到配置文件的位置:

gedit ~/eosio-wallet/config.ini

在第二段中,把服务地址设置为:

http-server-address = 127.0.0.1:8889

为了更清晰的看明白,如下图:

七、启动节点,建立测试网

因为刚刚已经执行过一次 nodeos 命令了,它会在~/.local/share/eosio/nodeos/data/ 这个目录下生成相应的文件,如果现在重新执行 nodeos 命令,可能会报出如下错误:

Failed to start a pending block, will try again later ...

这时要先删除这个目录下的所有文件:

rm -rf ~/.local/share/eosio/nodeos/data/*

删除后再次运行 nodeos 命令:

cd eos/build/programs/nodeos
./nodeos

启动后每0.5秒,就会生成一个块,并有日志输出到终端滚动显示,如下标出了第一个区块:

恭喜你,已经成功部署好环境啦!

相关文章

网友评论

    本文标题:12月5号 搭建 EOS 开发环境+创建单节点测试网

    本文链接:https://www.haomeiwen.com/subject/kpxzfqtx.html