区块链系列之如何安装和编译EOS

1. 介绍

EOS - The Most Powerful Infrastructure for Decentralized Applications

2. 获取代码

2.1 环境要求

  • Git Version >= 1.7

2.2 拉取代码

执行git clone https://github.com/eosio/eos --recursive来拉取源代码,拉取完成后可以看到如下输出

拉取代码 - 图片来自简书App

3. 编译EOS

3.1 自动生成脚本

对于Ubuntu 16.06 和MacOS Sierra,项目中有一个自动构建的脚本,它可以安装所有依赖并编译EOS。

当执行编译脚本build.sh时可以给出以下参数

architecture [ubuntu|darwin]
optional mode [full|build]

  • 第一个选项architecture决定了脚本运行在哪个架构下,ubuntu是指Ubuntu,darwin是指MacOS。
  • 第二个选项是指可选的编译模式,可选项有fullbuildfull是指编译时安装所有依赖并进行EOS编译,build是指只编译EOS。默认不传递此参数时,使用full模式。

cd eos
git checkout dawn-2.x
./build.sh ${architecture} ${optional_mode}

在切换到eos目录然后执行以上命令进行编译,下面分别介绍Ubuntu和MacOS Sierra下如何编译EOS。

3.1.1 Ubuntu 16.10

Full Build

git clone https://github.com/eosio/eos --recursive
cd eos
git checkout dawn-2.x
./build.sh ubuntu full

3.1.2 MacOS Sierra

运行脚本之前请确保你的MacOS Sierra系统中安装最新版本的XCode和Brew

若是没有安装请使用如下命令安装Xcode和Brew

xcode-select --install (安装Xcode Command Line Tools)
ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)" (安装Brew)

最后使用如下命令拉取代码并编译

git clone https://github.com/eosio/eos --recursive
cd eos
git checkout dawn-2.x
./build.sh darwin full

3.2 手动生成脚本

3.2.1 依赖软件

3.2.2 MacOS Sierra

  • 安装相关依赖

brew update
brew install git automake libtool boost openssl llvm@4 gmp ninja gettext
brew link gettext --force

  • 安装secp256k1-zkp

git clone https://github.com/cryptonomex/secp256k1-zkp.git
cd secp256k1-zkp
./autogen.sh
./configure
make
sudo make install

  • 安装binaryen

git clone https://github.com/WebAssembly/binaryen.git
cd binaryen
git checkout tags/1.37.14
cmake . && make

  • 设置环境变量

echo "export BINARYEN_ROOT=~/binaryen" >> ~/.bash_profile
source ~/.bash_profile

  • 编译LLVM和WASM

mkdir ~/wasm-compiler
cd ~/wasm-compiler
git clone --depth 1 --single-branch --branch release_40 https://github.com/llvm-mirror/llvm.git
cd llvm/tools
git clone --depth 1 --single-branch --branch release_40 https://github.com/llvm-mirror/clang.git
cd ..
mkdir build
cd build
cmake -G "Unix Makefiles" -DCMAKE_INSTALL_PREFIX=.. -DLLVM_TARGETS_TO_BUILD= -DLLVM_EXPERIMENTAL_TARGETS_TO_BUILD=WebAssembly -DCMAKE_BUILD_TYPE=Release ../
make -j4 install

  • 设置环境变量

echo "export WASM_LLVM_CONFIG=~/wasm-compiler/llvm/bin/llvm-config" >> ~/.bash_profile
echo "export LLVM_DIR=/usr/local/Cellar/llvm/4.0.1/lib/cmake/llvm" >> ~/.bash_profile
source ~/.bash_profile

4. Docker

4.1 安装依赖

4.2 构建EOS镜像

4.3 启动EOS容器

  • docker run --name eosd -p 8888:8888 -p 9876:9876 -t eosio/eos start_eosd.sh arg1 arg2

4.4 获取链信息

4.5 启动EOSD和WALLETD容器

  • docker-compose up

4.5.1 执行EOSC命令

  • alias eosc='docker-compose exec walletd /opt/eos/bin/eosc -H eosd'
  • eosc get info
  • eosc get account inita

4.5.2 更改默认配置

我们可以查看Docker Compose的配置文件并根据自身需要来更改配置文件, 比如更改依赖的服务或者挂载的目录,最后通过如下命令重启容器

docker-compose down
docker-compose up

4.5.3 清除数据挂载点

docker volume rm eosd-data-volume

5. 创建和启动单节点测试网络

在构建EOS成功后,可以在build/programs目录下看到编译生成的二进制文件
编辑config.ini文件并添加以下内容

genesis-json = /path/to/eos/source/genesis.json
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
plugin = eosio::producer_plugin
plugin = eosio::wallet_api_plugin
plugin = eosio::chain_api_plugin
plugin = eosio::http_plugin

随后执行eosd来启动节点,启动后将看到如下输出

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

6. 参考

7. 个人总结

通过以上步骤完成EOS在本地的安装后,可以大概知道EOS项目具体的子项目是如何关联的,当然要是从源码解读的角度来看,这些都是入门的基础操作,接下来我会分享一些有关EOS项目的个人看法,感谢您抽空浏览我的文章,要是我的文章对您有所启发,那将是我莫大的荣幸。

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容

  • 1 EOS智能合约的介绍1.1 所需背景知识1.2 EOS智能合约基础知识1.3 技术局限性 2 智能合约文件2....
    cenkai88阅读 30,652评论 5 28
  • 1 获取代码 2 构建EOS2.1 自动构建2.1.1 Ubuntu 16.102.1.2 MacOS Sierr...
    cenkai88阅读 4,811评论 0 0
  • 我是一名口吃患者,因为平时说话费劲,所以我大多数时间都沉默寡言。很少与别人主动交谈,生怕自己的缺陷被放大被发现。“...
    冲冲安阅读 3,395评论 0 1
  • 突然,我发现支付宝余额多了一笔钱,将近千元,百思不得其解。查了账单才发现,是一篇文章的稿费。 关于这篇文章,说来话...
    万伊刀阅读 8,232评论 1 2
  • 十一、实现页面静态化业务场景 我们在做某项目时,涉及到程序访问的性能问题,这时候我们想到可以通过静态化来提高用户访...
    发觉原来我只是250阅读 3,290评论 0 0