前言
接上一篇通过eosio_build.sh脚本安装EOS,其实EOS官方更推荐我们使用Docker来安装(EOS官方已经把编译好的镜像文件上传到Docker公共仓库中),简单快速,且不用趟编译过程中的各种依赖坑,所以在此墙裂推荐一下。
一、安装Docker
参见我的另一篇文章:在Ubuntu下安装Docker https://www.linuxidc.com/Linux/2018-09/154498.htm
二、安装EOS
通过Docker安装EOS,安装过程非常简单,只需要从官方拉取一个image即可,安装时间在10分钟不等。
1、拉取EOS官方Docker image
$ docker pull eosio/eos-dev
Using default tag: latest
latest: Pulling from eosio/eos-dev
a48c500ed24e: Pulling fs layer
1e1de00ff7e1: Pulling fs layer
0330ca45a200: Pulling fs layer
471db38bcfbf: Pull complete
0b4aba487617: Pull complete
c48089e40a92: Pull complete
6ba3b1cb9ec5: Pull complete
fc42d6567ea7: Pull complete
5aad39598cd9: Pull complete
3289b843cc06: Pull complete
7fce24403a03: Pull complete
693e3de53a75: Pull complete
3eba792bc608: Pull complete
beb224e3e4ff: Pull complete
8be9106d93b3: Pull complete
e68cf64b358f: Pull complete
678c68b82b10: Pull complete
c0fbf552019c: Pull complete
e46f8cadc969: Pull complete
c5bde327188d: Pull complete
Digest: sha256:9994635121c24a82f0028e716941c65908449e2a3e4b5705b14d5642afa3accd
Status: Downloaded newer image for eosio/eos-dev:latest
2、启动EOSIO节点
$ sudo docker run –rm –name eosio -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:
2e1a3574dd2908645843152e5d561af53f3ffa777a99d6ecdd152f5a91230f6f
三、验证节点通信
1、检查节点是否已经正常工作:
$ sudo docker logs –tail 10 eosio
正常情况下输出的内容应该类似于这样:
212500ms thread-0 producer_plugin.cpp:1087 produce_block ] Produced block 000000ac1a243dd1… #172 @ 2018-07-05T04:03:32.500 signed by eosio [trxs: 0, lib: 171, confirmed: 0]
213000ms thread-0 producer_plugin.cpp:1087 produce_block ] Produced block 000000ad12ef4cd0… #173 @ 2018-07-05T04:03:33.000 signed by eosio [trxs: 0, lib: 172, confirmed: 0]
213500ms thread-0 producer_plugin.cpp:1087 produce_block ] Produced block 000000aef4292764… #174 @ 2018-07-05T04:03:33.500 signed by eosio [trxs: 0, lib: 173, confirmed: 0]
214000ms thread-0 producer_plugin.cpp:1087 produce_block ] Produced block 000000af2bf08a6b… #175 @ 2018-07-05T04:03:34.000 signed by eosio [trxs: 0, lib: 174, confirmed: 0]
214500ms thread-0 producer_plugin.cpp:1087 produce_block ] Produced block 000000b0fb442f21… #176 @ 2018-07-05T04:03:34.500 signed by eosio [trxs: 0, lib: 175, confirmed: 0]
215000ms thread-0 producer_plugin.cpp:1087 produce_block ] Produced block 000000b18f90a938… #177 @ 2018-07-05T04:03:35.000 signed by eosio [trxs: 0, lib: 176, confirmed: 0]
215500ms thread-0 producer_plugin.cpp:1087 produce_block ] Produced block 000000b25c380b9c… #178 @ 2018-07-05T04:03:35.500 signed by eosio [trxs: 0, lib: 177, confirmed: 0]
216000ms thread-0 producer_plugin.cpp:1087 produce_block ] Produced block 000000b33b225011… #179 @ 2018-07-05T04:03:36.000 signed by eosio [trxs: 0, lib: 178, confirmed: 0]
216500ms thread-0 producer_plugin.cpp:1087 produce_block ] Produced block 000000b432badfcf… #180 @ 2018-07-05T04:03:36.500 signed by eosio [trxs: 0, lib: 179, confirmed: 0]
217000ms thread-0 producer_plugin.cpp:1087 produce_block ] Produced block 000000b5b315cf60… #181 @ 2018-07-05T04:03:37.000 signed by eosio [trxs: 0, lib: 180, confirmed: 0]
2、在浏览器中查看节点信息:
在浏览器地址栏访问 http://localhost:8888/v1/chain/get_info,检查RPC接口是否正常工作,正常情况下会显示:
{
“server_version”: “5875549c”,
“chain_id”: “cf057bbfb72640471fd910bcb67639c22df9f92470936cddc1ade0e2f2e7dc4f”,
“head_block_num”: 2233,
“last_irreversible_block_num”: 2232,
“last_irreversible_block_id”: “000008b872290cc75b8cb68b836a82ff87a1cc39b75f88341765f68bc925a623”,
“head_block_id”: “000008b9c9c9c11ee3e4c95613c971861788f7e80a82e20bcad0c2ef622aa7be”,
“head_block_time”: “2018-07-05T04:20:43.000”,
“head_block_producer”: “eosio”,
“virtual_block_cpu_limit”: 1861596,
“virtual_block_net_limit”: 9777935,
“block_cpu_limit”: 199900,
“block_net_limit”: 1048576
}
以上信息我们还可以通过cleos get info命令查看到。
至此,我们就在Docker容器中成功地运行了一个EOS节点区块链!
四、客户端配置
1、在docker下使用cleos客户端,我们需要以Docker的命令方式来运行,且需要带命令的完整路径
,如/opt/eosio/bin/cleos,为了后续操作方便,我们给cleos命令配置一下别名:
alias cleos=’docker exec eosio /opt/eosio/bin/cleos –wallet-url http://localhost:8888′
我们试着在终端测试一下是否生效:
$ cleos –help
看到命令的相关参数信息就说明已经可以运行生效了。
2、关闭节点运行
$ docker stop eosio
之前使用eosio_build.sh脚本的安装方式时,只能粗暴的按Ctrl+C中断节点,有了Docker后,就能优雅地关闭节点了。
参考:
https://developers.eos.io/eosio-nodeos/docs/docker-quickstart EOS官方开发文档
本文永久更新链接地址:https://www.linuxidc.com/Linux/2018-09/154499.htm