任务1-2:区块链系统部署与运维
通过给定区块链项目需求,进行区块链系统部署,包括系统部署、控制台部署等。通过监控工具完成对网络、节点服务的监控。最终利用业务需求规范,完成系统日志、网络参数、节点服务等系统结构的维护。
- 部署区块链服务器,配置管理平台参数及访问端口;
- 部署项目节点,获取管理平台与节点服务的加密通信;
- 部署应用程序接口服务,应用工具完成接口部署;
- 部署区块链系统,对接应用服务器和数据库。
子任务1-2-1:搭建区块链系统
在本机搭建一条分布式存储的4节点区块链系统,其网络端口要求如下:
机构名称 | 节点数 | P2P端口 | channel端口 | rpc端口 |
---|---|---|---|---|
机构A | 1 | 30100 | 20100 | 8010 |
机构B | 1 | 30200 | 20200 | 8020 |
机构C | 2 | 30300 | 20300 | 8030 |
搭建完区块链系统后,需检查每个节点的连接数和运行状态。
根据题意,需要搭建 4节点 3机构 1群组
每一行的格式
ip:nodeNum agencyName groupList p2p_port,channel_port,jsonrpc_port". eg "127.0.0.1:4 agency1 1,2 30300,20200,8545
在 /root/tools
文件夹下创建 ipconf
并写入以下内容
127.0.0.1:1 agencyA 1 30100,20100,8010
127.0.0.1:1 agencyB 1 30200,20200,8020
127.0.0.1:2 agencyC 1 30300,20300,8030
使用 build_chain.sh
脚本文件创建搭建,指定参数 -f
为配置文件路径 -e
为本地 fisco-bcos
路径
bash build_chain.sh -f /root/tools/ipconf -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=1 Agency=agencyA Groups=1
Processing IP=127.0.0.1 Total=1 Agency=agencyB Groups=1
Processing IP=127.0.0.1 Total=2 Agency=agencyC Groups=1
==============================================================
Generating configuration files ...
Processing IP=127.0.0.1 Total=1 Agency=agencyA Groups=1
Processing IP=127.0.0.1 Total=1 Agency=agencyB Groups=1
Processing IP=127.0.0.1 Total=2 Agency=agencyC Groups=1
==============================================================
Group:1 has 4 nodes
==============================================================
[INFO] FISCO-BCOS Path : /root/tools/fisco-bcos
[INFO] IP List File : /root/tools/ipconf
[INFO] Start Port : 30300 20200 8545
[INFO] Server IP : 127.0.0.1:1 127.0.0.1:1 127.0.0.1:2
[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
进入到节点目录并启动
cd /root/tools/nodes/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
node1 start successfully
node0 start successfully
检查节点运行状态
ps -ef | grep -v grep | grep fisco-bcos
root 42568 1 2 22:15 pts/2 00:00:07 /root/tools/nodes/127.0.0.1/node3/../fisco-bcos -c config.ini
root 42570 1 2 22:15 pts/2 00:00:07 /root/tools/nodes/127.0.0.1/node0/../fisco-bcos -c config.ini
root 42572 1 2 22:15 pts/2 00:00:07 /root/tools/nodes/127.0.0.1/node2/../fisco-bcos -c config.ini
root 42574 1 2 22:15 pts/2 00:00:07 /root/tools/nodes/127.0.0.1/node1/../fisco-bcos -c config.ini
检查节点连接数
tail -f /root/tools/nodes/127.0.0.1/node0/log/log* | grep connected
使用 tail
命令 查看 node0
的日志 并且使用grep进行日志筛选 ,connected
是连接日志的关键词 这里表示 node0与其他三个节点有连接
info|2024-03-07 22:22:19.265058|[P2P][Service] heartBeat,connected count=3
info|2024-03-07 22:22:29.265271|[P2P][Service] heartBeat,connected count=3
info|2024-03-07 22:22:39.265688|[P2P][Service] heartBeat,connected count=3
info|2024-03-07 22:22:49.265973|[P2P][Service] heartBeat,connected count=3
检查节点共识
tail -f /root/tools/nodes/127.0.0.1/node0/log/log* | grep +++
也是 tail
命令 查看 node0
的日志 并且使用grep进行日志筛选 ,++
是共识日志的关键词 这里表示 [g:1]
它在 1 群组
info|2024-03-07 22:31:30.348843|[g:1][CONSENSUS][SEALER]++++++++++++++++ Generating seal on,blkNum=1,tx=0,nodeIdx=3,hash=5afff3a0...
info|2024-03-07 22:31:34.391707|[g:1][CONSENSUS][SEALER]++++++++++++++++ Generating seal on,blkNum=1,tx=0,nodeIdx=3,hash=05a982ed...
info|2024-03-07 22:31:38.424213|[g:1][CONSENSUS][SEALER]++++++++++++++++ Generating seal on,blkNum=1,tx=0,nodeIdx=3,hash=0f57b219...
info|2024-03-07 22:31:42.465376|[g:1][CONSENSUS][SEALER]++++++++++++++++ Generating seal on,blkNum=1,tx=0,nodeIdx=3,hash=04b1277c...
info|2024-03-07 22:31:46.496742|[g:1][CONSENSUS][SEALER]++++++++++++++++ Generating seal on,blkNum=1,tx=0,nodeIdx=3,hash=8a84ba6d...
info|2024-03-07 22:31:50.528327|[g:1][CONSENSUS][SEALER]++++++++++++++++ Generating seal on,blkNum=1,tx=0,nodeIdx=3,hash=bdc7fbce...
info|2024-03-07 22:31:54.553522|[g:1][CONSENSUS][SEALER]++++++++++++++++ Generating seal on,blkNum=1,tx=0,nodeIdx=3,hash=5b7083bd...
子任务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
cp config-example.toml config.toml
修改 config.toml
配置文件
[network]
peers=["127.0.0.1:20200", "127.0.0.1:20201"] # The peer list to connect
回到 root/tools/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]>
查询节点版本信息
getNodeVersion
ClientVersion{
version='2.8.0',
supportedVersion='2.8.0',
chainId='1',
buildTime='20210830 12:52:15',
buildType='Linux/clang/Release',
gitBranch='HEAD',
gitCommitHash='30fb38ac5692468058abf6aa12869d2ae776c275'
}
部署HelloWorld合约
deploy HelloWorld
transaction hash: 0x68fa7d2cbc9ecd6a5152b562479ed2a51d0563f0de9a670c082cde679267d8ef
contract address: 0x3756bedc678fd30d2244f0c6aeee25854f5b8628
currentAccount: 0x8260941110ff1737a165db809e77b0ba4aef6f1d
查看交易回执,解释每个字段含义
交易hash是 HelloWorld
合约的
getTransactionReceipt 0x68fa7d2cbc9ecd6a5152b562479ed2a51d0563f0de9a670c082cde679267d8ef
{
"transactionHash":"0x68fa7d2cbc9ecd6a5152b562479ed2a51d0563f0de9a670c082cde679267d8ef",
"transactionIndex":"0x0",
"root":"0xadcf3e9772344da3f8de6d8f21c57c816e472e7632c03d52cc43f55c581c4551",
"blockNumber":"0x1",
"blockHash":"0x9acf1e551d079298b90d7c9de4dd845c0b991f8842a39928ecb69b5a01deed01",
"from":"0x8260941110ff1737a165db809e77b0ba4aef6f1d",
"to":"0x0000000000000000000000000000000000000000",
"gasUsed":"0x44ab3",
"contractAddress":"0x3756bedc678fd30d2244f0c6aeee25854f5b8628",
"logs":[
],
"logsBloom":"0x00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000",
"status":"0x0",
"statusMsg":"None",
"input":"0x608060405234801561001057600080fd5b506040805190810160405280600d81526020017f48656c6c6f2c20576f726c6421000000000000000000000000000000000000008152506000908051906020019061005c929190610062565b50610107565b828054600181600116156101000203166002900490600052602060002090601f016020900481019282601f106100a357805160ff19168380011785556100d1565b828001600101855582156100d1579182015b828111156100d05782518255916020019190600101906100b5565b5b5090506100de91906100e2565b5090565b61010491905b808211156101005760008160009055506001016100e8565b5090565b90565b6102d7806101166000396000f30060806040526004361061004c576000357c0100000000000000000000000000000000000000000000000000000000900463ffffffff1680634ed3885e146100515780636d4ce63c146100ba575b600080fd5b34801561005d57600080fd5b506100b8600480360381019080803590602001908201803590602001908080601f016020809104026020016040519081016040528093929190818152602001838380828437820191505050505050919291929050505061014a565b005b3480156100c657600080fd5b506100cf610164565b6040518080602001828103825283818151815260200191508051906020019080838360005b8381101561010f5780820151818401526020810190506100f4565b50505050905090810190601f16801561013c5780820380516001836020036101000a031916815260200191505b509250505060405180910390f35b8060009080519060200190610160929190610206565b5050565b606060008054600181600116156101000203166002900480601f0160208091040260200160405190810160405280929190818152602001828054600181600116156101000203166002900480156101fc5780601f106101d1576101008083540402835291602001916101fc565b820191906000526020600020905b8154815290600101906020018083116101df57829003601f168201915b5050505050905090565b828054600181600116156101000203166002900490600052602060002090601f016020900481019282601f1061024757805160ff1916838001178555610275565b82800160010185558215610275579182015b82811115610274578251825591602001919060010190610259565b5b5090506102829190610286565b5090565b6102a891905b808211156102a457600081600090555060010161028c565b5090565b905600a165627a7a72305820e32c234959759785da20746da4dd6fd062f151034e74512bc1bc1c181c0c810f0029",
"output":"0x",
"txProof":null,
"receiptProof":null,
"message":null,
"statusOK":true
}
- input: 交易输入的ABI编码十六进制字符串
- output :交易返回的ABI编码十六进制字符串logs :event log列表,保存交易的event信息
- statusOk: 交易状态
- status : 状态码【可用来判断是否交易成功】
- blockNumber : 区块高度
- blockHash: 区块的hash
- gasUsed: 这次交易消耗的gas量
- from:是谁发起交易
- to : 对谁发起交易,这里由于部署合约,所以是0x0000000000000000000000000000000000000000
其它的自行看官网
查询部署合约的区块信息
刚才只部署了合约没有进行任何交易,所有是 1
getBlockByNumber 1
{
transactions=[
TransactionHash{
value='0x68fa7d2cbc9ecd6a5152b562479ed2a51d0563f0de9a670c082cde679267d8ef'
}
],
number='0x1',
hash='0x9acf1e551d079298b90d7c9de4dd845c0b991f8842a39928ecb69b5a01deed01',
parentHash='0xb7f3e61bdef3b91c6c2448dbeb53dad5ea0ffab4c199a542b3e14eca7642559a',
logsBloom='0x00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000',
transactionsRoot='0x097153a6b2d88febaad7ebf5478fe352ffb44568948119ca2c9876bf7c1f6d2a',
receiptsRoot='0x86566f567b38be0de8d64b6ab8174a46261e0f26334fd730862ed37a1907d760',
dbHash='0xadcf3e9772344da3f8de6d8f21c57c816e472e7632c03d52cc43f55c581c4551',
stateRoot='0xadcf3e9772344da3f8de6d8f21c57c816e472e7632c03d52cc43f55c581c4551',
sealer='0x2',
sealerList=[
3ac9fab71c5533b8c74d287866acedff00e2d0def407cf311df9e7b70c7c1493c8aa757d61c636e039fd53032846a30a328b3969283f2c5472fcd917eb79c82d,
8194c0ee03dc4e006b7cba065c1a4d7e0e693eef731ccfeb3839ee7136a4f7f7aac92095a29d36c1675ca71b0c0fac9271aa3524f6de830101a9cfeef24b56c6,
aa4fe6fc1db47e34bfaae90abd34ae6a14488949496865fcf95bb3a5efa51e77647ca16ace70da9c249ec574e78c98092a0fc186920fd1688d98751e81f20dd3,
e0d10d6078b5c413edaa90b94a6cb28432a8fd1eddde235289b9cd39238777e3c582177fd3d5f02b1934b2a1b33718a17e3c9d04578416f4ced15053a3998842
],
extraData=[
],
gasLimit='0x0',
gasUsed='0x0',
timestamp='0x18e19679d82',
signatureList=null
}
子任务1-2-3:区块链系统权限分配
把三个账号分别设置为委员账号
先创建三个账号,使用 newAccount
newAccount
[group:1]> newAccount
AccountPath: account/ecdsa/0x6eed2d6b063e71bb16086eb46c4425426d67b014.pem
Note: This operation does not create an account in the blockchain, but only creates a local account, and deploying a contract through this account will create an account in the blockchain
newAccount: 0x6eed2d6b063e71bb16086eb46c4425426d67b014
AccountType: ecdsa
[group:1]> newAccount
AccountPath: account/ecdsa/0x3f2c7fa068b0a7b0ff1e0579c087eb3dd755c087.pem
Note: This operation does not create an account in the blockchain, but only creates a local account, and deploying a contract through this account will create an account in the blockchain
newAccount: 0x3f2c7fa068b0a7b0ff1e0579c087eb3dd755c087
AccountType: ecdsa
[group:1]> newAccount
AccountPath: account/ecdsa/0x4ec1b4d20bfa3e1ea36f04756d82f2f879ad7b52.pem
Note: This operation does not create an account in the blockchain, but only creates a local account, and deploying a contract through this account will create an account in the blockchain
newAccount: 0x4ec1b4d20bfa3e1ea36f04756d82f2f879ad7b52
AccountType: ecdsa
先把设置 机构 A
设置 委员账号
,由于刚才启动控制台没有指定账户,现在是无名委员账号,可以直接指定委员账号
grantCommitteeMember 0x6eed2d6b063e71bb16086eb46c4425426d67b014
{
"code":1,
"msg":"Success"
}
现在 委员账号
是 机构A
,需要登录 机构A
账户,使用 loadAccount
登录账户
loadAccount 0x6eed2d6b063e71bb16086eb46c4425426d67b014
再设置 机构B
为 委员账号
grantCommitteeMember 0x3f2c7fa068b0a7b0ff1e0579c087eb3dd755c087
再设置 机构C
为 委员账号
的时候就需要委员投票大于50%才能设置成功,现在登录的是 机构A
投票完,再登录 机构B
账号进行投票
grantCommitteeMember 0x4ec1b4d20bfa3e1ea36f04756d82f2f879ad7b52
loadAccount 0x3f2c7fa068b0a7b0ff1e0579c087eb3dd755c087
grantCommitteeMember 0x4ec1b4d20bfa3e1ea36f04756d82f2f879ad7b52
返回 code
是 1 设置成功
{
"code":1,
"msg":"Success"
}
设置机构 A 账号的投票权重为2
现在登录的账号是 机构B
,设置为需要登录 机构C
,投票一下
updateCommitteeMemberWeight 0x6eed2d6b063e71bb16086eb46c4425426d67b014 2
loadAccount 0x4ec1b4d20bfa3e1ea36f04756d82f2f879ad7b52
updateCommitteeMemberWeight 0x6eed2d6b063e71bb16086eb46c4425426d67b014 2
查询投票权重为2
queryCommitteeMemberWeight 0x6eed2d6b063e71bb16086eb46c4425426d67b014
Account: 0x6eed2d6b063e71bb16086eb46c4425426d67b014 Weight: 2
新增运维账号D,并部署HelloWorld合约
创建一个新账号
newAccount
设置运维角色
grantOperator 0xf68ddccc6d77efe1fc346c64593326de9ea9a430
登录运维账号
loadAccount 0xf68ddccc6d77efe1fc346c64593326de9ea9a430
部署HelloWorld
deploy HelloWorld
评论区