EOS · 2018年10月31日 1

使用Docker安装EOS单节点环境

简介

本文将再centos7下使用Docker搭建eos单节点环境,使用官方提供的eos-dev镜像;此篇主要是为后续多节点环境搭建做铺垫。

docker与docker-compose

$ yum install docker
$ yum install curl
# docker-compose的版本可以再github中查看
$ curl -L https://github.com/docker/compose/releases/download/1.22.0/docker-compose-`uname -s`-`uname -m` -o /usr/local/bin/docker-compose
$ sudo chmod 755 /usr/local/bin/docker-compose
# 启动docker 
$ systemctl start docker
# 设置开机启动docker服务
$ systemctl enable docker

构建容器与网络

网络与镜像

# 下载docker镜像
$ docker pull eosio/eos-dev:v1.4.1
# 创建docker网络
$ docker network create eosdev
# 查看docker网络
$ docker network inspect eosdev

nodeos容器

以上准备工作完成以后就可以创建并启动容器了:

$ docker run \
  --name nodeos1 -d -p 8888:8888 \
  --network eosdev \
  --ip 172.18.0.11 \
  --privileged=true \
  -v /home/eosio/nodeos1/work:/work \
  -v /home/eosio/nodeos1/data:/mnt/dev/data \
  -v /home/eosio/nodeos1/config:/mnt/dev/config \
  eosio/eos-dev \
  /bin/bash -c \
  "nodeos -d /mnt/dev/data --config-dir /mnt/dev/config"

这里是设置容器的配置比如名称、端口、映射文件、网络、启动命令等。我移除官方教程中的一些配置等信息,eos启动参数等(这些内容我们将会使用config.ini配置)。以上信息是可以再容器启动后再次修改的,所以配置错了也没关系,可以学习一下docker容器如何修改配置信息,亦或者把容器删了再来一次。


docker容器的信息在/var/lib/docker/containers,在这里找到docker容器的列表,再关闭docker服务的情况下可以修改以下文件,达到配置容器的作用。

/var/lib/docker/containers/ac6e0d75c4beda1a573ee82409f2aa2802cfb300d5d8c845136353b43449bd0f/config.v2.json
/var/lib/docker/containers/ac6e0d75c4beda1a573ee82409f2aa2802cfb300d5d8c845136353b43449bd0f/hostconfig.json

再修改之前必须将docker停掉,注意不是停止容器是停止docker

$ systemctl stop docker

keosd容器

有了eos-nodeos节点,还需要一个keosd钱包服务,这只需要一个就好:

$ docker run -d --name keosd \
  --network=eosdev \
  --ip 172.18.0.10 \
  -i eosio/eos-dev /bin/bash -c "keosd --http-server-address=0.0.0.0:9876"

查看创建完成的容器:

$ docker ps -a
CONTAINER ID        IMAGE               COMMAND                  CREATED             STATUS              PORTS                    NAMES
6814412dc205        eosio/eos-dev       "/bin/bash -c 'nod..."   13 seconds ago      Up 11 seconds       0.0.0.0:8888->8888/tcp   nodeos1
6c5265fa4b84        eosio/eos-dev       "/bin/bash -c 'keo..."   4 minutes ago       Up 4 minutes                                 keosd

顺利的话会是以下情况:

$ docker logs --tail 10 nodeos1
info  2018-10-31T08:05:57.779 thread-0  main.cpp:110                  main                 ] nodeos version v1.4.2
info  2018-10-31T08:05:57.779 thread-0  main.cpp:111                  main                 ] eosio root is /root/.local/share
error 2018-10-31T08:05:57.779 thread-0  controller.cpp:1596           startup              ] No head block in fork db, perhaps we need to replay
warn  2018-10-31T08:05:57.779 thread-0  controller.cpp:574            initialize_fork_db   ]  Initializing new blockchain with genesis state                  
info  2018-10-31T08:05:57.806 thread-0  chain_plugin.cpp:707          plugin_startup       ] starting chain in read/write mode
info  2018-10-31T08:05:57.806 thread-0  chain_plugin.cpp:711          plugin_startup       ] Blockchain started; head block is #1, genesis timestamp is 2018-06-01T12:00:00.000
info  2018-10-31T08:05:57.806 thread-0  http_plugin.cpp:486           plugin_startup       ] start listening for http requests
info  2018-10-31T08:05:57.807 thread-0  net_plugin.cpp:3017           plugin_startup       ] starting listener, max clients is 25
info  2018-10-31T08:05:57.807 thread-0  producer_plugin.cpp:714       plugin_startup       ] producer plugin:  plugin_startup() begin
info  2018-10-31T08:05:57.807 thread-0  producer_plugin.cpp:748       plugin_startup       ] producer plugin:  plugin_startup() end

容器启动失败的情况

如果nodeos1启动失败,提示can not read options configuration file '/mnt/dev/config/config.ini'

