侧边栏壁纸
博主头像
学习乐园369博主等级

没有你学不会的,只会是你不想学

  • 累计撰写 9 篇文章
  • 累计创建 5 个标签
  • 累计收到 0 条评论

目 录CONTENT

文章目录

全国职业院校技能大赛-区块链技术应用(1卷)-区块链系统部署与运维

xiaoke
2024-03-08 / 0 评论 / 2 点赞 / 3077 阅读 / 15733 字

任务1-2:区块链系统部署与运维

子任务1-2-1: 搭建区块链系统并验证

采用默认配置搭建区块链网络

使用 build_chain.sh在本机搭建一条4节点区块链系统,-l指定IP,-p指定端口,-e指定本地 fisco-bcos,不指定则去GitHub自动下载

[root@localhost tools]# bash build_chain.sh -l 127.0.0.1:4 -p 30300,20200,8545 -e /root/tools/fisco-bcos 
Checking fisco-bcos binary...
Binary check passed.
==============================================================
Generating CA key...
==============================================================
Generating keys and certificates ...
Processing IP=127.0.0.1 Total=4 Agency=agency Groups=1
==============================================================
Generating configuration files ...
Processing IP=127.0.0.1 Total=4 Agency=agency Groups=1
==============================================================
[INFO] FISCO-BCOS Path : /root/tools/fisco-bcos
[INFO] Start Port      : 30300 20200 8545
[INFO] Server IP       : 127.0.0.1:4
[INFO] Output Dir      : /root/tools/nodes
[INFO] CA Path         : /root/tools/nodes/cert/
==============================================================
[INFO] Execute the download_console.sh script in directory named by IP to get FISCO-BCOS console.
e.g.  bash /root/tools/nodes/127.0.0.1/download_console.sh -f
==============================================================
[INFO] All completed. Files in /root/tools/nodes

启动节点

[root@localhost tools]# cd /root/tools/nodes/127.0.0.1/
[root@localhost 127.0.0.1]# bash start_all.sh 
try to start node0
try to start node1
try to start node2
try to start node3
 node3 start successfully
 node2 start successfully
 node0 start successfully
 node1 start successfully
通过命令验证区块链节点进程运行状况
[root@localhost 127.0.0.1]# ps -ef | grep -v grep | grep fisco-bcos
root      27986      1 11 15:03 pts/2    00:00:10 /root/tools/nodes/127.0.0.1/node3/../fisco-bcos -c config.ini
root      27988      1 11 15:03 pts/2    00:00:10 /root/tools/nodes/127.0.0.1/node0/../fisco-bcos -c config.ini
root      27990      1 11 15:03 pts/2    00:00:10 /root/tools/nodes/127.0.0.1/node2/../fisco-bcos -c config.ini
root      27992      1 11 15:03 pts/2    00:00:10 /root/tools/nodes/127.0.0.1/node1/../fisco-bcos -c config.ini
通过命令验证区块链连接状态和共识状态日志输出

验证区块链连接状态

使用 tail,关键词 connected,这里查看 node0节点一共有3个节点连接

[root@localhost 127.0.0.1]# tail -f /root/tools/nodes/127.0.0.1/node0/log/log* | grep connected
info|2024-03-08 15:07:11.532131|[P2P][Service] heartBeat,connected count=3
info|2024-03-08 15:07:21.532923|[P2P][Service] heartBeat,connected count=3
info|2024-03-08 15:07:31.533679|[P2P][Service] heartBeat,connected count=3

验证区块链共识状态

使用 tail,关键词 ++,这里查看 node0节点它在 [g:1]群组中

