微众联盟链fiscobcos 2.1安装
FISCO BCOS即Finacial blockchain shenzhen consrotium, 深圳金融区块链合作联盟, 简称金盟链。Fiscobcos性能蛮不错的, 安装学习下。
1.依赖环境
在centos下为例,依赖openssl, curl,切到root执行
yum install openssl curl
下载安装脚本build_chain.sh
curl -LO https://github.com/FISCO-BCOS/FISCO-BCOS/releases/download/v2.1.0/build_chain.sh && chmod u+x build_chain.sh
2.创建单群组4节点联盟链
bash build_chain.sh -l "127.0.0.1:4" -p 30300,20200,8545
运行结果,这三个端口分别是p2p_port,channel_port,jsonrpc_port
==============================================================
Generating CA key...
==============================================================
Generating keys ...
Processing IP:127.0.0.1 Total:4 Agency:agency Groups:1
==============================================================
Generating configurations...
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] State Type : storage
[INFO] RPC listen IP : 127.0.0.1
[INFO] Output Dir : /mnt/sda3/fisco/nodes
[INFO] CA Key Path : /mnt/sda3/fisco/nodes/cert/ca.key
================================================================
[WARN] RPC listens 127.0.0.1 will cause nodes' JSON-RPC and Channel service to be inaccessible form other machines
[INFO] Execute the following command to get FISCO-BCOS console
bash <(curl -s https://raw.githubusercontent.com/FISCO-BCOS/console/master/tools/download_console.sh)
================================================================
[INFO] All completed. Files in /mnt/sda3/fisco/nodes
我们看下生成的文件结构
[root@k8s-master fisco]# tree
.
├── build_chain.sh
└── nodes
├── 127.0.0.1
│ ├── fisco-bcos
│ ├── node0
│ │ ├── conf
│ │ │ ├── ca.crt
│ │ │ ├── group.1.genesis
│ │ │ ├── group.1.ini
│ │ │ ├── node.crt
│ │ │ ├── node.key
│ │ │ └── node.nodeid
│ │ ├── config.ini
│ │ ├── scripts
│ │ │ ├── load_new_groups.sh
│ │ │ └── reload_whitelist.sh
│ │ ├── start.sh
│ │ └── stop.sh
│ ├── node1
│ │ ├── conf
│ │ │ ├── ca.crt
│ │ │ ├── group.1.genesis
│ │ │ ├── group.1.ini
│ │ │ ├── node.crt
│ │ │ ├── node.key
│ │ │ └── node.nodeid
│ │ ├── config.ini
│ │ ├── scripts
│ │ │ ├── load_new_groups.sh
│ │ │ └── reload_whitelist.sh
│ │ ├── start.sh
│ │ └── stop.sh
│ ├── node2
│ │ ├── conf
│ │ │ ├── ca.crt
│ │ │ ├── group.1.genesis
│ │ │ ├── group.1.ini
│ │ │ ├── node.crt
│ │ │ ├── node.key
│ │ │ └── node.nodeid
│ │ ├── config.ini
│ │ ├── scripts
│ │ │ ├── load_new_groups.sh
│ │ │ └── reload_whitelist.sh
│ │ ├── start.sh
│ │ └── stop.sh
│ ├── node3
│ │ ├── conf
│ │ │ ├── ca.crt
│ │ │ ├── group.1.genesis
│ │ │ ├── group.1.ini
│ │ │ ├── node.crt
│ │ │ ├── node.key
│ │ │ └── node.nodeid
│ │ ├── config.ini
│ │ ├── scripts
│ │ │ ├── load_new_groups.sh
│ │ │ └── reload_whitelist.sh
│ │ ├── start.sh
│ │ └── stop.sh
│ ├── sdk
│ │ ├── ca.crt
│ │ ├── node.crt
│ │ ├── node.key
│ │ ├── sdk.crt
│ │ └── sdk.key
│ ├── start_all.sh
│ └── stop_all.sh
└── cert
├── agency
│ ├── agency.crt
│ ├── agency.key
│ ├── agency.srl
│ ├── ca.crt
│ └── cert.cnf
├── ca.crt
├── ca.key
├── ca.srl
└── cert.cnf
17 directories, 62 files
3.启动所有节点
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
node2 start successfully
node1 start successfully
node3 start successfully
node0 start successfully
检查四个节点进程
[root@k8s-master fisco]# ps -ef | grep -v grep | grep fisco-bcos
root 4216 1 1 21:39 pts/0 00:00:06 /mnt/sda3/fisco/nodes/127.0.0.1/node2/../fisco-bcos -c config.ini
root 4218 1 1 21:39 pts/0 00:00:06 /mnt/sda3/fisco/nodes/127.0.0.1/node1/../fisco-bcos -c config.ini
root 4220 1 1 21:39 pts/0 00:00:06 /mnt/sda3/fisco/nodes/127.0.0.1/node3/../fisco-bcos -c config.ini
root 4222 1 2 21:39 pts/0 00:00:07 /mnt/sda3/fisco/nodes/127.0.0.1/node0/../fisco-bcos -c config.ini
查看连接日志,节点0应该和其它三个节点连接
[root@k8s-master fisco]# tail -f nodes/127.0.0.1/node0/log/log* | grep connected
info|2019-12-23 21:48:48.965591|[P2P][Service] heartBeat,connected count=3
info|2019-12-23 21:48:58.977200|[P2P][Service] heartBeat,connected count=3
info|2019-12-23 21:49:08.979322|[P2P][Service] heartBeat,connected count=3
查看共识日志,一些封装出块信息
[root@k8s-master fisco]# tail -f nodes/127.0.0.1/node0/log/log* | grep +++
info|2019-12-23 21:50:55.232417|[g:1][CONSENSUS][SEALER]++++++++++++++++ Generating seal on,blkNum=1,tx=0,nodeIdx=0,hash=34842cc2...
info|2019-12-23 21:50:59.309530|[g:1][CONSENSUS][SEALER]++++++++++++++++ Generating seal on,blkNum=1,tx=0,nodeIdx=0,hash=758d0004...
info|2019-12-23 21:51:03.449523|[g:1][CONSENSUS][SEALER]++++++++++++++++ Generating seal on,blkNum=1,tx=0,nodeIdx=0,hash=729872b2...
4. 使用控制台
4.1 控制台安装
控制台通过Web3SDK链接FISCO BCOS节点,实现查询区块链状态、部署调用合约等功能,其依赖JDK。切回fisco目录执行下载命令,java写的东西有点大几十兆下载有点慢。
bash <(curl -s https://raw.githubusercontent.com/FISCO-BCOS/console/master/tools/download_console.sh)
貌似是spring框架开发的,需要配置下。
cp -n console/conf/applicationContext-sample.xml console/conf/applicationContext.xml
cp nodes/127.0.0.1/sdk/* console/conf/
启动控制台
cd console && bash start.sh
这里对JDK有有些要求, centos自带的openjdk是跑不起来的,有以下错误。应该是一些加密库实现的差异,需要使用的oracle JDK。
Failed to connect to the node. Please check the node status and the console configuration.
运行成功控制台如下:
[root@k8s-master console]# ./start.sh
=============================================================================================
Welcome to FISCO BCOS console(1.0.5)!
Type 'help' or 'h' for help. Type 'quit' or 'q' to quit console.
________ ______ ______ ______ ______ _______ ______ ______ ______
| | \/ \ / \ / \ | \ / \ / \ / \
| $$$$$$$$\$$$$$| $$$$$$| $$$$$$| $$$$$$\ | $$$$$$$| $$$$$$| $$$$$$| $$$$$$\
| $$__ | $$ | $$___\$| $$ \$| $$ | $$ | $$__/ $| $$ \$| $$ | $| $$___\$$
| $$ \ | $$ \$$ \| $$ | $$ | $$ | $$ $| $$ | $$ | $$\$$ \
| $$$$$ | $$ _\$$$$$$| $$ __| $$ | $$ | $$$$$$$| $$ __| $$ | $$_\$$$$$$\
| $$ _| $$_| \__| $| $$__/ | $$__/ $$ | $$__/ $| $$__/ | $$__/ $| \__| $$
| $$ | $$ \\$$ $$\$$ $$\$$ $$ | $$ $$\$$ $$\$$ $$\$$ $$
\$$ \$$$$$$ \$$$$$$ \$$$$$$ \$$$$$$ \$$$$$$$ \$$$$$$ \$$$$$$ \$$$$$$
=============================================================================================
[group:1]>
4.2 控制台交互
help可以显示所有命令,一些例子
[group:1]> getNodeVersion
{
"Build Time":"20190923 13:22:09",
"Build Type":"Linux/clang/Release",
"Chain Id":"1",
"FISCO-BCOS Version":"2.1.0",
"Git Branch":"HEAD",
"Git Commit Hash":"cb68124d4fbf3df563a57dfff5f0c6eedc1419cc",
"Supported Version":"2.1.0"
}
[group:1]> getPeers
[
{
"Agency":"agency",
"IPAndPort":"127.0.0.1:30301",
"Node":"node1",
"NodeID":"a3bccbdf5a090de3a5a174e629578d08a08b55faea22c515eddda5470414e7a7ddab7b3968cd91df2b4ea83fad920e22e3bbe052f6ce1b1a2b3eb803dd4395cd",
"Topic":[
]
},
{
"Agency":"agency",
"IPAndPort":"127.0.0.1:49368",
"Node":"node3",
"NodeID":"73971a2056fff221f0784402e819a1ba05ab1a7b4a03acda985ecf7b414de4a58c41dfcbafa38fe83ef1e4dd8a7f62480c2e2a4717fa98dea4a41f1d76a6466b",
"Topic":[
]
},
{
"Agency":"agency",
"IPAndPort":"127.0.0.1:30302",
"Node":"node2",
"NodeID":"81a3e29de016bfe4ede4d21827fea31d4aba29a57cb8a8c73377c0313f72ef3611133913c46979faf0972a0bb6c8db40a4568ba48579843454266be121b943d0",
"Topic":[
]
}
]
[group:1]> help
5.智能合约
/fisco/console/contracts/solidity自带了一个HelloWorld的智能合约。
[root@k8s-master solidity]# pwd
/mnt/sda3/fisco/console/contracts/solidity
[root@k8s-master solidity]# ll
总用量 12
-rw-r--r--. 1 6003 6003 266 9月 24 15:33 HelloWorld.sol
-rw-r--r--. 1 6003 6003 1713 9月 24 15:33 Table.sol
-rw-r--r--. 1 6003 6003 3057 9月 24 15:33 TableTest.sol
HelloWorld.sol内容如下:
pragma solidity ^0.4.24;
contract HelloWorld{
string name;
constructor() public{
name = "Hello, World!";
}
function get() constant public returns(string){
return name;
}
function set(string n) public{
name = n;
}
}
控制台部署HelloWorld合约
[group:1]> deploy HelloWorld
contract address: 0x79ea4777a3759d36c142bb6365691f427cebb6
调用HelloWorld合约
[group:1]> getBlockNumber
1
[group:1]> call HelloWorld 0x79ea4777a3759d36c142bb6365691f427cebb673 get
Hello, World!
[group:1]> call HelloWorld 0x79ea4777a3759d36c142bb6365691f427cebb673 set "Hello,Zeal"
transaction hash: 0x920837f04e8f67cf53fadcb30cace55f3e9f219644b522a2444f9ea0ef77568a
[group:1]> getBlockNumber
2
[group:1]> call HelloWorld 0x79ea4777a3759d36c142bb6365691f427cebb673 get
Hello,Zeal
6.总结
牛刀小试,暂时入门例子就主要是fisco-bcos主进程,老版本fabric的peer和orderer以前也是整合在一起的,后续我们再继续学下fisco-bcos的核心概念。
- 原文作者:Zealot
- 原文链接:https://www.51discuss.com/posts/2019-3th-fiscobcos-installation/
- 版权声明:本作品采用知识共享署名-非商业性使用-禁止演绎 4.0 国际许可协议进行许可,非商业转载请注明出处(作者,原文链接),商业转载请联系作者获得授权。