搭建一个私有的EOS集群 - 2

多节点的搭建

上一篇 搭建一个私有的EOS集群 搭建了一个单节点的私链,本文将继续介绍多节点的私链搭建。

一台服务器上搭建的多节点

启动keosd和创建钱包

1、启动keosd程序

keosd的配置文件可以参考上一篇文章。

1
keosd -d wallet/data --config-dir wallet/config &

2、创建钱包

1
2
3
4
5
[root@dbl14195 eos]# cleos --wallet-url http://127.0.0.1:8899 wallet create --to-console
Creating wallet: default
Save password to use in the future to unlock this wallet.
Without password imported keys will not be retrievable.
"PW5Juu3fMoX6wK3rV4kMeZToXitspmWLHw3k1zpx7BJ9piBxsoGGv"

如果钱包被锁住,可以通过下面的命令解锁:

1
cleos --wallet-url http://127.0.0.1:8899 wallet unlock -n default --password PW5Juu3fMoX6wK3rV4kMeZToXitspmWLHw3k1zpx7BJ9piBxsoGGv

3、导入初始的eosio的密钥

1
2
[root@dbl14195 eos]# cleos --wallet-url http://127.0.0.1:8899 -u http://127.0.0.1:48888 wallet import --private-key 5KQwrPbwdL6PhXujxW37FSSQZ1JiwsST4cqQzDeyXtP79zkvFD3
imported private key for: EOS6MRyAjQq8ud7hVNYcfnVPJqcVpscN5So8BhtHuGYqET5GDW5CV

启动第一个节点

我们可以使用初始的密钥5KQwrPbwdL6PhXujxW37FSSQZ1JiwsST4cqQzDeyXtP79zkvFD3启动第一个节点。

配置和第一篇文章中的一样:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
# the endpoint upon which to listen for incoming connections (eosio::bnet_plugin)
bnet-endpoint = 0.0.0.0:44321
# 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:48888
# The actual host:port used to listen for incoming p2p connections. (eosio::net_plugin)
p2p-listen-endpoint = 0.0.0.0:49876
producer-name = eosio
signature-provider = EOS6MRyAjQq8ud7hVNYcfnVPJqcVpscN5So8BhtHuGYqET5GDW5CV=KEY:5KQwrPbwdL6PhXujxW37FSSQZ1JiwsST4cqQzDeyXtP79zkvFD3
plugin = eosio::producer_plugin
plugin = eosio::chain_api_plugin
plugin = eosio::http_plugin
plugin = eosio::history_api_plugin
1
nodeos -d eos1/data --config-dir eos1/config &

启动第二个节点

1、首先加载eosio.bios合约

1
2
3
4
5
6
7
[root@dbl14195 eos]# cleos --wallet-url http://127.0.0.1:8899 -u http://127.0.0.1:48888 set contract eosio /data1/eos/eos/build/contracts/eosio.bios
Reading WASM from /data1/eos/eos/build/contracts/eosio.bios/eosio.bios.wasm...
Publishing contract...
executed transaction: d7204ea95bcc9723eb69c231a6cf13adb12820b7973984f80ce35dfb1a834e27 4352 bytes 1688 us
# eosio <= eosio::setcode {"account":"eosio","vmtype":0,"vmversion":0,"code":"0061736d0100000001621260037f7e7f0060057f7e7e7e7e...
# eosio <= eosio::setabi {"account":"eosio","abi":"0e656f73696f3a3a6162692f312e30050c6163636f756e745f6e616d65046e616d650f7065...
warning: transaction executed locally, but may not be confirmed by the network yet ]

这个合约允许你可以直接控制其他账号的资源分配,访问 privileged API。

2、创建新的密钥

1
2
3
[root@dbl14195 eos]# cleos create key --to-console
Private key: 5KcEKvuxxTvShQUCYKT7FKVdA1LJh9CSKTYTCLgCjmmPYL2CjGq
Public key: EOS7mq47SiZVXyw9R3CeGoEsh5YeEtEpmasWL8H14E9a3mrUnbq1B

然后再导入到钱包:

1
cleos --wallet-url http://127.0.0.1:8899 -u http://127.0.0.1:48888 wallet import --private-key 5KcEKvuxxTvShQUCYKT7FKVdA1LJh9CSKTYTCLgCjmmPYL2CjGq

3、创建新的账号