$ docker logs --tail 10 nodeos1
error 2018-10-31T08:00:58.680 thread-0  main.cpp:136                  main                 ] Throw location unknown (consider using BOOST_THROW_EXCEPTION)
Dynamic exception type: boost::exception_detail::clone_impl<boost::exception_detail::error_info_injector<boost::program_options::reading_file> >
std::exception::what: can not read options configuration file '/mnt/dev/config/config.ini'

这是容器内权限不够,需要给当前容器配置privileged=true可以解决。

配置nodeos节点

之前大家肯定都有配置了解过config.ini,这里就不多说了,将修改好的配置文件放入我们映射的docker目录/home/eosio/nodeos1/config/config.ini即可。以下是除去默认配置之外需要修改的项:

....
....
p2p-listen-endpoint = 0.0.0.0:8288
# 当部署多节点时,配置此项连接其他节点,注意如果都是docker内的节点,则要输入docker network的ip与端口。
# p2p-peer-address = 172.18.0.5:8299

http-server-address = 0.0.0.0:8888

enable-stale-production = true 
producer-name = eosio 
plugin = eosio::producer_plugin
plugin = eosio::chain_api_plugin
plugin = eosio::http_plugin
plugin = eosio::history_api_plugin
plugin = eosio::bnet_plugin

http-validate-host = 0

ccess-control-allow-origin = *
verbose-http-errors = true
filter-on = *
contracts-console = true

chain-state-db-size-mb = 10240

agent-name = "EOS Test Agent8888"

再修改之前先停止容器,修改完成再次启动,命令如下:

$ docker stop nodeos1
$ docker start nodeos1

启动后再次查看nodeos1的日志:

$ docker logs --tail 10 nodeos1
warn  2018-10-31T08:40:55.661 thread-0  bnet_plugin.cpp:1373          plugin_startup       ] bnet startup 
warn  2018-10-31T08:40:55.662 thread-1  bnet_plugin.cpp:1425          operator()           ] start thread
info  2018-10-31T08:40:55.662 thread-0  net_plugin.cpp:3017           plugin_startup       ] starting listener, max clients is 25
info  2018-10-31T08:40:56.001 thread-0  producer_plugin.cpp:1490      produce_block        ] Produced block 000000028c4a8016... #2 @ 2018-10-31T08:40:56.000 signed by eosio [trxs: 0, lib: 0, confirmed: 0]
info  2018-10-31T08:40:56.500 thread-0  producer_plugin.cpp:1490      produce_block        ] Produced block 00000003d1b4d74a... #3 @ 2018-10-31T08:40:56.500 signed by eosio [trxs: 0, lib: 2, confirmed: 0]
info  2018-10-31T08:40:57.001 thread-0  producer_plugin.cpp:1490      produce_block        ] Produced block 000000040e6116d3... #4 @ 2018-10-31T08:40:57.000 signed by eosio [trxs: 0, lib: 3, confirmed: 0]
info  2018-10-31T08:40:57.501 thread-0  producer_plugin.cpp:1490      produce_block        ] Produced block 0000000523e1921f... #5 @ 2018-10-31T08:40:57.500 signed by eosio [trxs: 0, lib: 4, confirmed: 0]
info  2018-10-31T08:40:58.001 thread-0  producer_plugin.cpp:1490      produce_block        ] Produced block 00000006920c9016... #6 @ 2018-10-31T08:40:58.000 signed by eosio [trxs: 0, lib: 5, confirmed: 0]
info  2018-10-31T08:40:58.501 thread-0  producer_plugin.cpp:1490      produce_block        ] Produced block 00000007cf2bdf91... #7 @ 2018-10-31T08:40:58.500 signed by eosio [trxs: 0, lib: 6, confirmed: 0]
info  2018-10-31T08:40:59.001 thread-0  producer_plugin.cpp:1490      produce_block        ] Produced block 00000008b1ccb681... #8 @ 2018-10-31T08:40:59.000 signed by eosio [trxs: 0, lib: 7, confirmed: 0]

已经开始产生区块了。
单节点的配置就到此为止了。

使用方法

如果要使用keosd或者cleos的功能,进入到容器内执行命令即可:

$ docker exec -it keosd bash
# 使用上边的命令进入容器内后,就和普通的环境是一样的直接使用cleos即可
$ cleos --wallet-url http://127.0.0.1:9876 wallet list keys
[]
Error 3120006: No available wallet
Ensure that you have created a wallet and have it open

不过这样略显麻烦,可以使用alias定义命令的别名:

alias cleos='docker exec -it nodeos1 /opt/eosio/bin/cleos --url http://127.0.0.1:8888 --wallet-url http://172.18.0.10:9876' 

这样就和普通使用没什么区别了。

.
.
.
.
.
.
【本文章出自NM1024.com,转载请注明作者出处。】






>>转载请注明原文链接地址:使用Docker安装EOS单节点环境