以太坊区块链 POA本地搭建多节点私有链

前面的单个节点的设置参考其他教程搭建,这里主要针对搭建多节点相互连通的问题进行总结。

我的geth版本号是

geth -version 1.9.22-stable-c71a7e26

(一)创建测试文件夹

mkdir test_mygeth
cd test_mygeth
mkdir bootdir boot1 boot2

(二)bootnode配置

sudo bootnode --genkey boot.key
sudo bootnode --nodekey boot.key

在这里插入图片描述

(三)分别在boot1和boot2目录下创建一个新账户

sudo geth --datadir ./ account new

在这里插入图片描述
在这里插入图片描述

(四)使用puppeth创建test_genesis.json

ccczy@ccczy-virtual-machine:~/test_mygeth/boot1$ puppeth
+-----------------------------------------------------------+
| Welcome to puppeth, your Ethereum private network manager |
|                                                           |
| This tool lets you create a new Ethereum network down to  |
| the genesis block, bootnodes, miners and ethstats servers |
| without the hassle that it would normally entail.         |
|                                                           |
| Puppeth uses SSH to dial in to remote servers, and builds |
| its network components out of Docker containers using the |
| docker-compose toolset.                                   |
+-----------------------------------------------------------+

Please specify a network name to administer (no spaces, hyphens or capital letters please)
> test_genesis

Sweet, you can set this via --network=test_genesis next time!

INFO [10-11|23:36:44.845] Administering Ethereum network           name=test_genesis
WARN [10-11|23:36:44.910] No previous configurations found         path=/home/ccczy/.puppeth/test_genesis

What would you like to do? (default = stats)
 1. Show network stats
 2. Configure new genesis
 3. Track new remote server
 4. Deploy network components
> 2

What would you like to do? (default = create)
 1. Create new genesis from scratch
 2. Import already existing genesis
> 1

Which consensus engine to use? (default = clique)
 1. Ethash - proof-of-work
 2. Clique - proof-of-authority
> 2

How many seconds should blocks take? (default = 15)
> 3

Which accounts are allowed to seal? (mandatory at least one)
> 0xAC97FEf673342870bd5F466b6778B480620Ecdb9
> 0x9BC7A19cED9e2E0A3E7aFb92113f4EA814963355
> 0x

Which accounts should be pre-funded? (advisable at least one)
> 0x9BC7A19cED9e2E0A3E7aFb92113f4EA814963355
> 0xAC97FEf673342870bd5F466b6778B480620Ecdb9
> 0x

Should the precompile-addresses (0x1 .. 0xff) be pre-funded with 1 wei? (advisable yes)
> 

Specify your chain/network ID if you want an explicit one (default = random)
> 456
INFO [10-11|23:38:16.130] Configured new genesis block 

What would you like to do? (default = stats)
 1. Show network stats
 2. Manage existing genesis
 3. Track new remote server
 4. Deploy network components
> 2

 1. Modify existing configurations
 2. Export genesis configurations
 3. Remove genesis configuration
> 2

Which folder to save the genesis specs into? (default = current)
  Will create test_genesis.json, test_genesis-aleth.json, test_genesis-harmony.json, test_genesis-parity.json
> test_genesis.json
INFO [10-11|23:38:57.386] Saved native genesis chain spec          path=test_genesis.json/test_genesis.json
ERROR[10-11|23:38:57.386] Failed to create Aleth chain spec        err="unsupported consensus engine"
ERROR[10-11|23:38:57.419] Failed to create Parity chain spec       err="unsupported consensus engine"
INFO [10-11|23:38:57.420] Saved genesis chain spec                 client=harmony path=test_genesis.json/test_genesis-harmony.json

What would you like to do? (default = stats)
 1. Show network stats
 2. Manage existing genesis
 3. Track new remote server
 4. Deploy network components
> ^C
> 
ccczy@ccczy-virtual-machine:~/test_mygeth/boot1$ ls
keystore  test_genesis.json

ccczy@ccczy-virtual-machine:~/test_mygeth/boot1$ ls -l test_genesis.json
总用量 48
-rw-r--r-- 1 ccczy ccczy 21827 10月 11 23:38 test_genesis-harmony.json
-rw-r--r-- 1 ccczy ccczy 21827 10月 11 23:38 test_genesis.json

会在test_genesis.json生成两个json文件,尝试用test_genesis.json作为创世纪块文件头

test_genesis.json复制到boot1和boot2的目录下
在这里插入图片描述

(五)用同一个genesis.json进行初始化

ccczy@ccczy-virtual-machine:~/test_mygeth/boot1$ sudo geth --datadir ./ init test_genesis.json 
ccczy@ccczy-virtual-machine:~/test_mygeth/boot2$ sudo geth --datadir ./ init test_genesis.json 

(六)启动节点

sudo geth --datadir ./ --port 30321 --networkid 456 --rpc --rpcaddr 0.0.0.0 --rpcapi net,web3,eth,personal --rpcport 8110 --bootnodes "enode://45c611ce644da6f08214ca45a4ca6f4f6d5075a76fa2d57febb898a40bfb141b7eaf69cecc7984fdaca15838026c8967e026ab2cad46237bae86db35f958f32d@127.0.0.1:30301"  --unlock "0x9BC7A19cED9e2E0A3E7aFb92113f4EA814963355" --allow-insecure-unlock --syncmode "full" console
sudo geth --datadir ./ --port 30322 --networkid 456 --rpc --rpcaddr 0.0.0.0 --rpcapi net,web3,eth,personal --rpcport 8111 --bootnodes "enode://45c611ce644da6f08214ca45a4ca6f4f6d5075a76fa2d57febb898a40bfb141b7eaf69cecc7984fdaca15838026c8967e026ab2cad46237bae86db35f958f32d@127.0.0.1:30301"  --unlock " 0xAC97FEf673342870bd5F466b6778B480620Ecdb9" --allow-insecure-unlock --syncmode "full" console
  • -networkid 要与上面自己在puppeth时填写的一致,我这里填写的是456
  • 注意-port , -rpcport在两个节点的值要设置成不一样的,否则会提示端口占用的问题。

(七)节点设置

启动节点后在boot1和boot2开启挖矿

miner.start(1)

使用add.Peer将节点二加入到节点一中

admin.addPeer("enode://071dbf222dba7385efe622930f3c5438d52c710b07fda41999eab0259f8c78c8ed1ec3a500e9270435fff75560d23ed0bc642b1174ce00b034773cbd49933117@127.0.0.1:30322")
  • 节点的enode信息在启动节点后可以找到

在这里插入图片描述

# 使用net.peerCount 测试节点是否连接
net.peerCount

在这里插入图片描述

配置成功!

上述测试:主要参考大佬的方法 geth基于PoA共识机制构建联盟链

总结
1.测试了一下,在启动节点可以不使用--bootnode "enode:......也可以完成节点的连接🔗, 在启动后使用命令 admin.addPeer("enode:.......")即可
2.enode尾部的信息形式为@127.0.0.1:30322样式
3.在两个节点中networkid 一致,port、pcport需要不同

  • 0
    点赞
  • 7
    收藏
    觉得还不错? 一键收藏
  • 7
    评论
评论 7
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值