1
2
3
4
[root@dbl14195 eos]# cleos --wallet-url http://127.0.0.1:8899 -u http://127.0.0.1:48888 create account eosio admin1 EOS7mq47SiZVXyw9R3CeGoEsh5YeEtEpmasWL8H14E9a3mrUnbq1B EOS7mq47SiZVXyw9R3CeGoEsh5YeEtEpmasWL8H14E9a3mrUnbq1B
executed transaction: 930cf193cf5604298570ec843d3f25c79157266121638eaaff36a8c3c52de1e1 200 bytes 459 us
# eosio <= eosio::newaccount {"creator":"eosio","name":"admin1","owner":{"threshold":1,"keys":[{"key":"EOS7mq47SiZVXyw9R3CeGoEsh5...
warning: transaction executed locally, but may not be confirmed by the network yet ]

4、配置第二个节点

修改第二个节点的配置文件,处理端口和地址的修改,注意配置下面两个项:

1
2
producer-name = admin1
signature-provider = EOS7mq47SiZVXyw9R3CeGoEsh5YeEtEpmasWL8H14E9a3mrUnbq1B=KEY:5KcEKvuxxTvShQUCYKT7FKVdA1LJh9CSKTYTCLgCjmmPYL2CjGq

如果你查看第二个节点的输出,回发现还是一直由eosio出块,admin1一直是idle的。

5、激活producer

为了激活admin1, 需要注册admin1bios节点, bios节点需要更新producer schedule

1
cleos --wallet-url http://127.0.0.1:8899 -u http://127.0.0.1:48888 push action eosio setprods "{ \"schedule\": [{\"producer_name\": \"admin1\",\"block_signing_key\": \"EOS7mq47SiZVXyw9R3CeGoEsh5YeEtEpmasWL8H14E9a3mrUnbq1B\"}]}" -p eosio@active

查看链的信息:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
[root@dbl14195 eos]# cleos --wallet-url http://127.0.0.1:8899 -u http://127.0.0.1:48888 get info
{
"server_version": "59626f1e",
"chain_id": "6cbecff836a9fa60da53bf97a0a180103b2e76041d4414693d11bf39e2341547",
"head_block_num": 2021,
"last_irreversible_block_num": 2020,
"last_irreversible_block_id": "000007e4da8cfb1df4830984b71a9d01b83bff8838bd0664760cb4a25855e34e",
"head_block_id": "000007e5769882a45e38e3c458868d8c0d7a584a3840985f9da8ec4068ac1ee5",
"head_block_time": "2018-11-23T09:21:09.500",
"head_block_producer": "admin1",
"virtual_block_cpu_limit": 1505902,
"virtual_block_net_limit": 7909266,
"block_cpu_limit": 99900,
"block_net_limit": 1048576,
"server_version_string": "v1.4.4"
}

启动第三个节点

1
2
3
4
5
6
7
8
9
cleos create key --to-console
Private key: 5KKFC7iXX7UNXHfWe7ZyHCadWqU4iTUc2waja5fUmW8i8YFZZ9U
Public key: EOS81Nchk9aYx7Ld7jNQwqXfCJqiSc5Nxg3p6v3Fev8Uq78BzyArZ
cleos --wallet-url http://127.0.0.1:8899 -u http://127.0.0.1:48888 wallet import --private-key 5KKFC7iXX7UNXHfWe7ZyHCadWqU4iTUc2waja5fUmW8i8YFZZ9U
cleos --wallet-url http://127.0.0.1:8899 -u http://127.0.0.1:48888 create account eosio admin2 EOS81Nchk9aYx7Ld7jNQwqXfCJqiSc5Nxg3p6v3Fev8Uq78BzyArZ EOS81Nchk9aYx7Ld7jNQwqXfCJqiSc5Nxg3p6v3Fev8Uq78BzyArZ
cleos --wallet-url http://127.0.0.1:8899 -u http://127.0.0.1:48888 push action eosio setprods "{ \"schedule\": [{\"producer_name\": \"admin1\",\"block_signing_key\": \"EOS7mq47SiZVXyw9R3CeGoEsh5YeEtEpmasWL8H14E9a3mrUnbq1B\"},{\"producer_name\": \"admin2\",\"block_signing_key\": \"EOS81Nchk9aYx7Ld7jNQwqXfCJqiSc5Nxg3p6v3Fev8Uq78BzyArZ\"}]}" -p eosio@active

注意我们设置了两个producer,你可以看到它们轮流出块:

