前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >微众联盟链fiscobcos 2.1安装

微众联盟链fiscobcos 2.1安装

作者头像
Zeal
发布2020-11-11 15:56:08
8420
发布2020-11-11 15:56:08
举报
文章被收录于专栏:Hyperledger实践Hyperledger实践

FISCO BCOS即Finacial blockchain shenzhen consrotium, 深圳金融区块链合作联盟, 简称金盟链。Fiscobcos性能蛮不错的, 安装学习下。

1.依赖环境

在centos下为例,依赖openssl, curl,切到root执行

代码语言:javascript
复制
yum install openssl curl

下载安装脚本build_chain.sh

代码语言:javascript
复制
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节点联盟链

代码语言:javascript
复制
bash build_chain.sh -l "127.0.0.1:4" -p 30300,20200,8545

运行结果,这三个端口分别是p2p_port,channel_port,jsonrpc_port

代码语言:javascript
复制
==============================================================
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

我们看下生成的文件结构

代码语言:javascript
复制
[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.启动所有节点

代码语言:javascript
复制
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

检查四个节点进程

代码语言:javascript
复制
[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应该和其它三个节点连接

代码语言:javascript
复制
[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

查看共识日志,一些封装出块信息

代码语言:javascript
复制
[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写的东西有点大几十兆下载有点慢。

代码语言:javascript
复制
bash <(curl -s https://raw.githubusercontent.com/FISCO-BCOS/console/master/tools/download_console.sh)

貌似是spring框架开发的,需要配置下。

代码语言:javascript
复制
cp -n console/conf/applicationContext-sample.xml console/conf/applicationContext.xml
cp nodes/127.0.0.1/sdk/* console/conf/

启动控制台

代码语言:javascript
复制
cd console && bash start.sh

这里对JDK有有些要求, centos自带的openjdk是跑不起来的,有以下错误。应该是一些加密库实现的差异,需要使用的oracle JDK。

代码语言:javascript
复制
Failed to connect to the node. Please check the node status and the console configuration.

运行成功控制台如下:

代码语言:javascript
复制
[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可以显示所有命令,一些例子

代码语言:javascript
复制
[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的智能合约。

代码语言:javascript
复制
[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内容如下:

代码语言:javascript
复制
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合约

代码语言:javascript
复制
[group:1]> deploy HelloWorld
contract address: 0x79ea4777a3759d36c142bb6365691f427cebb6

调用HelloWorld合约

代码语言:javascript
复制
[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的核心概念。

本文参与 腾讯云自媒体同步曝光计划,分享自微信公众号。
原始发表:2019-12-24,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 Hyperledger实践 微信公众号,前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体同步曝光计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
目录
  • 1.依赖环境
  • 2.创建单群组4节点联盟链
  • 3.启动所有节点
  • 4. 使用控制台
    • 4.1 控制台安装
      • 4.2 控制台交互
      • 5.智能合约
      • 6.总结
      相关产品与服务
      对象存储
      对象存储(Cloud Object Storage,COS)是由腾讯云推出的无目录层次结构、无数据格式限制,可容纳海量数据且支持 HTTP/HTTPS 协议访问的分布式存储服务。腾讯云 COS 的存储桶空间无容量上限,无需分区管理,适用于 CDN 数据分发、数据万象处理或大数据计算与分析的数据湖等多种场景。
      领券
      问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档