2023-03-10 | 扩容一个新节点
Fisco-Bcos扩容新节点
相关文章->扩容一个新节点
概念
FISCO BCOS引入了游离节点、观察者节点和共识节点,这三种节点类型可通过控制台相互转换。
共识节点:参与共识的节点,拥有群组的所有数据(搭链时默认都生成共识节点)。
观察者节点:不参与共识,但能实时同步链上数据的节点。
游离节点:已启动,待等待加入群组的节点。处在一种暂时的节点状态,不能获取链上的数据。
步骤
为节点生成证书并启动
获取证书下载脚本
1
| curl -#LO https://raw.githubusercontent.com/FISCO-BCOS/FISCO-BCOS/master-2.0/tools/gen_node_cert.sh
|
执行脚本生成新节点证书
1 2 3 4
| # -c指定机构证书及私钥所在路径 # -o输出到指定文件夹,其中node4/conf中会存在机构agency新签发的证书和私钥 # 成功会输出 All completed 提示 bash gen_node_cert.sh -c ../cert/agency -o node4
|
复制文件到node4目录
拷贝node0目录下start.sh
、stop.sh
脚本和config.ini
配置到node4目录
1
| cp node0/config.ini node0/start.sh node0/stop.sh node4/
|
配置参数
一共需要修改四处
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
| $ vim node4/config.ini [rpc] ;rpc listen ip listen_ip=127.0.0.1 ;channelserver listen port channel_listen_port=20204 #第一处 ;jsonrpc listen port jsonrpc_listen_port=8549 #第二处 [p2p] ;p2p listen ip listen_ip=0.0.0.0 ;p2p listen port listen_port=30304 #第三处 ;nodes to connect node.0=127.0.0.1:30300 node.1=127.0.0.1:30301 node.2=127.0.0.1:30302 node.3=127.0.0.1:30303 node.4=127.0.0.1:30304 #第四处
|
拷贝群组相关文件
拷贝节点1的node0/conf/group.1.genesis
(内含群组节点初始列表)和node0/conf/group.1.ini
到node4/conf
目录下,不需改动
1
| cp node0/conf/group.1.genesis node0/conf/group.1.ini node4/conf/
|
启动新节点
在node4目录执行start.sh
脚本启动节点
检查节点启动情况
确认node4与其他节点连接已经建立,加入网络操作完成
1
| tail -f node4/log/log* | grep "connected"
|
1 2 3 4
| # 以下日志表明节点node4与其他4个节点建立了连接 [root@localhost localhost]# tail node0/log/log* -f | grep -v grep | grep connected info|2023-03-11 11:44:29.722535|[P2P][Service] heartBeat,connected count=4 info|2023-03-11 11:44:39.722712|[P2P][Service] heartBeat,connected count=4
|
新节点加入群组
获取node4的nodeid
1
| cat node4/conf/node.nodeid
|
加入group:1
使用addObserver将node4作为观察节点加入群组1
1 2 3 4 5 6 7 8 9 10 11 12 13
| [group:1]> getObserverList []
[group:1]> addObserver 94ae60f93ef9a25a93666e0149b7b4cb0e044a61b7dcd1b00096f2bdb17d1c6853fc81a24e037c9d07803fcaf78f768de2ba56a4f729ef91baeadaa55a8ccd6e { "code":1, "msg":"Success" }
[group:1]> getObserverList [ 94ae60f93ef9a25a93666e0149b7b4cb0e044a61b7dcd1b00096f2bdb17d1c6853fc81a24e037c9d07803fcaf78f768de2ba56a4f729ef91baeadaa55a8ccd6e ]
|
使用addSealer将node4作为共识节点加入群组1
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22
| [group:1]> getSealerList [ 6c41f7e138051a13a220cb186e934398e37700295ff355b87f113704996b3e03750100e16653cda18b5f954d3b7b08d068ca4a9d65cec5a40db980b697ffb699, 7404cdf7f34f038aba90059ff25dc5f05f538010c55e98976aea6bc954910f34f15a255869751c8fe564bdb0fa1eee8e2db47eeca0fdd1359beaac6adcd37ede, a7b856e5b59072c809ea963fa45ede72f7d37561affff989fbede6cd61a40137e2146db205434788e61b89a57f08c614cd283e5e915c23714c2fa685237e8bdb, e5ea1e18717418a57f115bf1cea5168250f86e5b77f74dd15d0c4bf3758ca37002059ba2e54131296d1646a62be5faf85e243dac8d33d452acd63e20428b72ed ]
[group:1]> addSealer 94ae60f93ef9a25a93666e0149b7b4cb0e044a61b7dcd1b00096f2bdb17d1c6853fc81a24e037c9d07803fcaf78f768de2ba56a4f729ef91baeadaa55a8ccd6e { "code":1, "msg":"Success" }
[group:1]> getSealerList [ 6c41f7e138051a13a220cb186e934398e37700295ff355b87f113704996b3e03750100e16653cda18b5f954d3b7b08d068ca4a9d65cec5a40db980b697ffb699, 7404cdf7f34f038aba90059ff25dc5f05f538010c55e98976aea6bc954910f34f15a255869751c8fe564bdb0fa1eee8e2db47eeca0fdd1359beaac6adcd37ede, a7b856e5b59072c809ea963fa45ede72f7d37561affff989fbede6cd61a40137e2146db205434788e61b89a57f08c614cd283e5e915c23714c2fa685237e8bdb, e5ea1e18717418a57f115bf1cea5168250f86e5b77f74dd15d0c4bf3758ca37002059ba2e54131296d1646a62be5faf85e243dac8d33d452acd63e20428b72ed, 94ae60f93ef9a25a93666e0149b7b4cb0e044a61b7dcd1b00096f2bdb17d1c6853fc81a24e037c9d07803fcaf78f768de2ba56a4f729ef91baeadaa55a8ccd6e ]
|
节点管理
参考文章->节点管理
多群组部署
实现
新建文件
1 2 3 4 5 6 7
| [root@localhost /]# cd fisco2 && cat > ipconf <<HHH > localhost:2 agencyA 1,2 > localhost:2 agencyB 1 > HHH [root@localhost fisco2]# cat ipconf localhost:2 agencyA 1,2 # agencyA:在127.0.0.1上有2个节点,同时属于group1、group2; localhost:2 agencyB 1 # agencyB:在127.0.0.1上有2个节点,属于group1;
|
使用配置文件创建节点
1
| bash build_chain.sh -f ./ipconf -e ./fisco
|
启动节点
1 2 3 4 5 6 7 8 9
| [root@localhost localhost]# bash ./start_all.sh try to start node0 try to start node1 try to start node2 try to start node3 node0 start successfully node3 start successfully node2 start successfully node1 start successfully
|
检查连接以及是否产生共识
1 2 3 4 5 6 7 8 9 10
| [root@localhost localhost]# ps -ef | grep -v grep | grep fisco-bcos root 69993 1 2 20:11 pts/0 00:00:03 /fisco2/nodes/localhost/node0/../fisco-bcos -c config.ini root 69995 1 1 20:11 pts/0 00:00:01 /fisco2/nodes/localhost/node2/../fisco-bcos -c config.ini root 69997 1 1 20:11 pts/0 00:00:01 /fisco2/nodes/localhost/node3/../fisco-bcos -c config.ini root 69999 1 2 20:11 pts/0 00:00:03 /fisco2/nodes/localhost/node1/../fisco-bcos -c config.ini [root@localhost localhost]# tail -f node0/log/log* | grep +++ info|2023-03-11 20:16:36.908649|[g:2][CONSENSUS][SEALER]++++++++++++++++ Generating seal on,blkNum=1,tx=0,nodeIdx=1,hash=160ccf37... info|2023-03-11 20:16:37.861884|[g:1][CONSENSUS][SEALER]++++++++++++++++ Generating seal on,blkNum=1,tx=0,nodeIdx=3,hash=8ce12fdb... info|2023-03-11 20:16:38.914920|[g:2][CONSENSUS][SEALER]++++++++++++++++ Generating seal on,blkNum=1,tx=0,nodeIdx=1,hash=655bec83... info|2023-03-11 20:16:40.920451|[g:2][CONSENSUS][SEALER]++++++++++++++++ Generating seal on,blkNum=1,tx=0,nodeIdx=1,hash=82967295...
|
细节
cat写文件
1 2 3
| cat > filename << end_signal > content > end_signal
|
- EOF只是标识,不是固定的
- 可以用按键
Ctrl+D
输出EOF的标识
cat << EOF >> test.sh 内容 EOF
== cat > test.sh << EOF 内容 EOF