区块链系统部署与运维

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

1-1: 搭建区块链系统并验证

基于给定服务器环境以及软件(地址“/root/tools”),搭建一条4节点的区块链系统并验证,具体工作内容如下:

(1)配置网络(安装包在/root/tools/目录**)**

提示:如果已经搭建完成(即有nodes目录),删除rm -rf nodes,继续搭建。

image-20251003112021224

命令: bash build_chain.sh -l 127.0.0.1:4 -p 30300,20200,8545 -e

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
root@admin:~/tools# ./build_chain.sh -l 127.0.0.1:4 -p 30300,20200,8545
[INFO] Downloading fisco-bcos binary from https://github.com/FISCO-BCOS/FISCO-BCOS/releases/download/v2.8.0/fisco-bcos.tar.gz ...
######################################################################## 100.0%
./build_chain.sh: 行 1560: [[: 43168632
10920882:表达式中有语法错误 (错误符号是 "10920882")
==============================================================
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] 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@admin:~/tools#

启动网络节点(搭建完成会生成nodes目录

命令: bash nodes/127.0.0.1/start_all.sh

1
2
3
4
5
6
7
8
9
10
root@admin:~/tools/nodes/127.0.0.1# ./start_all.sh
try to start node0
try to start node1
try to start node2
try to start node3
node2 start successfully
node1 start successfully
node3 start successfully
node0 start successfully
root@admin:~/tools/nodes/127.0.0.1#

(2)通过命令验证区块链节点进程运行状况

检查进程

命令: ps -ef | grep fisco-bcos

1
2
3
4
5
6
root@admin:~/tools/nodes/127.0.0.1#  ps -ef | grep -v grep | grep fisco-bcos
root 5588 1 1 11:26 pts/0 00:00:01 /root/tools/nodes/127.0.0.1/node3/../fisco-bcos -c config.ini
root 5589 1 1 11:26 pts/0 00:00:01 /root/tools/nodes/127.0.0.1/node0/../fisco-bcos -c config.ini
root 5592 1 1 11:26 pts/0 00:00:01 /root/tools/nodes/127.0.0.1/node2/../fisco-bcos -c config.ini
root 5594 1 1 11:26 pts/0 00:00:01 /root/tools/nodes/127.0.0.1/node1/../fisco-bcos -c config.ini
root@admin:~/tools/nodes/127.0.0.1#

(3)通过命令验证区块链连接状态和共识状态日志输出。

查看共识状态

命令: tail -f node0/log/log* | grep connected

1
2
3
4
5
6
7
root@admin:~/tools/nodes/127.0.0.1# tail -f node0/log/log* | grep connected
info|2025-10-03 11:31:06.806705|[P2P][Service] heartBeat,connected count=3
info|2025-10-03 11:31:16.807000|[P2P][Service] heartBeat,connected count=3
info|2025-10-03 11:31:26.807282|[P2P][Service] heartBeat,connected count=3
info|2025-10-03 11:31:36.807683|[P2P][Service] heartBeat,connected count=3
^C
root@admin:~/tools/nodes/127.0.0.1#

查看日志输出

命令:tail -f node0/log/log* | grep +++++

1
2
3
4
5
6
7
root@admin:~/tools/nodes/127.0.0.1# tail -f node0/log/log* | grep +++++
info|2025-10-03 11:32:44.168990|[g:1][CONSENSUS][SEALER]++++++++++++++++ Generating seal on,blkNum=1,tx=0,nodeIdx=3,hash=acdeacf2...
info|2025-10-03 11:32:48.180522|[g:1][CONSENSUS][SEALER]++++++++++++++++ Generating seal on,blkNum=1,tx=0,nodeIdx=3,hash=762aefdd...
info|2025-10-03 11:32:52.195371|[g:1][CONSENSUS][SEALER]++++++++++++++++ Generating seal on,blkNum=1,tx=0,nodeIdx=3,hash=b6b97d9c...
info|2025-10-03 11:32:56.209507|[g:1][CONSENSUS][SEALER]++++++++++++++++ Generating seal on,blkNum=1,tx=0,nodeIdx=3,hash=c5db2cfb...
^C
root@admin:~/tools/nodes/127.0.0.1#

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

基于给定服务器环境以及软件(地址“/root/tools”),搭建区块链控制台并开展相关运维工作,具体工作内容如下:

(1)配置控制台,管理相关证书并启动;

安装console**,解压console.tar.gz文件的命令:tar -zxvf console.tar.gz

image-20251003113531469

配置控制台证书

命令:cp -n console/conf/config-example.toml console/conf/

命令:cp -r nodes/127.0.0.1/sdk/* console/conf/

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
root@admin:~/tools# cp console/conf/config-example.toml console/conf/config.toml
root@admin:~/tools# cp -r nodes/127.0.0.1/sdk/* console/conf/
root@admin:~/tools# cd console/conf
root@admin:~/tools/console/conf# ll
总用量 40
drwxr-xr-x 2 501 staff 4096 10月 3 11:41 ./
drwxr-xr-x 6 501 staff 4096 8月 25 2021 ../
-rw-r--r-- 1 root root 664 10月 3 11:41 ca.crt
-rw-r--r-- 1 501 staff 2851 8月 25 2021 config-example.toml
-rw-r--r-- 1 root root 2851 10月 3 11:40 config.toml
-rw-r--r-- 1 501 staff 321 8月 25 2021 group-generate-config.toml
-rw-r--r-- 1 501 staff 1407 8月 25 2021 log4j.properties
-rw-r--r-- 1 root root 1825 10月 3 11:41 sdk.crt
-rw------- 1 root root 237 10月 3 11:41 sdk.key
-rw-r--r-- 1 root root 129 10月 3 11:41 sdk.publickey
root@admin:~/tools/console/conf#

启动控制台

命令: cd console ./start.sh

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
root@admin:~/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]>

(2)使用控制台安装HelloWorld智能合约;

部署合约

命令: deploy HelloWorld

(此处需记录合约地址)

1
2
3
4
5
6
[group:1]> deploy HelloWorld
transaction hash: 0x2188c7564b992cc82ee822da857cbe9c62fd0f6fc6a009f34b9b2a6ea85356fa
contract address: 0x6c1f62cf09bd542a36634776cf0e5eeddb176ddc
currentAccount: 0xc31d60b2f2734b5cf7264c25c445d839ef5acc60

[group:1]>

(3)使用控制台完成HelloWorld智能合约的set与get操作;

调用set方法的操作注意合约地址要用上一步部署的合约地址

命令:call HelloWorld 0x6c1f62cf09bd542a36634776cf0e5eeddb176ddc set “Hello,cdnkxy”

1
2
3
4
5
6
7
8
9
10
11
12
[group:1]> call HelloWorld 0x6c1f62cf09bd542a36634776cf0e5eeddb176ddc set "Hello,cdnkxy"
transaction hash: 0x69edb4c9249d3d02ba6b24808c374c362a18ad4e3e535d1dfae4cdd91a8adb24
---------------------------------------------------------------------------------------------
transaction status: 0x0
description: transaction executed successfully
---------------------------------------------------------------------------------------------
Receipt message: Success
Return message: Success
Return values:[]
---------------------------------------------------------------------------------------------
Event logs
Event: {}

调用get操作

命令:call HelloWorld 0x6c1f62cf09bd542a36634776cf0e5eeddb176ddc get

1
2
3
4
5
6
7
8
9
10
11
12
[group:1]> call HelloWorld 0x6c1f62cf09bd542a36634776cf0e5eeddb176ddc get
---------------------------------------------------------------------------------------------
Return code: 0
description: transaction executed successfully
Return message: Success
---------------------------------------------------------------------------------------------
Return value size:1
Return types: (STRING)
Return values:(Hello,cdnkxy)
---------------------------------------------------------------------------------------------

[group:1]>

(4)使用控制台查看区块链中区块高度。

命令:getBlockNumber

1
2
3
4
[group:1]> getBlockNumber
2

[group:1]>

1-3:区块链节点运维

基于已完成的区块链系统与管理平台搭建工作,开展区块链节点的加入与退出运维工作,具体内容如下:

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

​ 1)、修改配置文件: cd /tools/nodes/127.0.0.1/ && vim node0/config.ini

image-20251003142431739

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
root@admin:~/tools# cd nodes/127.0.0.1/
root@admin:~/tools/nodes/127.0.0.1# vim node0/config.ini

[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

​ 2)、重新启动节点node0,使配置文件生效。

​ 命令:bash node0/stop.sh && node0/start.sh

1
2
3
4
5
6
root@admin:~/tools/nodes/127.0.0.1# ./node0/stop.sh
stop node0 success.
root@admin:~/tools/nodes/127.0.0.1# ./node0/start.sh
node0 start successfully
root@admin:~/tools/nodes/127.0.0.1#

(2)通过给定工具(地址/root/tools)完成新节点(node4)配置;

生成新节点

​ 1)、使用gen_node_cert.sh生成新节点node4

​ 命令:cd /root/tools/ && bash gen_node_cert.sh -c nodes/cert/agency -o node4

1
2
3
4
5
6
7
8
9
10
#权限不够要先给gen_node_cert.sh加权限
root@admin:~/tools# chmod 777 gen_node_cert.sh
root@admin:~/tools# ./gen_node_cert.sh -c nodes/cert/agency -o node4
==============================================================
[INFO] Cert Path : nodes/cert/agency/
[INFO] Output Dir : node4
==============================================================
[INFO] All completed. Files in node4
root@admin:~/tools#

​ 2)、将新节点node4复制到节点群nodes目录下。

​ 命令:cp -r ./node4/ nodes/127.0.0.1/

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
root@admin:~/tools# cp -r ./node4/ nodes/127.0.0.1/
root@admin:~/tools# cd nodes/127.0.0.1/
root@admin:~/tools/nodes/127.0.0.1# ll
总用量 28588
drwxr-xr-x 8 root root 4096 10月 3 14:40 ./
drwxr-xr-x 4 root root 4096 10月 3 11:24 ../
-rwxr-xr-x 1 root root 5476 10月 3 11:24 download_bin.sh*
-rwxr-xr-x 1 root root 2932 10月 3 11:24 download_console.sh*
-rwxr-xr-x 1 root root 29213128 10月 3 11:24 fisco-bcos*
drwxr-xr-x 6 root root 4096 10月 3 14:30 node0/
drwxr-xr-x 6 root root 4096 10月 3 11:26 node1/
drwxr-xr-x 6 root root 4096 10月 3 11:26 node2/
drwxr-xr-x 6 root root 4096 10月 3 11:26 node3/
drwxr-xr-x 3 root root 4096 10月 3 14:40 node4/
drwxr-xr-x 2 root root 4096 10月 3 11:24 sdk/
-rwxr-xr-x 1 root root 520 10月 3 11:24 start_all.sh*
-rwxr-xr-x 1 root root 506 10月 3 11:24 stop_all.sh*
-rwxr-xr-x 1 root root 2627 10月 3 11:24 .transTest.sh*
root@admin:~/tools/nodes/127.0.0.1#

​ 3)、将节点node0下的配置文件复制到节点node4目录下。

​ 命令:cd nodes/127.0.0.1/ && cp node0/config.ini node0/start.sh node0/stop.sh node4/

1
2
3
4
5
6
7
8
9
10
11
root@admin:~/tools/nodes/127.0.0.1# cp node0/config.ini node0/start.sh node0/stop.sh node4/
root@admin:~/tools/nodes/127.0.0.1# cd node4
root@admin:~/tools/nodes/127.0.0.1/node4# ll
总用量 24
drwxr-xr-x 3 root root 4096 10月 3 14:42 ./
drwxr-xr-x 8 root root 4096 10月 3 14:40 ../
drwxr-xr-x 2 root root 4096 10月 3 14:40 conf/
-rw-r--r-- 1 root root 1681 10月 3 14:42 config.ini
-rwxr-xr-x 1 root root 1005 10月 3 14:42 start.sh*
-rwxr-xr-x 1 root root 830 10月 3 14:42 stop.sh*
root@admin:~/tools/nodes/127.0.0.1/node4#

​ 4)、修改node4/config.ini

​ 对于[rpc]模块,修改channel_listen_port和jsonrpc_listen_port;

​ 对于[p2p]模块,修改listen_port并在node.中增加自身节点信息;

​ 命令:vi node4/config.ini

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
root@admin:~/tools/nodes/127.0.0.1/node4# vim config.ini
[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


​ 5)、复制群组配置信息

​ 命令:cp node1/conf/group.1.genesis node1/conf/group.1.ini node4/conf/

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
root@admin:~/tools/nodes/127.0.0.1# cp node1/conf/group.1.genesis node1/conf/group.1.ini node4/conf/
root@admin:~/tools/nodes/127.0.0.1# cd node4/conf
root@admin:~/tools/nodes/127.0.0.1/node4/conf# ll
总用量 48
drwxr-xr-x 2 root root 4096 10月 3 14:47 ./
drwxr-xr-x 3 root root 4096 10月 3 14:43 ../
-rw-r--r-- 1 root root 574 10月 3 14:40 agency.crt
-rw-r--r-- 1 root root 664 10月 3 14:40 ca.crt
-rw-r--r-- 1 root root 1257 10月 3 14:47 group.1.genesis
-rw-r--r-- 1 root root 2745 10月 3 14:47 group.1.ini
-rw-r--r-- 1 root root 1825 10月 3 14:40 node.crt
-rw------- 1 root root 237 10月 3 14:40 node.key
-rw-r--r-- 1 root root 129 10月 3 14:40 node.nodeid
-rw-r--r-- 1 root root 71 10月 3 14:40 node.param
-rw-r--r-- 1 root root 65 10月 3 14:40 node.private
-rw-r--r-- 1 root root 174 10月 3 14:40 node.pubkey
root@admin:~/tools/nodes/127.0.0.1/node4/conf#

(3)启动新节点加入区块链系统并验证。

​ 1)、启动新节点

​ 命令: cd node4 && bash stop.sh && bash start.sh

1
2
3
4
5
root@admin:~/tools/nodes/127.0.0.1# cd node4
root@admin:~/tools/nodes/127.0.0.1/node4# ./start.sh
node4 start successfully
root@admin:~/tools/nodes/127.0.0.1/node4#

​ 2)、检查新节点连接情况

image-20251003160032438

1-4:区块链网络运维

根据任务描述要求,完成网络配置与管理运维操作,具体内容如下:

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

设置黑名单

​ 1)、查看node0节点的连接状态日志(现有4个节点连接)

注意:如果查询不到连接状态,修改node0的配置文件中的日志级别为info。

​ 命令:tail -f node0/log/log* | grep connected

​ 2)编辑节点node0的config.ini文件,将node3设为黑名单禁止连接

​ 命令:vi node0/config.ini

​ 编辑certificate_blacklist,设置node3节点ID为黑名单。

​ 查看node3的节点ID(cat nodes/127.0.0.1/node3/conf/node.nodeid

注意:crl.0的注释;要删除(即把前置的分号删除

​ 3)重新启动节点
​ 命令:bash node0/stop.sh && node0/start.sh

​ 4)查看node0节点的连接状态日志(现有3个节点连接)

​ 命令:tail -f node0/log/log* | grep connected

​ 5)重复操作(1)-(4)完成node1节点配置和验证

​ 6)重复操作(1)-(4)完成node2节点配置和验证

​ 7)重复操作(1)-(4)完成node4节点配置和验证

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

配置交易限制

​ 1)、启动控制台:命令:bash start.sh

​ 2)设置区块打包最大交易数量为2000

​ 命令: setSystemConfigByKey tx_count_limit 2000

(3) 验证区块最大打包交易数量情况。

检查区块最大打包交易数量设置生效

​ 命令:getSystemConfigByKey tx_count_limit