1
2
3
4
5
6
#2971 @ 2018-11-23T09:29:04.500 signed by admin1 [trxs: 0, lib: 2949, conf: 0, latency: 1 ms]
info 2018-11-23T09:29:05.002 thread-0 producer_plugin.cpp:337 on_incoming_block ] Received block 2fe5f94d61b899bc... #2972 @ 2018-11-23T09:29:05.000 signed by admin1 [trxs: 0, lib: 2949, conf: 0, latency: 2 ms]
info 2018-11-23T09:29:05.502 thread-0 producer_plugin.cpp:337 on_incoming_block ] Received block e15dc2b6c7d299b4... #2973 @ 2018-11-23T09:29:05.500 signed by admin1 [trxs: 0, lib: 2949, conf: 0, latency: 2 ms]
info 2018-11-23T09:29:06.000 thread-0 producer_plugin.cpp:1490 produce_block ] Produced block 00000b9e92b7c061... #2974 @ 2018-11-23T09:29:06.000 signed by admin2 [trxs: 0, lib: 2961, confirmed: 12]
info 2018-11-23T09:29:06.500 thread-0 producer_plugin.cpp:1490 produce_block ] Produced block 00000b9f57fc9e40... #2975 @ 2018-11-23T09:29:06.500 signed by admin2 [trxs: 0, lib: 2961, confirmed: 0]
info 2018-11-23T09:29:07.000 thread-0 producer_plugin.cpp:1490 produce_block ] Produced block 00000ba09fc353fc... #2976 @ 2018-11-23T09:29:07.000 signed by admin2 [trxs: 0, lib: 2961, confirmed: 0]

本文介绍了使用eosio.bios 合约创建多个producer的例子,一般用于链启动的时刻。 进一步,你可以使用其他的智能合约,通过投票的方式选举producer。

其他一些cleos参考

创建钱包

1
2
3
4
5
6
7
cleos --wallet-url http://127.0.0.1:8899 wallet create --to-console
Creating wallet: default
Save password to use in the future to unlock this wallet.
Without password imported keys will not be retrievable.
"PW5KTTysN5kLt8g5Kz7JmUzGkQu5GkwfDVdKhiEzCDwDxYGaayDoo"
cleos --wallet-url http://127.0.0.1:8899 wallet unlock -n default --password PW5KTTysN5kLt8g5Kz7JmUzGkQu5GkwfDVdKhiEzCDwDxYGaayDoo

导入eosio的密钥

1
cleos --wallet-url http://127.0.0.1:8899 -u http://127.0.0.1:48888 wallet import --private-key 5KQwrPbwdL6PhXujxW37FSSQZ1JiwsST4cqQzDeyXtP79zkvFD3

导入下列账号的密钥

1
cleos --wallet-url http://127.0.0.1:8899 -u http://127.0.0.1:48888 wallet import --private-key 5JBdJmbN4d3eJ5eC2Cqostnv1bFELVgcgRRLxzw2D7UriWnLJVK

创建下列账号

1
2
3
4
5
6
7
8
9
cleos --wallet-url http://127.0.0.1:8899 -u http://127.0.0.1:48888 create account eosio eosio.token EOS8JiEZKuszbSKS273ekW6p62MEGGYcswfgTTV6eDb2SLJFotZT6
cleos --wallet-url http://127.0.0.1:8899 -u http://127.0.0.1:48888 create account eosio eosio.bpay EOS8JiEZKuszbSKS273ekW6p62MEGGYcswfgTTV6eDb2SLJFotZT6
cleos --wallet-url http://127.0.0.1:8899 -u http://127.0.0.1:48888 create account eosio eosio.msig EOS8JiEZKuszbSKS273ekW6p62MEGGYcswfgTTV6eDb2SLJFotZT6
cleos --wallet-url http://127.0.0.1:8899 -u http://127.0.0.1:48888 create account eosio eosio.names EOS8JiEZKuszbSKS273ekW6p62MEGGYcswfgTTV6eDb2SLJFotZT6
cleos --wallet-url http://127.0.0.1:8899 -u http://127.0.0.1:48888 create account eosio eosio.ram EOS8JiEZKuszbSKS273ekW6p62MEGGYcswfgTTV6eDb2SLJFotZT6
cleos --wallet-url http://127.0.0.1:8899 -u http://127.0.0.1:48888 create account eosio eosio.ramfee EOS8JiEZKuszbSKS273ekW6p62MEGGYcswfgTTV6eDb2SLJFotZT6
cleos --wallet-url http://127.0.0.1:8899 -u http://127.0.0.1:48888 create account eosio eosio.saving EOS8JiEZKuszbSKS273ekW6p62MEGGYcswfgTTV6eDb2SLJFotZT6
cleos --wallet-url http://127.0.0.1:8899 -u http://127.0.0.1:48888 create account eosio eosio.stake EOS8JiEZKuszbSKS273ekW6p62MEGGYcswfgTTV6eDb2SLJFotZT6
cleos --wallet-url http://127.0.0.1:8899 -u http://127.0.0.1:48888 create account eosio eosio.vpay EOS8JiEZKuszbSKS273ekW6p62MEGGYcswfgTTV6eDb2SLJFotZT6

