美文网首页Hyperledger
Hyperledger Fabric实践(1) 组建最简网络

Hyperledger Fabric实践(1) 组建最简网络

作者: 假装在去天使之城的路上 | 来源:发表于2018-06-23 13:54 被阅读16次

    悄悄告诉你

    这个链接卧虎藏龙:
    HiBlock区块链技术布道 GitHub

    Fabric和Composer的关系:

    Hyperledger的Composer和Fabric到底是什么关系?

    目标

    通过动手启动一个最简单的Hyperledger Fabric网络,来进一步了解Hyperledger Fabric的网络构成。
    这里介绍的步骤,以及代码可能不适用于最新Docker Image,我们在这里主要关注网络结构。

    这个网络将包含:

    • 两个参与方
    • 每个参与方有两个节点
    • 有一个 排序节点

    准备

    Prerequisites

    Hyperledger Fabric Samples

    我们将会使用: first-network来演示。

    开启我们的第一网络

    打开目标目录

    cd fabric-samples/first-network
    

    在first-network的文件夹下面,有一个包含了我们启动所需要全部步骤(两个参与方,每个参与方维护两个节点,有一个独立的排序节点)的脚本文件 byfn.sh,这个脚本文件附带注解,有兴趣的童靴可以研究一下。

    • 查询 byfn.sh的文档
    ./byfn.sh --help
    
    Usage: 
      byfn.sh -m up|down|restart|generate 
    
    Typically, one would first generate the required certificates and 
    genesis block, then bring up the network. e.g.:
        byfn.sh -m generate -c mychannel
        byfn.sh -m up -c mychannel -s couchdb
        byfn.sh -m up -c mychannel -s couchdb -i 1.0.6
        byfn.sh -m down -c mychannel
    
    Taking all defaults:
        byfn.sh -m generate
        byfn.sh -m up
        byfn.sh -m down
    

    生成网络需要的要素

    ./byfn.sh -m generate
    
    Generating certs and genesis block for with channel 'mychannel' and CLI timeout of '10'
    Continue (y/n)? 
    
    生成证书,以及一个叫做'mychannel'的通道,并为此通道配置一个区块,最长等待请求的时长为10秒?
    输入y。
    你可以通过参数来个性化配置网络
    

    然后屏幕上就生成了一大堆的输出。根本就不想看对吧?不想看的童鞋可以直接跳到下一个步骤。

    ##########################################################
    ##### Generate certificates using cryptogen tool #########
    ##########################################################
    org1.example.com
    org2.example.com
    
    通过 cryptogen tool 生成数字证书
    
    ##########################################################
    #########  Generating Orderer Genesis block ##############
    ##########################################################
    2018-06-23 13:32:34.246 JST [common/configtx/tool] main -> INFO 001 Loading configuration
    2018-06-23 13:32:34.416 JST [common/configtx/tool] doOutputBlock -> INFO 002 Generating genesis block
    2018-06-23 13:32:34.417 JST [common/configtx/tool] doOutputBlock -> INFO 003 Writing genesis block
    
    生成排序节点,以及创世纪区块(第一个区块)
    
    #################################################################
    ### Generating channel configuration transaction 'channel.tx' ###
    #################################################################
    2018-06-23 13:32:34.462 JST [common/configtx/tool] main -> INFO 001 Loading configuration
    2018-06-23 13:32:34.464 JST [common/configtx/tool] doOutputChannelCreateTx -> INFO 002 Generating new channel configtx
    2018-06-23 13:32:34.464 JST [common/configtx/tool] doOutputChannelCreateTx -> INFO 003 Writing new channel tx
    
    生成渠道配置交易:'channel.tx'
    
    #################################################################
    #######    Generating anchor peer update for Org1MSP   ##########
    #################################################################
    2018-06-23 13:32:34.475 JST [common/configtx/tool] main -> INFO 001 Loading configuration
    2018-06-23 13:32:34.479 JST [common/configtx/tool] doOutputAnchorPeersUpdate -> INFO 002 Generating anchor peer update
    2018-06-23 13:32:34.480 JST [common/configtx/tool] doOutputAnchorPeersUpdate -> INFO 003 Writing anchor peer update
    
    #################################################################
    #######    Generating anchor peer update for Org2MSP   ##########
    #################################################################
    2018-06-23 13:32:34.490 JST [common/configtx/tool] main -> INFO 001 Loading configuration
    2018-06-23 13:32:34.494 JST [common/configtx/tool] doOutputAnchorPeersUpdate -> INFO 002 Generating anchor peer update
    2018-06-23 13:32:34.494 JST [common/configtx/tool] doOutputAnchorPeersUpdate -> INFO 003 Writing anchor peer update
    
    生成anchor peer,别且将其分配给各个参与方
    

    启动网络

    ./byfn.sh -m up
    
    Starting with channel 'mychannel' and CLI timeout of '10'
    Continue (y/n)? 
    
    启动'mychannel'?
    输入y。
    

    然后屏幕上又出现了一堆代码,不想看的童靴可以跳过。

    Creating network "net_byfn" with the default driver
    生成网络
    
    Creating volume "net_orderer.example.com" with default driver
    生成排序节点数据
    
    volume是Docker里面,存储数据的一种方法。
    详细可以参照:https://docs.docker.com/storage/volumes/
    
    Creating volume "net_peer0.org1.example.com" with default driver
    Creating volume "net_peer1.org1.example.com" with default driver
    Creating volume "net_peer0.org2.example.com" with default driver
    Creating volume "net_peer1.org2.example.com" with default driver
    生成四个节点数据
    
    Creating peer0.org2.example.com ... done
    Creating peer1.org1.example.com ... done
    Creating peer1.org2.example.com ... done
    Creating peer0.org1.example.com ... done
    生成四个节点
    
    Creating orderer.example.com    ... done
    
    生成排序节点
    
    Creating cli                    ... done
    生成命令行接口
    
     ____    _____      _      ____    _____ 
    / ___|  |_   _|    / \    |  _ \  |_   _|
    \___ \    | |     / _ \   | |_) |   | |  
     ___) |   | |    / ___ \  |  _ <    | |  
    |____/    |_|   /_/   \_\ |_| \_\   |_|  
    
    
    Channel name : mychannel
    Creating channel...
    生成渠道
    
    Query Result: 90
    2018-06-23 04:57:52.496 UTC [main] main -> INFO 008 Exiting.....
    ===================== Query on PEER3 on channel 'mychannel' is successful ===================== 
    
    ========= All GOOD, BYFN execution completed =========== 
    
    
     _____   _   _   ____   
    | ____| | \ | | |  _ \  
    |  _|   |  \| | | | | | 
    | |___  | |\  | | |_| | 
    |_____| |_| \_| |____/  
    
    网络启动后,然后自动执行一连串的点对点的交易,如果交易都顺利完成了,你将看到这个提示。
    具体交易流程和内容,可以更加输出的log来确认。我们下次再学习了。
    
    docker ps
    查看Docker的状态
    
     
    CONTAINER ID        IMAGE                                                                                                  COMMAND                  PORTS                                              NAMES
    91f7854cce55        dev-peer1.org2.example.com-mycc-1.0-26c2ef32838554aac4f7ad6f100aca865e87959c9a126e86d764c8d01f8346ab   "chaincode -peer.add…"                                                      dev-peer1.org2.example.com-mycc-1.0
    dc4a6df35ca5        dev-peer0.org1.example.com-mycc-1.0-384f11f484b9302df90b453200cfb25174305fce8f53f4e94d45ee3b6cab0ce9   "chaincode -peer.add…"                                                      dev-peer0.org1.example.com-mycc-1.0
    d60e45ed340a        dev-peer0.org2.example.com-mycc-1.0-15b571b3ce849066b7ec74497da3b27e54e0df1345daff3951b94245ce09c42b   "chaincode -peer.add…"                                                      dev-peer0.org2.example.com-mycc-1.0
    各个节点上生成的智能合约。(好像少了一个,没有dev-peer1.org1.example.com-mycc-1.0)
    
    ec0de22dfda5        hyperledger/fabric-peer:latest                                                                         "peer node start"        0.0.0.0:7051->7051/tcp, 0.0.0.0:7053->7053/tcp     peer0.org1.example.com
    fbbddcc6e511        hyperledger/fabric-peer:latest                                                                         "peer node start"        0.0.0.0:10051->7051/tcp, 0.0.0.0:10053->7053/tcp   peer1.org2.example.com
    acb521a4dff8        hyperledger/fabric-peer:latest                                                                         "peer node start"        0.0.0.0:8051->7051/tcp, 0.0.0.0:8053->7053/tcp     peer1.org1.example.com
    555938e16fcb        hyperledger/fabric-peer:latest                                                                         "peer node start"        0.0.0.0:9051->7051/tcp, 0.0.0.0:9053->7053/tcp     peer0.org2.example.com
    节点
    
    7f6f7b69635c        hyperledger/fabric-orderer:latest                                                                      "orderer"                0.0.0.0:7050->7050/tcp                             orderer.example.com
    排序节点
    
    

    关闭网络

    在完成交易之后,你希望Docker释放生成的所有: containers, the crypto material, four artifacts, 以及the chaincode images

    ./byfn.sh -m down
    Stopping with channel 'mychannel' and CLI timeout of '10'
    Continue (y/n)? 
    
    关闭通道'mychannel'?
    输入y。
    
    Stopping orderer.example.com    ... done
    
    Stopping peer1.org2.example.com ... done
    Stopping peer1.org2.example.com ... done
    Stopping peer1.org1.example.com ... done
    Stopping peer0.org2.example.com ... done
    
    Removing cli                    ... done
    
    Removing orderer.example.com    ... done
    
    Removing peer0.org1.example.com ... done
    Removing peer1.org2.example.com ... done
    Removing peer1.org1.example.com ... done
    Removing peer0.org2.example.com ... done
    
    Removing network net_byfn
    
    

    再次查看Docker的状态

    docker ps

    所有的containers都消失了。

    图片来源

    图片来自官方网站

    相关链接

    Ledger

    相关文章

      网友评论

        本文标题:Hyperledger Fabric实践(1) 组建最简网络

        本文链接:https://www.haomeiwen.com/subject/jqwryftx.html