[root@localhost 127.0.0.1]# tail -f /root/tools/nodes/127.0.0.1/node0/log/log* | grep ++
info|2024-03-08 15:08:58.748762|[g:1][CONSENSUS][SEALER]++++++++++++++++ Generating seal on,blkNum=1,tx=0,nodeIdx=1,hash=3a6979be...
info|2024-03-08 15:09:02.814596|[g:1][CONSENSUS][SEALER]++++++++++++++++ Generating seal on,blkNum=1,tx=0,nodeIdx=1,hash=a33746d0...
info|2024-03-08 15:09:06.879987|[g:1][CONSENSUS][SEALER]++++++++++++++++ Generating seal on,blkNum=1,tx=0,nodeIdx=1,hash=595e86e9...
info|2024-03-08 15:09:10.953230|[g:1][CONSENSUS][SEALER]++++++++++++++++ Generating seal on,blkNum=1,tx=0,nodeIdx=1,hash=dd7de7c6...
info|2024-03-08 15:09:15.010876|[g:1][CONSENSUS][SEALER]++++++++++++++++ Generating seal on,blkNum=1,tx=0,nodeIdx=1,hash=2de6c46d...
info|2024-03-08 15:09:19.095112|[g:1][CONSENSUS][SEALER]++++++++++++++++ Generating seal on,blkNum=1,tx=0,nodeIdx=1,hash=865c90c5...

子任务1-2-2:搭建区块链系统管理平台并验证

配置控制台,管理相关证书并启动

切换到 root/tools/console目录下,并且把节点的 SDK目录下的文件全部拷贝到 conf目录下