导入智能合约

1
2
3
4
5
6
7
8
9
10
11
12
13
cleos --wallet-url http://127.0.0.1:8899 -u http://127.0.0.1:48888 set contract eosio /data1/eos/eos/build/contracts/eosio.bios -p eosio@active
cleos --wallet-url http://127.0.0.1:8899 -u http://127.0.0.1:48888 set contract eosio.token /data1/eos/eos/build/contracts/eosio.token
cleos --wallet-url http://127.0.0.1:8899 -u http://127.0.0.1:48888 set contract eosio.msig /data1/eos/eos/build/contracts/eosio.msig
cleos --wallet-url http://127.0.0.1:8899 -u http://127.0.0.1:48888 push action eosio.token create '[ "eosio", "10000000000.0000 SYS" ]' -p eosio.token@active
cleos --wallet-url http://127.0.0.1:8899 -u http://127.0.0.1:48888 push action eosio.token issue '[ "eosio", "1000000000.0000 SYS", "memo" ]' -p eosio@active
cleos --wallet-url http://127.0.0.1:8899 -u http://127.0.0.1:48888 set contract eosio /data1/eos/eos/build/contracts/eosio.system -p eosio
cleos --wallet-url http://127.0.0.1:8899 -u http://127.0.0.1:48888 push action eosio setpriv '["eosio.msig", 1]' -p eosio@active

创建新的账号

1
2
3
4
5
6
7
cleos --wallet-url http://127.0.0.1:8899 -u http://127.0.0.1:48888 wallet import --private-key 5KTXFtDCRvo9GkB9tQZTcoygFJCMgNyyXMFddUu9k3o1R2Vm954
cleos --wallet-url http://127.0.0.1:8899 -u http://127.0.0.1:48888 wallet import --private-key 5K5V8eH68nzcmTkzYRWHBvgEtzKo5SJDu57DcrXFmszoHCQnUzF
cleos --wallet-url http://127.0.0.1:8899 -u http://127.0.0.1:48888 system newaccount eosio --transfer admin1 EOS6CrKkykBfRkiqS5kkbhjVHhnQFxf8YuwtVqQgrso4GniesqPcG --stake-net "100000.0000 SYS" --stake-cpu "100000.0000 SYS" --buy-ram-kbytes 8192
cleos --wallet-url http://127.0.0.1:8899 -u http://127.0.0.1:48888 system newaccount eosio --transfer admin2 EOS6FF1ByAGfNEbx1okMiKjeKq9FeNQvybz7pPTWqpJ7vwxDatDiS --stake-net "100000.0000 SYS" --stake-cpu "100000.0000 SYS" --buy-ram-kbytes 8192

注册为producer

1
2
cleos --wallet-url http://127.0.0.1:8899 -u http://127.0.0.1:48888 system regproducer admin1 EOS6CrKkykBfRkiqS5kkbhjVHhnQFxf8YuwtVqQgrso4GniesqPcG https://admin1.com/EOS6CrKkykBfRkiqS5kkbhjVHhnQFxf8YuwtVqQgrso4GniesqPcG
cleos --wallet-url http://127.0.0.1:8899 -u http://127.0.0.1:48888 system regproducer admin2 EOS6FF1ByAGfNEbx1okMiKjeKq9FeNQvybz7pPTWqpJ7vwxDatDiS https://admin2.com/EOS6FF1ByAGfNEbx1okMiKjeKq9FeNQvybz7pPTWqpJ7vwxDatDiS

查看producer列表

1
cleos --wallet-url http://127.0.0.1:8899 -u http://127.0.0.1:48888 system listproducers

投票

1
cleos --wallet-url http://127.0.0.1:8899 -u http://127.0.0.1:48888 system voteproducer prods admin1 admin2

查看账号信息

1
cleos --wallet-url http://127.0.0.1:8899 -u http://127.0.0.1:48888 get account eosio

参考资料

  1. https://blockflow.net/t/topic/621
  2. https://www.jianshu.com/p/ed90f99ead51
  3. https://developers.eos.io/eosio-nodeos/docs/local-multi-node-testnet