本教程介绍如何配置在多个主机上运行多个节点的EOSIO私链网络,即多主机多节点EOS私链网络,我们将在本地计算机上配置四个节点,并让它们互相通信,其中三个节点产快,一个节点非产快,主要会用到三个程序nodeos、keosd、cleos,以下是该私链网络结构图:
在第一个节点上,我们启动eos进程时启动钱包插件,在这个私有网络上我们使用这个节点上钱包。
第一个节点配置如下:
# The local IP and port to listen for incoming http connections; set blank to disable. (eosio::http_plugin)
http-server-address = 0.0.0.0:9800
# The actual host:port used to listen for incoming p2p connections. (eosio::net_plugin)
p2p-listen-endpoint = 0.0.0.0:9900
# The public endpoint of a peer node to connect to. Use multiple p2p-peer-address options as needed to compose a network. (eosio::net_plugin)
# p2p-peer-address =
p2p-peer-address = 193.112.127.146:9900
p2p-peer-address = 118.126.97.157:9900
p2p-peer-address = 111.230.210.23:9900
producer-name = eosio
# Timeout for unlocked wallet in seconds (default 900 (15 minutes)). Wallets will automatically lock after specified number of seconds of inactivity. Activity is defined as any wallet command e.g. list-wallets. (eosio::wallet_plugin)
unlock-timeout = 90000
# Plugin(s) to enable, may be specified multiple times
# plugin =
plugin = eosio::http_plugin
plugin = eosio::chain_api_plugin
plugin = eosio::net_api_plugin
plugin = eosio::wallet_api_plugin
plugin = eosio::history_api_plugin
主要配置本节点rpc监听地址,p2p监听地址,p2p连接地址,bp名称,因为启动有钱包插件,配置了钱包锁定的超时时间,同时加载了需要使用的插件,我们在这个节点加载钱包插件。
启动第一个节点:
nohup nodeos --enable-stale-production --data-dir /opt/tangy/eos.io/node1/data --config-dir /opt/tangy/eos.io/node1/config &
这种启动方式将nodeos放入后台运行,同时日志输出到nohup.out,检查日志以检查nodeos是否正确启动。--enable-stale-production表明该节点启动后进行产快。这一步创建了一个特殊的bp,实际上其创建了一个新的EOS网络。
创建一个默认钱包,记下钱包密码
[kingnet@pdev3 config]$ cleos --wallet-url http://localhost:9800 wallet create
Creating wallet: default
Save password to use in the future to unlock this wallet.
Without password imported keys will not be retrievable.
"PW5HpgLDiM7CPAeJYKpY4CjSoW1kwaH5Xkz6K48hRP4MARqRrBdHR"
加载bios合约
cleos --wallet-url http://localhost:9800 --url http://localhost:9800 set contract eosio /opt/tangy/eos.io/eos/build/contracts/eosio.bios/
创建后面三个节点使用的账户,分别为inita,initb,initc.
cleos --wallet-url http://localhost:9800 --url http://localhost:9800 create account eosio inita EOS6MRyAjQq8ud7hVNYcfnVPJqcVpscN5So8BhtHuGYqET5GDW5CV EOS6MRyAjQq8ud7hVNYcfnVPJqcVpscN5So8BhtHuGYqET5GDW5CV
cleos --wallet-url http://localhost:9800 --url http://localhost:9800 create account eosio initb EOS6MRyAjQq8ud7hVNYcfnVPJqcVpscN5So8BhtHuGYqET5GDW5CV EOS6MRyAjQq8ud7hVNYcfnVPJqcVpscN5So8BhtHuGYqET5GDW5CV
cleos --wallet-url http://localhost:9800 --url http://localhost:9800 create account eosio initc EOS6MRyAjQq8ud7hVNYcfnVPJqcVpscN5So8BhtHuGYqET5GDW5CV EOS6MRyAjQq8ud7hVNYcfnVPJqcVpscN5So8BhtHuGYqET5GDW5CV
我们没有重新创建新的key用来创建账户,我们为了方便全是使用了同一个key。
以下操作在第二个节点上进行,在第二个节点不需要加载钱包插件。
第二个节点配置如下:
# The local IP and port to listen for incoming http connections; set blank to disable. (eosio::http_plugin)
http-server-address = 0.0.0.0:9800
# The actual host:port used to listen for incoming p2p connections. (eosio::net_plugin)
p2p-listen-endpoint = 0.0.0.0:9900
# The public endpoint of a peer node to connect to. Use multiple p2p-peer-address options as needed to compose a network. (eosio::net_plugin)
# p2p-peer-address =
p2p-peer-address = 118.126.99.34:9900
p2p-peer-address = 118.126.97.157:9900
p2p-peer-address = 111.230.210.23:9900
# ID of producer controlled by this node (e.g. inita; may specify multiple times) (eosio::producer_plugin)
producer-name = inita
# Plugin(s) to enable, may be specified multiple times
# plugin =
plugin = eosio::http_plugin
plugin = eosio::chain_api_plugin
plugin = eosio::net_api_plugin
#plugin = eosio::wallet_api_plugin
#plugin = eosio::account_history_api_plugin
启动第二个节点:
nohup nodeos --data-dir /opt/tangy/eos.io/node1/data --config-dir /opt/tangy/eos.io/node1/config &
该节点启动后不会产快,它会连接其他节点去同步块信息。
我们按照类似的配置和步骤分别在第三个和第四个节点上启动eos。
此时第一个节点产快,而第二、三、四个节点是非BP节点,不产快,现在需要配置BP。
在第一个节点上执行以下BP配置:
cleos --wallet-url=http://localhost:9800 --url=http://localhost:9800 push action eosio setprods '{"version":1, "producers":[{"producer_name":"inita","block_signing_key":"EOS6MRyAjQq8ud7hVNYcfnVPJqcVpscN5So8BhtHuGYqET5GDW5CV"},{"producer_name":"initb","block_signing_key":"EOS6MRyAjQq8ud7hVNYcfnVPJqcVpscN5So8BhtHuGYqET5GDW5CV"},{"producer_name":"initc","block_signing_key":"EOS6MRyAjQq8ud7hVNYcfnVPJqcVpscN5So8BhtHuGYqET5GDW5CV"}]}' -p eosio@active
以上设置将配置第二、三、四节点产快。
检查结果,可以看到inita,initb和initc交叉产快。
[kingnet@pdev2 config]$ cleos --wallet-url http://localhost:9800 --url http://localhost:9800 get info
{
"server_version": "9be89106",
"head_block_num": 2245742,
"last_irreversible_block_num": 2245723,
"last_irreversible_block_id": "0022445be2d0022487ccb8871ba8b0d73e0746b60888507186a8413627cc839f",
"head_block_id": "0022446ef1e494a0fe22bd045f4355c1b37736c5dc0d636e02fc20bc6c7948f0",
"head_block_time": "2018-05-27T10:01:03",
"head_block_producer": "initb",
"virtual_block_cpu_limit": 100000000,
"virtual_block_net_limit": 1048576000,
"block_cpu_limit": 99900,
"block_net_limit": 1048576
}
[kingnet@pdev2 config]$ cleos --wallet-url http://localhost:9800 --url http://localhost:9800 get info
{
"server_version": "9be89106",
"head_block_num": 2245764,
"last_irreversible_block_num": 2245747,
"last_irreversible_block_id": "00224473c141103d8de5e17192db1ad9f901b389d33556ba7839bad0ba62b972",
"head_block_id": "0022448435e88cbc78bb86c4283cb61243f3fc6fe671ad488160db149be3ae2d",
"head_block_time": "2018-05-27T10:01:14",
"head_block_producer": "inita",
"virtual_block_cpu_limit": 100000000,
"virtual_block_net_limit": 1048576000,
"block_cpu_limit": 99900,
"block_net_limit": 1048576
}
[kingnet@pdev2 config]$ cleos --wallet-url http://localhost:9800 --url http://localhost:9800 get info
{
"server_version": "9be89106",
"head_block_num": 2245809,
"last_irreversible_block_num": 2245795,
"last_irreversible_block_id": "002244a374587df48499dce37c64267e1225d22ec9023704f51ecb57f798da84",
"head_block_id": "002244b12ad5b861594b643a8c27070e76910150a3c2216d0336fecc381b021a",
"head_block_time": "2018-05-27T10:01:36",
"head_block_producer": "initb",
"virtual_block_cpu_limit": 100000000,
"virtual_block_net_limit": 1048576000,
"block_cpu_limit": 99900,
"block_net_limit": 1048576
}
[kingnet@pdev2 config]$ cleos --wallet-url http://localhost:9800 --url http://localhost:9800 get info
{
"server_version": "9be89106",
"head_block_num": 2245823,
"last_irreversible_block_num": 2245807,
"last_irreversible_block_id": "002244af6bac069171d4a0c652c6f31c9ea5968db99a67fafd76f1f1c3f0c321",
"head_block_id": "002244bf640043597a13459ce17076a3fac998814323dec542dfb235a6dedc73",
"head_block_time": "2018-05-27T10:01:43",
"head_block_producer": "initc",
"virtual_block_cpu_limit": 100000000,
"virtual_block_net_limit": 1048576000,
"block_cpu_limit": 99900,
"block_net_limit": 1048576
}