FISCO BCOS是由国内企业主导研发、对外开源、安全可控的企业级金融联盟链底层平台,由金链盟开源工作组协作打造,并于2017年正式对外开源。
社区以开源链接多方,截止2020年5月,汇聚了超1000家企业及机构、逾万名社区成员参与共建共治,发展成为最大最活跃的国产开源联盟链生态圈。底层平台可用性经广泛应用实践检验,数百个应用项目基于FISCO BCOS底层平台研发,超80个已在生产环境中稳定运行,覆盖文化版权、司法服务、政务服务、物联网、金融、智慧社区等领域
FISCO BCOS以联盟链的实际需求为出发点,兼顾性能、安全、可运维性、易用性、可扩展性,支持多种SDK,并提供了可视化的中间件工具,大幅缩短建链、开发、部署应用的时间。此外,FISCO BCOS通过信通院可信区块链评测功能、性能两项评测,单链TPS可达两万。
本搭建教程参考https://fisco-bcos-documentation.readthedocs.io/zh_CN/latest/docs/installation.html
yum install -y openssl openssl-devel
## 创建操作目录
cd ~ && mkdir -p fisco && cd fisco
## 下载脚本
curl -#LO https://github.com/FISCO-BCOS/FISCO-BCOS/releases/download/v2.7.2/build_chain.sh && chmod u+x build_chain.sh
bash build_chain.sh -l 127.0.0.1:4 -p 30300,20200,8545
其中-p选项指定起始端口,分别是p2p_port,channel_port,jsonrpc_port
出于安全性和易用性考虑,v2.3.0版本最新配置将listen_ip拆分成jsonrpc_listen_ip和channel_listen_ip,但仍保留对listen_ip的解析功能,为便于开发和体验,channel_listen_ip参考配置是 0.0.0.0 ,出于安全考虑,请根据实际业务网络情况,修改为安全的监听地址,如:内网IP或特定的外网IP
命令执行成功会输出All completed
。如果执行出错,请检查nodes/build.log文件中的错误信息。
bash nodes/127.0.0.1/start_all.sh
##执行日志:
[root@localhost fisco]# bash nodes/127.0.0.1/start_all.sh
try to start node0
try to start node1
try to start node2
try to start node3
node0 start successfully
node2 start successfully
node3 start successfully
node1 start successfully
ps -ef | grep -v grep | grep fisco-bcos
##执行日志:
[root@localhost fisco]# ps -ef | grep -v grep | grep fisco-bcos
root 13820 1 3 10:06 pts/0 00:00:00 /root/fisco/nodes/127.0.0.1/node0/../fisco-bcos -c config.ini
root 13827 1 3 10:06 pts/0 00:00:00 /root/fisco/nodes/127.0.0.1/node2/../fisco-bcos -c config.ini
root 13831 1 3 10:06 pts/0 00:00:00 /root/fisco/nodes/127.0.0.1/node3/../fisco-bcos -c config.ini
root 13833 1 3 10:06 pts/0 00:00:00 /root/fisco/nodes/127.0.0.1/node1/../fisco-bcos -c config.ini
正常情况会不停地输出连接信息,从输出可以看出node0与另外3个节点有连接。
tail -f nodes/127.0.0.1/node0/log/log* | grep connected
##日志
[root@localhost fisco]# tail -f nodes/127.0.0.1/node0/log/log* | grep connected
info|2021-07-14 10:07:53.453594|[P2P][Service] heartBeat,connected count=3
info|2021-07-14 10:08:03.454509|[P2P][Service] heartBeat,connected count=3
info|2021-07-14 10:08:13.454700|[P2P][Service] heartBeat,connected count=3
执行下面指令,检查是否在共识
tail -f nodes/127.0.0.1/node0/log/log* | grep +++
正常情况会不停输出++++Generating seal
,表示共识正常。
[root@localhost fisco]# tail -f nodes/127.0.0.1/node0/log/log* | grep +++
info|2021-07-14 10:09:21.536245|[g:1][CONSENSUS][SEALER]++++++++++++++++ Generating seal on,blkNum=1,tx=0,nodeIdx=2,hash=05f54a7b...
info|2021-07-14 10:09:25.571959|[g:1][CONSENSUS][SEALER]++++++++++++++++ Generating seal on,blkNum=1,tx=0,nodeIdx=2,hash=41fea7de...
在控制台链接FISCO BCOS节点,实现查询区块链状态、部署调用合约等功能,能够快速获取到所需要的信息。
cd ~/fisco && curl -LO https://github.com/FISCO-BCOS/console/releases/download/v2.7.2/download_console.sh && bash download_console.sh
如果因为网络问题导致长时间无法下载,请尝试 cd ~/fisco && curl -#LO https://gitee.com/FISCO-BCOS/console/raw/master/tools/download_console.sh
# 最新版本控制台使用如下命令拷贝配置文件
cp -n console/conf/config-example.toml console/conf/config.toml
cp -r nodes/127.0.0.1/sdk/* console/conf/
cd ~/fisco/console && bash start.sh
输出下述信息表明启动成功 否则请检查conf/config.toml中节点端口配置是否正确
[root@localhost fisco]# cd ~/fisco/console && bash start.sh
=============================================================================================
Welcome to FISCO BCOS console(2.7.2)!
Type 'help' or 'h' for help. Type 'quit' or 'q' to quit console.
________ ______ ______ ______ ______ _______ ______ ______ ______
| | \/ \ / \ / \ | \ / \ / \ / \
| $$$$$$$$\$$$$$| $$$$$$| $$$$$$| $$$$$$\ | $$$$$$$| $$$$$$| $$$$$$| $$$$$$\
| $$__ | $$ | $$___\$| $$ \$| $$ | $$ | $$__/ $| $$ \$| $$ | $| $$___\$$
| $$ \ | $$ \$$ \| $$ | $$ | $$ | $$ $| $$ | $$ | $$\$$ \
| $$$$$ | $$ _\$$$$$$| $$ __| $$ | $$ | $$$$$$$| $$ __| $$ | $$_\$$$$$$\
| $$ _| $$_| \__| $| $$__/ | $$__/ $$ | $$__/ $| $$__/ | $$__/ $| \__| $$
| $$ | $$ \\$$ $$\$$ $$\$$ $$ | $$ $$\$$ $$\$$ $$\$$ $$
\$$ \$$$$$$ \$$$$$$ \$$$$$$ \$$$$$$ \$$$$$$$ \$$$$$$ \$$$$$$ \$$$$$$
=============================================================================================
[group:1]>
pragma solidity ^0.4.24;
contract HelloWorld {
string name;
function HelloWorld() {
name = "Hello, World!";
}
function get()constant returns(string) {
return name;
}
function set(string n) {
name = n;
}
}
[group:1]> deploy HelloWorld
transaction hash: 0xd1d9eedee03ab6c3adca63ea9aad9d3cb2b5427facb3ac06a79fb7ec72161eca
contract address: 0xb2afdcdd5ce9474289e007449e755f1847dfc765
currentAccount: 0x486b5c882efb7db6adee929416d4a6f21682f3b4
# 查看当前块高
[group:1]> getBlockNumber
1
# 调用get接口获取name变量 此处的合约地址是deploy指令返回的地址
[group:1]> call HelloWorld 0xb2afdcdd5ce9474289e007449e755f1847dfc765 get
---------------------------------------------------------------------------------------------
Return code: 0
description: transaction executed successfully
Return message: Success
---------------------------------------------------------------------------------------------
Return value size:1
Return types: (STRING)
Return values:(Hello, World!)
---------------------------------------------------------------------------------------------
# 查看当前块高,块高不变,因为get接口不更改账本状态
[group:1]> getBlockNumber
1
# 调用set设置name
[group:1]> call HelloWorld 0xb2afdcdd5ce9474289e007449e755f1847dfc765 set "Hello, FISCO BCOS"
transaction hash: 0x03eb38cec260b38db496196a7fd7cbedb5ba3dc094d8a316cf51b26e97731bb5
---------------------------------------------------------------------------------------------
transaction status: 0x0
description: transaction executed successfully
---------------------------------------------------------------------------------------------
Receipt message: Success
Return message: Success
Return values:[]
---------------------------------------------------------------------------------------------
Event logs
Event: {}
# 再次查看当前块高,块高增加表示已出块,账本状态已更改
[group:1]> getBlockNumber
2
# 调用get接口获取name变量,检查设置是否生效
[group:1]> call HelloWorld 0xb2afdcdd5ce9474289e007449e755f1847dfc765 get
---------------------------------------------------------------------------------------------
Return code: 0
description: transaction executed successfully
Return message: Success
---------------------------------------------------------------------------------------------
Return value size:1
Return types: (STRING)
Return values:(Hello, FISCO BCOS)
---------------------------------------------------------------------------------------------
# 退出控制台
[group:1]> quit