cd /root/tools/console
cp /root/tools/nodes/127.0.0.1/sdk/* ./conf/

进入 conf目录,拷贝 config-example.toml文件为 config.toml回到 root/tools/console目录启动控制台

[root@localhost console]# bash start.sh 
=============================================================================================
Welcome to FISCO BCOS console(2.8.0)!
Type 'help' or 'h' for help. Type 'quit' or 'q' to quit console.
 ________ ______  ______   ______   ______       _______   ______   ______   ______  
|        |      \/      \ /      \ /      \     |       \ /      \ /      \ /      \ 
| $$$$$$$$\$$$$$|  $$$$$$|  $$$$$$|  $$$$$$\    | $$$$$$$|  $$$$$$|  $$$$$$|  $$$$$$\
| $$__     | $$ | $$___\$| $$   \$| $$  | $$    | $$__/ $| $$   \$| $$  | $| $$___\$$
| $$  \    | $$  \$$    \| $$     | $$  | $$    | $$    $| $$     | $$  | $$\$$    \ 
| $$$$$    | $$  _\$$$$$$| $$   __| $$  | $$    | $$$$$$$| $$   __| $$  | $$_\$$$$$$\
| $$      _| $$_|  \__| $| $$__/  | $$__/ $$    | $$__/ $| $$__/  | $$__/ $|  \__| $$
| $$     |   $$ \\$$    $$\$$    $$\$$    $$    | $$    $$\$$    $$\$$    $$\$$    $$
 \$$      \$$$$$$ \$$$$$$  \$$$$$$  \$$$$$$      \$$$$$$$  \$$$$$$  \$$$$$$  \$$$$$$

=============================================================================================
[group:1]>
使用控制台安装HelloWorld智能合约
[group:1]> deploy HelloWorld 
transaction hash: 0x0ec66dc0ec9b52747a300e4eb794bedf065bae3a70566ddfa752666138cb5269
contract address: 0x6ee8e6914af23ecdce1e37ebaaa0cbdf82d0aafb
currentAccount: 0xf3f339a8324862ecdf258c519cc357d0c2f4f663
使用控制台完成HelloWorld智能合约的set与get操作
[group:1]> call HelloWorld 0x6ee8e6914af23ecdce1e37ebaaa0cbdf82d0aafb get
---------------------------------------------------------------------------------------------
Return code: 0
description: transaction executed successfully
Return message: Success
---------------------------------------------------------------------------------------------
Return value size:1
Return types: (STRING)
Return values:(Hello, World!)
---------------------------------------------------------------------------------------------

[group:1]> call HelloWorld 0x6ee8e6914af23ecdce1e37ebaaa0cbdf82d0aafb set "FISCO BCOS"
transaction hash: 0x0effadbbb695e3c6e6b2dd1e75e06280eaecb1f43b151dc492b5b3ec21225c60
---------------------------------------------------------------------------------------------
transaction status: 0x0
description: transaction executed successfully
---------------------------------------------------------------------------------------------
Receipt message: Success
Return message: Success
Return values:[]
---------------------------------------------------------------------------------------------
Event logs
Event: {}
使用控制台查看区块链中区块高度
[group:1]> getBlockNumber 
2

子任务1-2-3:区块链节点运维

获取指定区块链节点输出等级为警告级,并设置日志存储阈值位100MB并验证

这里是指定节点设置,正常比赛中会要求那个节点,这里设置 node0节点,切到 node0目录中,编辑 config.ini,找到 [log],修改 levelwarningmax_log_file_size=200 为 100

[log]
    enable=true
    log_path=./log
    ; enable/disable the statistics function
    enable_statistic=false
    ; network statistics interval, unit is second, default is 60s
    stat_flush_interval=60
    ; info debug trace
    level=warning
    ; MB
    max_log_file_size=100
    flush=true

重启节点

[root@localhost node0]# bash stop.sh && bash start.sh 
 stop node0 success.
 node0 start successfully

验证

正常节点是不会输出 warning日志,使用刚才的 tail查看一下,会发现什么也不输出

[root@localhost node0]# tail -f /root/tools/nodes/127.0.0.1/node0/log/log* | grep +++
通过给定工具(地址/root/tools)完成新节点(node4)配置

使用 gen_node_cert.sh生成一共新节点,-c,指定密钥位置 ,-o指定节点存储位置

[root@localhost tools]# bash gen_node_cert.sh -c /root/tools/nodes/cert/agency/ -o /root/tools/nodes/127.0.0.1/node4
gen_node_cert.sh:行151: xxd: 未找到命令
==============================================================
[INFO] Cert Path   : /root/tools/nodes/cert/agency/
[INFO] Output Dir  : /root/tools/nodes/127.0.0.1/node4
==============================================================
[INFO] All completed. Files in /root/tools/nodes/127.0.0.1/node4

再进入 node4目录中,方便拷贝配置文件,把 node0 中的 start.sh stop.sh config.ini 拷贝到 node4目录下,在拷贝 node0/conf下的群组文件,group.1.ini group.1.genesis,拷贝到 node4/conf目录下

[root@localhost conf]# cd /root/tools/nodes/127.0.0.1/node4/
[root@localhost node4]# cp /root/tools/nodes/127.0.0.1/node0/start.sh ./
[root@localhost node4]# cp /root/tools/nodes/127.0.0.1/node0/stop.sh ./
[root@localhost node4]# cp /root/tools/nodes/127.0.0.1/node0/config.ini ./
[root@localhost node4]# cp /root/tools/nodes/127.0.0.1/node0/conf/group.1.ini ./conf
[root@localhost node4]# cp /root/tools/nodes/127.0.0.1/node0/conf/group.1.genesis ./conf
[root@localhost node4]# ls
conf  config.ini  start.sh  stop.sh

修改配置文件 config.ini,。对于 [rpc]模块,修改 channel_listen_port=20204jsonrpc_listen_port=8549;对于 [p2p]模块,修改 listen_port=30304并在 node.中增加自身节点信息;

[rpc]
    channel_listen_ip=0.0.0.0
    channel_listen_port=20204
    jsonrpc_listen_ip=127.0.0.1
    jsonrpc_listen_port=8549
[p2p]
    listen_ip=0.0.0.0
    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
启动新节点加入区块链系统并验证

启动节点

[root@localhost node4]# bash start.sh 
 node4 start successfully

查看 node4的 id

[root@localhost node4]# cat /root/tools/nodes/127.0.0.1/node4/conf/node.nodeid 
724921f710711316d0bcc4ddb87f337e2f99782a35ead8c7b788cf6a93e1f4abc41efdecb03e0f12b132812b7c6235d693d8a1ecd5ae9c7f50591e304a8f2b71

再次进入控制台,把节点设置成 共识节点 ,使用 addSealer

[root@localhost console]# bash /root/tools/console/start.sh
=============================================================================================
Welcome to FISCO BCOS console(2.8.0)!
Type 'help' or 'h' for help. Type 'quit' or 'q' to quit console.
 ________ ______  ______   ______   ______       _______   ______   ______   ______  
|        |      \/      \ /      \ /      \     |       \ /      \ /      \ /      \ 
| $$$$$$$$\$$$$$|  $$$$$$|  $$$$$$|  $$$$$$\    | $$$$$$$|  $$$$$$|  $$$$$$|  $$$$$$\
| $$__     | $$ | $$___\$| $$   \$| $$  | $$    | $$__/ $| $$   \$| $$  | $| $$___\$$
| $$  \    | $$  \$$    \| $$     | $$  | $$    | $$    $| $$     | $$  | $$\$$    \ 
| $$$$$    | $$  _\$$$$$$| $$   __| $$  | $$    | $$$$$$$| $$   __| $$  | $$_\$$$$$$\
| $$      _| $$_|  \__| $| $$__/  | $$__/ $$    | $$__/ $| $$__/  | $$__/ $|  \__| $$
| $$     |   $$ \\$$    $$\$$    $$\$$    $$    | $$    $$\$$    $$\$$    $$\$$    $$
 \$$      \$$$$$$ \$$$$$$  \$$$$$$  \$$$$$$      \$$$$$$$  \$$$$$$  \$$$$$$  \$$$$$$

=============================================================================================
[group:1]> addSealer 724921f710711316d0bcc4ddb87f337e2f99782a35ead8c7b788cf6a93e1f4abc41efdecb03e0f12b132812b7c6235d693d8a1ecd5ae9c7f50591e304a8f2b71
{
    "code":1,
    "msg":"Success"
}

加入成功,用 tail,查看 node0节点连接情况,验证是否加入成功(刚才把 node0节点的日志输出改成 warning 了,需要修改回来为 info,并重新启动)

[root@localhost node0]# tail -f /root/tools/nodes/127.0.0.1/node0/log/log* | grep connected
info|2024-03-08 15:54:00.833135|[P2P][Service] heartBeat,connected count=4
info|2024-03-08 15:54:10.834152|[P2P][Service] heartBeat,connected count=4

这里的 connected conunt 为4,证明新节点已经加入成功

子任务1-2-4:区块链网络运维

设置区块链系统黑名单,将node3设为黑名单禁止连接,并验证

查看 node3的id

[root@localhost node0]# cat /root/tools/nodes/127.0.0.1/node3/conf/node.nodeid 
1971793aee3e24b79e04e21cd619ee2f6fe21ccda019f1b56b197be8b16e6717c2dda5abc979ded90518efd91e77cf2f2ecc3f3b7dad716237b9ae501a1a7bac

修改 node0config.ini文件 ,将 certifcate_blacklist[黑名单]字段添加 node3的节点id

[certificate_blacklist]
    ; crl.0 should be nodeid, nodeid's length is 128
    crl.0=1971793aee3e24b79e04e21cd619ee2f6fe21ccda019f1b56b197be8b16e6717c2dda5abc979ded90518efd91e77cf2f2ecc3f3b7dad716237b9ae501a1a7bac

重启 node0,节点再用 tail查看节点连接状态

[root@localhost node0]# bash stop.sh && bash start.sh 
 stop node0 success.
 node0 start successfully
[root@localhost node0]# tail -f /root/tools/nodes/127.0.0.1/node0/log/log* | grep connected
info|2024-03-08 16:05:47.634483|[P2P][Service] heartBeat,connected count=3
info|2024-03-08 16:05:57.635824|[P2P][Service] heartBeat,connected count=3

这里可以看到,连接数只有3个了,证明已经设置成功,node1 node2 node4,一样这样配置

设置系统中区块打包最大交易数量设为2000

进入控制台,使用 setSystemConfigByKey设置 tx_count_limit

[group:1]> setSystemConfigByKey tx_count_limit 2000
验证区块最大打包交易数量情况
[group:1]> getSystemConfigByKey tx_count_limit 
2000
2

评论区