废话不多说,直接上手,对于EOS安装有两种,一种源码安装,一种利用docker安装
使用 Docker 适合在本地测试链调试。如果需要连接主链,建议考虑编译源码
源码安装
1.下载 EOS 代码
git clone https://github.com/eosio/eos --recursive
2.编译代码
./eosio_build.sh
3.执行以下命令开始安装,安装时间较长,会遇到各种问题
./eosio_build.sh
①内存限制修改 解决:ubuntu:eosio_build_ubuntu.sh 25行7000改成3000
②mongoDB无法下载 解决:
https://fastdl.mongodb.org/linux/mongodb-linux-x86_64-3.6.3.tgz
https://github.com/mongodb/mongo-c-driver/releases/download/1.9.3/mongo-c-driver-1.9.3.tar.gz
1)本地下载2个文件“mongodb-linux-x86_64-3.6.3.tgz”和“mongo-c-driver-1.9.3.tar.gz”,cd到home目录,放到此位置,然后打开
~/eos/scripts/eosio_build_ubuntu.sh
注释掉208-213行,在213行后面加入
cp "${HOME}/mongodb-linux-x86_64-3.6.3.tgz" "${HOME}/opt/"
注释掉282-291行,在291行后面加入
cp "${HOME}/mongo-c-driver-1.9.3.tar.gz" "${TEMP_DIR}/"
修改地方:
#注释掉208-213行
#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
#增加一行
cp "${HOME}/mongodb-linux-x86_64-3.6.3.tgz" "${HOME}/opt/" #手工将文件包下载下来拷贝到家目录~/
#注释掉282-291行
# STATUS=$(curl -LO -w '%{http_code}' --connect-timeout 30 https://github.com/mongodb/mongo-c-driver/releases/download/1.9.3/mongo-c-driver-1.9.3.tar.gz)
# if [ "${STATUS}" -ne 200 ]; then
# if ! rm -f "${TEMP_DIR}/mongo-c-driver-1.9.3.tar.gz"
# then
# printf "\\n\\tUnable to remove file %s/mongo-c-driver-1.9.3.tar.gz.\\n" "${TEMP_DIR}"
# fi
# printf "\\tUnable to download MongoDB C driver at this time.\\n"
# printf "\\tExiting now.\\n\\n"
# exit 1;
# fi
#增加一行
cp "${HOME}/mongo-c-driver-1.9.3.tar.gz" "${TEMP_DIR}/" #手工将文件包下载下来拷贝到家目录~/
③Unable to unarchive file/tmp/boost_1_67_0.tar.bz2
解决方案:手动下载boost_1_67_0.tar.bz2
④Error compiling MongoDB C driver
解决方案:打开脚本,定位到412行,或搜索
Error compiling MongoDB C driver.
经查发现if ! make -j"${JOBS}"中的JOBS值为空,原因是第7行CPU_CORE=$( lscpu | grep "^CPU(s)" | tr -s ' ' | cut -d\ -f2 || cut -d' ' -f2 )没有获取到CPU的个数,在第8行增加CPU_CORE=2即可。
⑤Unable to clone llvm repo @ https://github.com/llvm-mirror/llvm.git.
解决方案
打开以下文件~/eos/scripts/eosio_build_ubuntu.sh文件,注释掉455-472行,即从if ! mkdir "${TEMP_DIR}/llvm-compiler" 2>/dev/null到fi行。再执行如下命令:
mkdir -p /tmp/llvm-compiler
cd /tmp/llvm-compiler
git clone --depth 1 --single-branch --branch release_40https://github.com/llvm-mirror/llvm.git
之后重新执行编译命令
cd ~/eos
sudo ./eosio_build.sh
5.出现eos字样,继续执行安装脚本
./eosio_install.sh
编译完成
安装:
cd ~/eos/build
sudo make install
6.验证本地测试链
构建完成后,所有的可执行程序都会放在 build/programs/nodeos 目录下。 我们用下面的命令来创建一个本地测试链:
cd build/programs/nodeos
./nodeos -e -p eosio --plugin eosio::chain_api_plugin --plugin eosio::history_api_plugin
这时终端会打印许多的日志信息。如果新的块被正确生成,那么你可以看到如下的日志
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
...
自动化构建完成
到此为止,源码安装构建EOS完成
7.如果部分失败----验证安装是否成功
1) 运行mongod,在Ubuntu系统中,运行:
~/opt/mongodb/bin/mongod -f ~/opt/mongodb/mongod.conf &
输出内容:[1] 37671
2)检验eosio是否安装成功命令
eos/build$ make test
显示类似如下效果
Start 1: test_cypher_suites
1/50 Test #1: test_cypher_suites ................... Passed 0.67 sec
Start 2: validate_simple.token_abi
2/50 Test #2: validate_simple.token_abi ............ Passed 0.31 sec
Start 3: validate_eosio.token_abi
3/50 Test #3: validate_eosio.token_abi ............. Passed 0.08 sec
Start 4: validate_eosio.msig_abi
4/50 Test #4: validate_eosio.msig_abi .............. Passed 0.20 sec
Start 5: validate_eosio.sudo_abi
5/50 Test #5: validate_eosio.sudo_abi .............. Passed 0.07 sec
Start 6: validate_multi_index_test_abi
6/50 Test #6: validate_multi_index_test_abi ........ Passed 0.07 sec
Start 7: validate_snapshot_test_abi
7/50 Test #7: validate_snapshot_test_abi ........... Passed 0.08 sec
Start 8: validate_eosio.system_abi
8/50 Test #8: validate_eosio.system_abi ............ Passed 0.03 sec
8.验证本地测试链
cd ~/eos/build/programs/nodeos
运行如下命令
./nodeos -e -p eosio --plugin eosio::chain_api_plugin --plugin eosio::history_api_plugin
显示如下效果
1672402ms thread-0 chain_plugin.cpp:208 plugin_initialize ] initializing chain plugin
1672402ms thread-0 chain_plugin.cpp:391 plugin_initialize ] Starting up fresh blockchain with default genesis state.
CHAINBASE: Failed to pin chainbase shared memory (of size 1024 MB) in RAM. Performance degradation is possible.
CHAINBASE: Failed to pin chainbase shared memory (of size 340 MB) in RAM. Performance degradation is possible.
1672457ms thread-0 http_plugin.cpp:290 plugin_initialize ] configured http to listen on 127.0.0.1:8888
1672458ms thread-0 net_plugin.cpp:2947 plugin_initialize ] Initialize net plugin
1672458ms thread-0 net_plugin.cpp:2971 plugin_initialize ] host: 0.0.0.0 port: 9876
1672458ms thread-0 net_plugin.cpp:3043 plugin_initialize ] my node_id is dd1b4640288cfefc56f90bc02f92b7ddd5f8e2e6f1d46d0422f7a5f43dafce8e
1672459ms thread-0 main.cpp:104 main ] nodeos version c9b7a247
1672459ms thread-0 main.cpp:105 main ] eosio root is /home/duncanwang/.local/share
1672459ms thread-0 controller.cpp:1190 startup ] No head block in fork db, perhaps we need to replay
1672459ms thread-0 controller.cpp:304 initialize_fork_db ] Initializing new blockchain with genesis state
1672496ms thread-0 chain_plugin.cpp:446 plugin_startup ] starting chain in read/write mode
1672496ms thread-0 chain_plugin.cpp:451 plugin_startup ] Blockchain started; head block is #1, genesis timestamp is 2018-06-01T12:00:00.000
1672496ms thread-0 http_plugin.cpp:331 plugin_startup ] start listening for http requests
到此源码编译EOS自动化构建完成
利用Docker搭建EOS本地测试网络
1.安装
安装翻墙工具会大大提高安装速度:
蓝灯linux版本:
32位 https://raw.githubusercontent.com/getlantern/lantern-binaries/master/lantern-installer-beta-32-bit.deb
64位 https://raw.githubusercontent.com/getlantern/lantern-binaries/master/lantern-installer-beta-64-bit.deb
①由于apt官方库里的docker版本可能比较旧,所以先卸载可能存在的旧版本:
$ sudo apt-get remove docker docker-engine docker-ce docker.io
②更新apt包索引:
$ sudo apt-get update
若执行时出现
Could not wait for server fd - select (11: 资源暂时不可用) [IP: 13.33.172.150 443]
正在读取软件包列表... 完成
E: 仓库'http://dl.google.com/linux/chrome/deb stable Release'将其'Origin'值从'Google, Inc.'修改到了'Google LLC'
解决方案:
1,打开 /etc/apt/sources.list.d/google-chrome.list 文件(用vim或者gedit等均可):
sudo vim /etc/apt/sources.list.d/google-chrome.list
2,修改文件内容:
原来是: deb http://dl.google.com/linux/chrome/deb/ stable main
改为:
deb [arch=amd64] http://dl.google.com/linux/chrome/deb/ stable main
3,再次执行 更新命令即可通过了
sudo apt-get update
③安装以下包以使apt可以通过HTTPS使用存储库(repository):
$ sudo apt-get install -y apt-transport-https ca-certificates curl software-properties-common
④添加Docker官方的GPG密钥:
$ curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add -
坑:如果提示gpg: 找不到有效的 OpenPGP 数据。先添加pgp key
gpg --keyserver pgpkeys.mit.edu --recv-key 9AA38DCD55BE302B
完成之后再执行 curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add -
即可成功
⑤使用下面的命令来设置stable存储库:
$ sudo add-apt-repository "deb [arch=amd64] https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable"
如果不可用,使用下面命令:
$ add-apt-repository "deb [arch=amd64] https://download.docker.com/linux/ubuntu artful stable"
⑥再更新一下apt包索引:
$ sudo apt-get update
遇到sudo apt-get update 错误时,一般考虑是源的问题,更换其他的源多试一试
⑦安装最新版本的Docker CE:
$ sudo apt-get install -y docker-ce
由于受电脑性能影响,安装过程较慢请耐心等待
2.验证docker
①查看docker服务是否启动:
$ systemctl status docker
②若未起动,则起动docker服务
$ sudo systemctl start docker
③运行 $ sudo docker run hello-world
成功输出Hello from Docker!则安装成功
3.安装docker-compose
①curl安装
# curl -L https://github.com/docker/compose/releases/download/1.7.1/docker-compose-`uname -s`-`uname -m` > /usr/local/bin/docker-compose
# chmod +x /usr/local/bin/docker-compose
# docker-compose --vesion 出现对应版本
Eos利用Docker下载
1、获取eos docker镜像
docker pull eosio/eos-dev
这一步需要一些时间来下载:
看到类似输出则下载成功
Using default tag: latest
latest: Pulling from eosio/eos-dev
6b98dfc16071: Pull complete
4001a1209541: Pull complete
6319fc68c576: Pull complete
b24603670dc3: Pull complete
97f170c87c6f: Pull complete
989c07c6edff: Pull complete
3cb5f57fd105: Pull complete
17e8c5aa3340: Pull complete
865a94241630: Pull complete
78c0dba4c581: Pull complete
80dfca640586: Pull complete
e56cf35e4a67: Pull complete
ec1eb8c6a441: Pull complete
60082656dfd0: Pull complete
d9c0344e2d4b: Pull complete
0465ab22c0f0: Pull complete
7967d8f0278f: Pull complete
Digest: sha256:e64ca620fe1adac673958bbb891d970c4f0324c8c08cfdcd175e88ae33a34d0b
Status: Downloaded newer image for eosio/eos-dev:latest
2、启动EOSIO节点 ---此处有一坑
sudo docker run --name aaa -d -p 8888:8888 -p 9876:9876 -v /tmp/work:/work -v /tmp/eosio/data:/mnt/dev/data -v /tmp/eosio/config:/mnt/dev/config eosio/eos-dev /bin/bash -c "nodeos -e -p eosio --plugin eosio::wallet_api_plugin --plugin eosio::wallet_plugin --plugin eosio::producer_plugin --plugin eosio::history_plugin --plugin eosio::chain_api_plugin --plugin eosio::history_api_plugin --plugin eosio::http_plugin -d /mnt/dev/data --config-dir /mnt/dev/config --http-server-address=0.0.0.0:8888 --access-control-allow-origin=* --contracts-console"
启动正常情况下,返回一个容器ID:
a87cd84752d593dd1aac1dda18c5281a96689349fd421587bd923c247bcf98aa
3.验证节点通信
sudo docker logs --tail 10 eosio
此时出现unable to find plugin: eosio::wallet_api_plugin问题,研究发现参考资料https://www.jianshu.com/p/d44efb18a346中有问题,不能走通
本来以为源码编译与利用Docker编译有冲突,两者其实是在不同环境中跑的,并未相互影响。
回到第二步;
2.第二步: 创建网络
为nodeos和keosd来创建网络连接
$ docker network create eosdev
执行命令会有如下输出 33d25b8c240093fc75d3f7086b23f2398767e1e7fcdf2b64b672e02a38871e9a
检查网络的列表可以看到eosdev网络
K ID NAME DRIVER SCOPE
b9277a66174b bridge bridge local
a01f6648238b eosdev bridge local
0192a14d006a host host local
6340b48dcc96 none null local
第三步: 启动容器
$ docker run --name nodeos -d -p 8888:8888 --network eosdev \
-v /tmp/eosio/work:/work -v /tmp/eosio/data:/mnt/dev/data \
-v /tmp/eosio/config:/mnt/dev/config eosio/eos-dev \
/bin/bash -c "nodeos -e -p eosio --plugin eosio::producer_plugin \
--plugin eosio::history_plugin --plugin eosio::chain_api_plugin \
--plugin eosio::history_api_plugin \
--plugin eosio::http_plugin -d /mnt/dev/data \
--config-dir /mnt/dev/config \
--http-server-address=0.0.0.0:8888 \
--access-control-allow-origin=* --contracts-console --http-validate-host=false"
输出
de2e8ffec9ee2920577381c6c88de6e3dd6405b035bc3b7da96de753fe62173
在这里解释一下上面的启动命令做了哪些设置
设置转发端口为 8888。
将nodeos连接到上一步创建的eosdev本地网络。
将docker容器里的3个文件夹连接到本地硬盘。
在Bash里启动Nodeos,并加载默认的插件,配置服务器地址,启用跨域访问以及加入合约调试功能
将一些目录挂载到本能/tmp文件夹下,这样在docker里可以持久化这些目录。
启动Keosd钱包管理程序
docker run -d --name keosd --network=eosdev \-i eosio/eos-dev /bin/bash -c "keosd --http-server-address=0.0.0.0:9876"
输出 9f36f15bcadb9068f7b305054a21c807dbc867acb1778c4130f698337f032830
第四步; 验证安装
检查Nodeos 是否在生产新的块
运行docker logs --tail 10 nodeos
正常情况会看到如下日志信息
1929001ms thread-0 producer_plugin.cpp:585 block_production_loo ] Produced block 0000366974ce4e2a... #13929 @ 2018-05-23T16:32:09.000 signed by eosio [trxs: 0, lib: 13928, confirmed: 0]
1929502ms thread-0 producer_plugin.cpp:585 block_production_loo ] Produced block 0000366aea085023... #13930 @ 2018-05-23T16:32:09.500 signed by eosio [trxs: 0, lib: 13929, confirmed: 0]
1930002ms thread-0 producer_plugin.cpp:585 block_production_loo ] Produced block 0000366b7f074fdd... #13931 @ 2018-05-23T16:32:10.000 signed by eosio [trxs: 0, lib: 13930, confirmed: 0]
1930501ms thread-0 producer_plugin.cpp:585 block_production_loo ] Produced block 0000366cd8222adb... #13932 @ 2018-05-23T16:32:10.500 signed by eosio [trxs: 0, lib: 13931, confirmed: 0]
1931002ms thread-0 producer_plugin.cpp:585 block_production_loo ] Produced block 0000366d5c1ec38d... #13933 @ 2018-05-23T16:32:11.000 signed by eosio [trxs: 0, lib: 13932, confirmed: 0]
1931501ms thread-0 producer_plugin.cpp:585 block_production_loo ] Produced block 0000366e45c1f235... #13934 @ 2018-05-23T16:32:11.500 signed by eosio [trxs: 0, lib: 13933, confirmed: 0]
1932001ms thread-0 producer_plugin.cpp:585 block_production_loo ] Produced block 0000366f98adb324... #13935 @ 2018-05-23T16:32:12.000 signed by eosio [trxs: 0, lib: 13934, confirmed: 0]
1932501ms thread-0 producer_plugin.cpp:585 block_production_loo ] Produced block 00003670a0f01daa... #13936 @ 2018-05-23T16:32:12.500 signed by eosio [trxs: 0, lib: 13935, confirmed: 0]
1933001ms thread-0 producer_plugin.cpp:585 block_production_loo ] Produced block 00003671e8b36e1e... #13937 @ 2018-05-23T16:32:13.000 signed by eosio [trxs: 0, lib: 13936, confirmed: 0]
1933501ms thread-0 producer_plugin.cpp:585 block_production_loo ] Produced block 0000367257fe1623... #13938 @ 2018-05-23T16:32:13.500 signed by eosio [trxs: 0, lib: 13937, confirmed: 0]
打印十条日志信息
检查钱包
登录keosd这个容器
登录成功后输入 root@c200799b40c9:/# cleos --wallet-url http://127.0.0.1:9876 wallet list keys
如果你看到这样的输出
Wallets:
[]
Error 3120006: No available wallet
Ensure that you have created a wallet and have it open 那么keosd是正常运行的
检查完毕请输入exit推出容器,回到本机。后面的命令都是在本机命令行执行。
检查 Nodeos 的访问端口
可以通过下列方法之一可以验证RPC的API端口是否正常工作
浏览器里访问由chain_api_plugin提供的get_info方法
http://localhost:8888/v1/chain/get_info
在命令行里输入
curl http://localhost:8888/v1/chain/get_info
如果端口工作正常的话应当能看到如下的输出
{
"server_version": "0f6695cb",
"chain_id": "cf057bbfb72640471fd910bcb67639c22df9f92470936cddc1ade0e2f2e7dc4f",
"head_block_num": 2877,
"last_irreversible_block_num": 2876,
"last_irreversible_block_id": "00000b3ca07ced4ecea4002ed1d5d306cac69a45fc61e818e0a0dedf1cb85da1",
"head_block_id": "00000b3d2a5ec2b770210b16bf94db0213be5bbd1fba0256654342ded3d54ef6",
"head_block_time": "2018-09-20T06:58:58.000",
"head_block_producer": "eosio",
"virtual_block_cpu_limit": 3545316,
"virtual_block_net_limit": 18623536,
"block_cpu_limit": 199900,
"block_net_limit": 1048576,
"server_version_string": "v1.3.0"
}
第五步: 为Cleos(交互终端)创建快捷方式
通常我们不会每一次使用 Nodes 和 Keosd 的时候都登录容器来进行操作,我们可以创建一些快捷方式来让这些操作变得便捷一些:
首先我们需要寻找keosd的IP地址。输入命令查看网络状况
$ docker network inspect eosdev
[
{
"Name": "eosdev",
"Id": "a01f6648238b28f4963623ebfbc87f23bf348c1cf715b3606b94ea99b46e4a3b",
"Created": "2018-11-07T19:01:45.013003389+08:00",
"Scope": "local",
"Driver": "bridge",
"EnableIPv6": false,
"IPAM": {
"Driver": "default",
"Options": {},
"Config": [
{
"Subnet": "172.18.0.0/16",
"Gateway": "172.18.0.1"
}
]
},
"Internal": false,
"Attachable": false,
"Ingress": false,
"ConfigFrom": {
"Network": ""
},
"ConfigOnly": false,
"Containers": {
"820d78e0a8cdd19743a03c667bedaef607dc9b0336624f54171702cd77565a3d": {
"Name": "nodeos",
"EndpointID": "4eaa6e2008297d07bf931b08ba63c6e723cd1e1c70b4694e86fe729db5c16922",
"MacAddress": "02:42:ac:12:00:02",
"IPv4Address": "172.18.0.2/16",
"IPv6Address": ""
},
"9f36f15bcadb9068f7b305054a21c807dbc867acb1778c4130f698337f032830": {
"Name": "keosd",
"EndpointID": "209571f943a9b169ea6c2a61db6b6222b45c9224c14db4551017d4e96a0b68d4",
"MacAddress": "02:42:ac:12:00:03",
"IPv4Address": "172.18.0.3/16",
"IPv6Address": ""
}
},
"Options": {},
"Labels": {}
}
]
从上面的输出可以看到 keosd 容器的IPv4地址是 172.20.0.3。接着在系统里设置一下快捷方式。
alias cleos='docker exec -it nodeos /opt/eosio/bin/cleos --url http://127.0.0.1:8888 --wallet-url http://172.20.0.3:9876'
这里cleos命令实际上是运行了nodeos这个容器里的cleos命令。因此--url设置为127.0.0.1即本容器的8888端口,而--wallet-url指向的是keosd这个容器
测试一下快捷方式是不是可以正常工作
$ cleos version client
Build version: 11c25394
关闭运行的容器可以使用 docker stop [container id]
恭喜你,已经成功的通过Docker来搭建本地EOS测试链了