美文网首页
005 hypeledger-fabric 启动网络(自动)

005 hypeledger-fabric 启动网络(自动)

作者: 唐僧取经 | 来源:发表于2018-08-05 12:25 被阅读0次

    一、启动网络步骤

    • 1.生成组织结构 sudo ./byfn.sh -m generate

      • 生成组织结构及身份证书(保存在当前目录的crypto-config目录下)

      • 生成orderer初始区块配置文件(保存在当前的目录的channel-artifacts目录下 ,genesis.block)

      • 生成应用通道交易配置文件(保存在当前的目录的channel-artifacts目录下,channel.tx)

      • 组织中锚节点更新配置文件(保存在当前的目录的channel-artifacts目录下,Org1MSPanchors.tx、Org2MSPanchors.tx)

        • 检查当前组织中新加入的节点
        • 跨组织数据交换
    • 2.启动网络 sudo ./byfn.sh -m up

      • 进入cli容器
      • 创建应用通道(根据指定的应用通道配置文件)
      • 将制定的节点加入到应用通道中
      • 在制定的节点中安装链码
      • 将安装的链码进行实例化
      链码必须在制定的节点上安装
      指定的节点安装链码成功后,需要对链码进行实例化,但是实例化只需要执行一次即可
      在实例化链码的时候,指定-P 指定策略规则
      
      
      • 调用链码对账本数据进行操作
    • 3.关闭网络 sudo ./byfm.sh down

      
      删除生成的所有组织结构及身份证书目录
      删除生成的channel-artifacts/目录下的四个配置文件
      

    二、具体操作过程

    进入fabric 目录中

    $ cd fabric-samples/first-network

    first-network目录下有两个自动化脚本byfn.sheyfn.sh, 这两个脚本的启动顺序是先执行byfn.sh再执行eyfn.sh(eyfn.sh不是必须的)

    查看帮助信息:

    $ ./byfn.sh --help
    启动模式

     <mode> - one of 'up', 'down', 'restart' or 'generate'
          - 'up' - bring up the network with docker-compose up
          - 'down' - clear the network with docker-compose down
          - 'restart' - restart the network
          - 'generate' - generate required certificates and genesis block
          - 'upgrade'  - upgrade the network from v1.0.x to v1.1
    -c <channel name> - channel name to use (defaults to "mychannel")
        -t <timeout> - CLI timeout duration in seconds (defaults to 10)
        -d <delay> - delay duration in seconds (defaults to 3)
        -f <docker-compose-file> - specify which docker-compose file use (defaults to docker-compose-cli.yaml)
        -s <dbtype> - the database backend to use: goleveldb (default) or couchdb
        -l <language> - the chaincode language: golang (default) or node
        -i <imagetag> - the tag to be used to launch the network (defaults to "latest")
    
    
    
    
    
    
    up:启动网络
    down:关闭网络
    restart:重新启动
    generate:生成网络环境中的组织结构及相应的证书及创世块
    upgrade:将网络从1.0升级到1.1
    
    -c:用于指定channelName,默认值"mychannel"
    -t:CLI timeout时间,默认值10
    -d:延迟启动,默认值3
    -f:使用指定的网络拓扑结构文件,默认使用docker-compose-cli.yaml
    -s:指定使用的数据库,可选 go leveldb或couchdb
    -l:指定chaincode使用的语言,可选golang 或node
    -i:指定镜像tag,默认 "latest"
    
    

    生成证书和密钥

    为各种网络实体生成所有证书和密钥,用于引导订购服务以及配置通道所需的一系列配置事务
    生成网络环境中的组织结构及相应的证书及创世块

    $ sudo ./byfn.sh -m generate

    执行结果:

    1命令:生成组织结构和身份证书   使用当前路径./crypto-config.yaml这个配置文件生成
    + cryptogen generate --config=./crypto-config.yaml
    生成了两个peer组织:
    org1.example.com
    org2.example.com
    
    /home/chelsea/hyfa/fabric-samples/first-network/../bin/configtxgen
    
    2命令:生成orderer初始区块 profile指定配置模版。 outputBlock生成的创世区块的路径及名称
    + configtxgen -profile TwoOrgsOrdererGenesis -outputBlock ./channel-artifacts/genesis.block
    
    3命令:生成通道的配置交易文件profile指定模版名称outputCreateChannelTx生成通道的配置文件保存路径及文件名称
    + configtxgen -profile TwoOrgsChannel -outputCreateChannelTx ./channel-artifacts/channel.tx -channelID mychannel
    
    4.1命令:生成org1锚节点更新文件 profile指定模版名称,outputAnchorPeersUpdate指定输出路径及文件名称 asOrg指定哪一个组织ID
    + configtxgen -profile TwoOrgsChannel -outputAnchorPeersUpdate ./channel-artifacts/Org1MSPanchors.tx -channelID mychannel -asOrg Org1MSP
    
    4.2命令:生成org2锚节点组织名称变化,文件名称变化
    + configtxgen -profile TwoOrgsChannel -outputAnchorPeersUpdate ./channel-artifacts/Org2MSPanchors.tx -channelID mychannel -asOrg Org2MSP
        
    

    前提准备:
    1、生成组织结构及身份证书
    2、创建orderer的初始区块
    创建初始区块,是为了启动orderer服务(排序,生成区块)
    3、生成通道配置交易文件
    用来生成应用通道,指定通道内的成员及访问策略
    4、生成锚节点更新配置文件
    用来配置锚节点


    至此,启动网络的前提准备条件结束。

    启动网络

    $ sudo ./byfn.sh -m up

    如果启动发生错误,则执行关闭命令后再次执行启动命令

    最后输出如下内容代表启动且测试成功

    ============== Query on peer1.org2 on channel 'mychannel' is successful ================ 
    
    ========= All GOOD, BYFN execution completed =========== 
    

    或者通过Node.js启动网络./byfn.sh -m up -l node

    first-network会生成1个orderer+4个peer+1个CLI的网络结构,整个网络包括2个org

    LOCAL_VERSION=1.1.0
    DOCKER_IMAGE_VERSION=1.1.0
    orderer.example.com is up-to-date
    peer0.org2.example.com is up-to-date
    peer1.org2.example.com is up-to-date
    peer1.org1.example.com is up-to-date
    peer0.org1.example.com is up-to-date
    Creating cli
    
     ____    _____      _      ____    _____
    / ___|  |_   _|    / \    |  _ \  |_   _|
    \___ \    | |     / _ \   | |_) |   | |
     ___) |   | |    / ___ \  |  _ <    | |
    |____/    |_|   /_/   \_\ |_| \_\   |_|
    
    Build your first network (BYFN) end-to-end test
    通道名称
    Channel name : mychannel
    Creating channel...
    TLS数据传输协议,保证在数据传输的完整性和安全性
    这个是docker容器的路径
    CORE_PEER_TLS_ROOTCERT_FILE=/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org1.example.com/peers/peer0.org1.example.com/tls/ca.crt
    密钥文件,指定路径
    CORE_PEER_TLS_KEY_FILE=/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org1.example.com/peers/peer0.org1.example.com/tls/server.key
    指定本地的mspid名称
    CORE_PEER_LOCALMSPID=Org1MSP
    fabric虚拟机:指docker
    CORE_VM_ENDPOINT=unix:///host/var/run/docker.sock
    CORE_PEER_TLS_CERT_FILE=/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org1.example.com/peers/peer0.org1.example.com/tls/server.crt
    CORE_PEER_TLS_ENABLED=true
    CORE_PEER_MSPCONFIGPATH=/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org1.example.com/users/Admin@org1.example.com/msp
    CORE_PEER_ID=cli
    CORE_LOGGING_LEVEL=INFO
    CORE_PEER_ADDRESS=peer0.org1.example.com:7051
    创建通道 -o:创建通道的必须指定order节点,完整名称:端口号
            -c:指定通道名称
            -f:指定之前生成的通道交易配置文件(已经指定好了有哪些组织)
            --tls:验证,是否使用tls协议,在数据传输过程中,保证数据的完整性
            --cafile:一旦启用了tls协议,就必须指定ca证书,docker容器中的证书文件
    + peer channel create -o orderer.example.com:7050 -c mychannel -f ./channel-artifacts/channel.tx --tls true --cafile /opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/ordererOrganizations/example.com/orderers/orderer.example.com/msp/tlscacerts/tlsca.example.com-cert.pem
    启动网络:
        1、启动docker容器
        2、进入到容器中
        3、创建应用通道(利用之前生成的通道配置文件,拷贝到docker容器中,创建通道)
        4、将对应的节点加入到应用通道中
        5、更新锚节点(在开发阶段测试阶段暂时不需要,生产环境中需要执行这个)
    创建通道成功:1,启动docker容器2、进入到容器里面创建通道
    ===================== Channel "mychannel" is created successfully =====================
    
    Having all peers join the channel...
    CORE_PEER_TLS_ROOTCERT_FILE=/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org1.example.com/peers/peer0.org1.example.com/tls/ca.crt
    CORE_PEER_TLS_KEY_FILE=/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org1.example.com/peers/peer0.org1.example.com/tls/server.key
    CORE_PEER_LOCALMSPID=Org1MSP
    CORE_VM_ENDPOINT=unix:///host/var/run/docker.sock
    CORE_PEER_TLS_CERT_FILE=/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org1.example.com/peers/peer0.org1.example.com/tls/server.crt
    CORE_PEER_TLS_ENABLED=true
    CORE_PEER_MSPCONFIGPATH=/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org1.example.com/users/Admin@org1.example.com/msp
    CORE_PEER_ID=cli
    CORE_LOGGING_LEVEL=INFO
    切换身份
    CORE_PEER_ADDRESS=peer0.org1.example.com:7051
    节点加入到通道中 -b : 指定要加入的通道  生成应用通道后产生的这个文件mychannel.block
    
    + peer channel join -b mychannel.block
    
    ===================== peer0.org1 joined on the channel "mychannel" =====================
    又指定了
    CORE_PEER_TLS_ROOTCERT_FILE=/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org1.example.com/peers/peer0.org1.example.com/tls/ca.crt
    CORE_PEER_TLS_KEY_FILE=/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org1.example.com/peers/peer0.org1.example.com/tls/server.key
    CORE_PEER_LOCALMSPID=Org1MSP
    CORE_VM_ENDPOINT=unix:///host/var/run/docker.sock
    CORE_PEER_TLS_CERT_FILE=/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org1.example.com/peers/peer0.org1.example.com/tls/server.crt
    CORE_PEER_TLS_ENABLED=true
    切换身份
    CORE_PEER_MSPCONFIGPATH=/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org1.example.com/users/Admin@org1.example.com/msp
    CORE_PEER_ID=cli
    CORE_LOGGING_LEVEL=INFO
    切换身份
    CORE_PEER_ADDRESS=peer1.org1.example.com:7051
    + peer channel join -b mychannel.block
    这次加入的是peer1节点   (就是把这个节点加入到通道中)
    ===================== peer1.org1 joined on the channel "mychannel" =====================
    
    CORE_PEER_TLS_ROOTCERT_FILE=/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org2.example.com/peers/peer0.org2.example.com/tls/ca.crt
    CORE_PEER_TLS_KEY_FILE=/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org1.example.com/peers/peer0.org1.example.com/tls/server.key
    CORE_PEER_LOCALMSPID=Org2MSP
    CORE_VM_ENDPOINT=unix:///host/var/run/docker.sock
    CORE_PEER_TLS_CERT_FILE=/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org1.example.com/peers/peer0.org1.example.com/tls/server.crt
    CORE_PEER_TLS_ENABLED=true
    切换身份
    CORE_PEER_MSPCONFIGPATH=/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org2.example.com/users/Admin@org2.example.com/msp
    CORE_PEER_ID=cli
    CORE_LOGGING_LEVEL=INFO
    切换身份
    CORE_PEER_ADDRESS=peer0.org2.example.com:7051
    + peer channel join -b mychannel.block
    org2的peer0节点加入通道
    ===================== peer0.org2 joined on the channel "mychannel" =====================
    
    CORE_PEER_TLS_ROOTCERT_FILE=/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org2.example.com/peers/peer0.org2.example.com/tls/ca.crt
    CORE_PEER_TLS_KEY_FILE=/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org1.example.com/peers/peer0.org1.example.com/tls/server.key
    CORE_PEER_LOCALMSPID=Org2MSP
    CORE_VM_ENDPOINT=unix:///host/var/run/docker.sock
    CORE_PEER_TLS_CERT_FILE=/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org1.example.com/peers/peer0.org1.example.com/tls/server.crt
    CORE_PEER_TLS_ENABLED=true
    CORE_PEER_MSPCONFIGPATH=/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org2.example.com/users/Admin@org2.example.com/msp
    CORE_PEER_ID=cli
    CORE_LOGGING_LEVEL=INFO
    切换身份
    CORE_PEER_ADDRESS=peer1.org2.example.com:7051
    + peer channel join -b mychannel.block
    
    
    ===================== peer1.org2 joined on the channel "mychannel" =====================
    更新锚节点
    Updating anchor peers for org1...
    CORE_PEER_TLS_ROOTCERT_FILE=/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org1.example.com/peers/peer0.org1.example.com/tls/ca.crt
    CORE_PEER_TLS_KEY_FILE=/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org1.example.com/peers/peer0.org1.example.com/tls/server.key
    CORE_PEER_LOCALMSPID=Org1MSP
    CORE_VM_ENDPOINT=unix:///host/var/run/docker.sock
    CORE_PEER_TLS_CERT_FILE=/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org1.example.com/peers/peer0.org1.example.com/tls/server.crt
    CORE_PEER_TLS_ENABLED=true
    CORE_PEER_MSPCONFIGPATH=/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org1.example.com/users/Admin@org1.example.com/msp
    CORE_PEER_ID=cli
    CORE_LOGGING_LEVEL=INFO
    切换身份
    CORE_PEER_ADDRESS=peer0.org1.example.com:7051
    更新锚节点
    + peer channel update -o orderer.example.com:7050 -c mychannel -f ./channel-artifacts/Org1MSPanchors.tx --tls true --cafile /opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/ordererOrganizations/example.com/orderers/orderer.example.com/msp/tlscacerts/tlsca.example.com-cert.pem
    
    ===================== Anchor peers for org "Org1MSP" on "mychannel" is updated successfully =====================
    
    Updating anchor peers for org2...
    CORE_PEER_TLS_ROOTCERT_FILE=/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org2.example.com/peers/peer0.org2.example.com/tls/ca.crt
    CORE_PEER_TLS_KEY_FILE=/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org1.example.com/peers/peer0.org1.example.com/tls/server.key
    CORE_PEER_LOCALMSPID=Org2MSP
    CORE_VM_ENDPOINT=unix:///host/var/run/docker.sock
    CORE_PEER_TLS_CERT_FILE=/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org1.example.com/peers/peer0.org1.example.com/tls/server.crt
    CORE_PEER_TLS_ENABLED=true
    CORE_PEER_MSPCONFIGPATH=/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org2.example.com/users/Admin@org2.example.com/msp
    CORE_PEER_ID=cli
    CORE_LOGGING_LEVEL=INFO
    CORE_PEER_ADDRESS=peer0.org2.example.com:7051
    更新锚节点
    + peer channel update -o orderer.example.com:7050 -c mychannel -f ./channel-artifacts/Org2MSPanchors.tx --tls true --cafile /opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/ordererOrganizations/example.com/orderers/orderer.example.com/msp/tlscacerts/tlsca.example.com-cert.pem
    
    ===================== Anchor peers for org "Org2MSP" on "mychannel" is updated successfully =====================
    
    Installing chaincode on peer0.org1...
    CORE_PEER_TLS_ROOTCERT_FILE=/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org1.example.com/peers/peer0.org1.example.com/tls/ca.crt
    CORE_PEER_TLS_KEY_FILE=/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org1.example.com/peers/peer0.org1.example.com/tls/server.key
    CORE_PEER_LOCALMSPID=Org1MSP
    CORE_VM_ENDPOINT=unix:///host/var/run/docker.sock
    CORE_PEER_TLS_CERT_FILE=/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org1.example.com/peers/peer0.org1.example.com/tls/server.crt
    CORE_PEER_TLS_ENABLED=true
    CORE_PEER_MSPCONFIGPATH=/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org1.example.com/users/Admin@org1.example.com/msp
    CORE_PEER_ID=cli
    CORE_LOGGING_LEVEL=INFO
    CORE_PEER_ADDRESS=peer0.org1.example.com:7051
    + peer chaincode install -n mycc -v 1.0 -l golang -p github.com/chaincode/chaincode_example02/go/
    
    ===================== Chaincode is installed on peer0.org1 =====================
    
    Install chaincode on peer0.org2...
    CORE_PEER_TLS_ROOTCERT_FILE=/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org2.example.com/peers/peer0.org2.example.com/tls/ca.crt
    CORE_PEER_TLS_KEY_FILE=/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org1.example.com/peers/peer0.org1.example.com/tls/server.key
    CORE_PEER_LOCALMSPID=Org2MSP
    CORE_VM_ENDPOINT=unix:///host/var/run/docker.sock
    CORE_PEER_TLS_CERT_FILE=/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org1.example.com/peers/peer0.org1.example.com/tls/server.crt
    CORE_PEER_TLS_ENABLED=true
    CORE_PEER_MSPCONFIGPATH=/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org2.example.com/users/Admin@org2.example.com/msp
    CORE_PEER_ID=cli
    CORE_LOGGING_LEVEL=INFO
    CORE_PEER_ADDRESS=peer0.org2.example.com:7051
    安装链码
    -n:指定链码名称
    -v:指定链码的当前版本
    -l:指定语言
    -P:指定要安装链码文件所在路径
    
    + peer chaincode install -n mycc -v 1.0 -l golang -p github.com/chaincode/chaincode_example02/go/
    
    
    ===================== Chaincode is installed on peer0.org2 =====================
    
    Instantiating chaincode on peer0.org2...
    CORE_PEER_TLS_ROOTCERT_FILE=/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org2.example.com/peers/peer0.org2.example.com/tls/ca.crt
    CORE_PEER_TLS_KEY_FILE=/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org1.example.com/peers/peer0.org1.example.com/tls/server.key
    CORE_PEER_LOCALMSPID=Org2MSP
    CORE_VM_ENDPOINT=unix:///host/var/run/docker.sock
    CORE_PEER_TLS_CERT_FILE=/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org1.example.com/peers/peer0.org1.example.com/tls/server.crt
    CORE_PEER_TLS_ENABLED=true
    CORE_PEER_MSPCONFIGPATH=/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org2.example.com/users/Admin@org2.example.com/msp
    CORE_PEER_ID=cli
    CORE_LOGGING_LEVEL=INFO
    CORE_PEER_ADDRESS=peer0.org2.example.com:7051
    实例化链码
        -o:指定order节点
        --tls:是否使用tls验证
        --cafile:如果使用tls验证,必须指定ca证书
        -C:指定通道名称
        -n:指定所使用的链码名称
        -l:指定语言
        -v:链码版本号
        -c:参数'{"Args":["","",""]}',初始化值
        -P:背书策略(签名),在实例化链码的时候,指定背书策略,指定由哪些节点进行签名
            'OR ('\''Org1MSP.peer'\'','\''Org2MSP.peer'\'')'
            由两个组织中的任意一个组织的所有的peer节点签名了,就算有效
            And:则是两个组织中的所有节点都签名了,才算有效
        
       目前版本: 无效的交易也会产生区块,会浪费存储空间,
       以后会改进:在链上都是合法的交易
        
    + peer chaincode instantiate -o orderer.example.com:7050 --tls true --cafile /opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/ordererOrganizations/example.com/orderers/orderer.example.com/msp/tlscacerts/tlsca.example.com-cert.pem -C mychannel -n mycc -l golang -v 1.0 -c '{"Args":["init","a","100","b","200"]}' -P 'OR  ('\''Org1MSP.peer'\'','\''Org2MSP.peer'\'')'
    
    
    ===================== Chaincode Instantiation on peer0.org2 on channel 'mychannel' is successful =====================
    
    Querying chaincode on peer0.org1...
    CORE_PEER_TLS_ROOTCERT_FILE=/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org1.example.com/peers/peer0.org1.example.com/tls/ca.crt
    CORE_PEER_TLS_KEY_FILE=/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org1.example.com/peers/peer0.org1.example.com/tls/server.key
    CORE_PEER_LOCALMSPID=Org1MSP
    CORE_VM_ENDPOINT=unix:///host/var/run/docker.sock
    CORE_PEER_TLS_CERT_FILE=/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org1.example.com/peers/peer0.org1.example.com/tls/server.crt
    CORE_PEER_TLS_ENABLED=true
    CORE_PEER_MSPCONFIGPATH=/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org1.example.com/users/Admin@org1.example.com/msp
    CORE_PEER_ID=cli
    CORE_LOGGING_LEVEL=INFO
    CORE_PEER_ADDRESS=peer0.org1.example.com:7051
    ===================== Querying on peer0.org1 on channel 'mychannel'... =====================
    Attempting to Query peer0.org1 ...3 secs
    + peer chaincode query -C mychannel -n mycc -c '{"Args":["query","a"]}'
    查询操作 -C 通道名称
            -n 链码名称
            -c 参数
    ===================== Query on peer1.org2 on channel 'mychannel' is successful =====================
    
    调用接口invoke
    
    +peer chaincode invoke -o orderer.example.com:7050 --tls true --cafile /opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/ordererOrganizations/example.com/orderers/orderer.example.com/msp/tlscacerts/tlsca.example.com-cert.pem -C mychannel -n mycc -c '{"Args":["invoke","a","b","10"]}'
    
    
    
    ========= All GOOD, BYFN execution completed ===========
     _____   _   _   ____
    | ____| | \ | | |  _ \
    |  _|   |  \| | | | | |
    | |___  | |\  | | |_| |
    |_____| |_| \_| |____/
    
    

    关闭网络

    $ sudo ./byfn.sh -m down

    关闭网络之后, 可以一步一步地探索网络设置. 将杀死容器, 删除加密文件, 并从Docker Registry中删除链码图像

    若在启动网络时遇到如下错误

    OCI runtime exec failed: exec failed: container_linux.go:348: starting container process caused "exec: \"scripts/script.sh\": stat scripts/script.sh: no such file or directory": unknown
    

    或者

    ERROR: Encountered errors while bringing up the project.
    
    ERROR !!!! Unable to start network
    

    则执行./byfn.sh down 清除网络后再启动

    down命令执行结果:

    proceeding ...
    Stopping cli ... done
    Stopping peer1.org1.example.com ... done
    Stopping peer1.org2.example.com ... done
    Stopping peer0.org1.example.com ... done
    Stopping orderer.example.com ... done
    Stopping peer0.org2.example.com ... done
    Removing cli ... done
    Removing peer1.org1.example.com ... done
    Removing peer1.org2.example.com ... done
    Removing peer0.org1.example.com ... done
    Removing orderer.example.com ... done
    Removing peer0.org2.example.com ... done
    Removing network net_byfn
    Removing volume net_peer0.org2.example.com
    Removing volume net_peer1.org2.example.com
    Removing volume net_peer1.org1.example.com
    Removing volume net_peer0.org1.example.com
    Removing volume net_orderer.example.com
    Removing network net_byfn
    WARNING: Network net_byfn not found.
    Removing volume net_peer0.org2.example.com
    WARNING: Volume net_peer0.org2.example.com not found.
    Removing volume net_peer1.org2.example.com
    WARNING: Volume net_peer1.org2.example.com not found.
    Removing volume net_peer1.org1.example.com
    WARNING: Volume net_peer1.org1.example.com not found.
    Removing volume net_peer0.org1.example.com
    WARNING: Volume net_peer0.org1.example.com not found.
    Removing volume net_orderer.example.com
    WARNING: Volume net_orderer.example.com not found.
    0793b5d3a967
    8727e212bf97
    9765aeea8b8c
    Untagged: dev-peer1.org2.example.com-mycc-1.0-26c2ef32838554aac4f7ad6f100aca865e87959c9a126e86d764c8d01f8346ab:latest
    Deleted: sha256:126a6b629cd0fcbe58bd5f028a77ada327535b1c794c1f563c85c76fbcd4229b
    Deleted: sha256:7194eff1993b6d63e6efe659287c0a52a5c32788fe3bf3380856f849cb83c4df
    Deleted: sha256:ac92354517d4dd6088860161202ac1265aed68d1b216f182c1fe25ef729a018b
    Deleted: sha256:2062550443bb2d4e36842e1f3ba7749ad779cf8d14b733a7e72a418282c7a081
    Untagged: dev-peer0.org1.example.com-mycc-1.0-384f11f484b9302df90b453200cfb25174305fce8f53f4e94d45ee3b6cab0ce9:latest
    Deleted: sha256:64cbb75f65f253e57639b78b7c6a8923b6b551102f1907eb34b1529855327a72
    Deleted: sha256:7a6a88dae6fcb8d7b457ab12ccbbd096244145b39d8138f2a5203efc43794dea
    Deleted: sha256:5ab45356179dc4346211336e235ab8ec10dfa0a0f1846de40b49dbe469f2011d
    Deleted: sha256:e450cc4004c7d26368ebcbd34827f1e994a06e477cdae548f554b22e31da3632
    Untagged: dev-peer0.org2.example.com-mycc-1.0-15b571b3ce849066b7ec74497da3b27e54e0df1345daff3951b94245ce09c42b:latest
    Deleted: sha256:2db04cb705c79cc519bebef5d156c73b7974ebca99a7155b37a2d51f1296efe7
    Deleted: sha256:f2b01326ebdef4740fa4374023dce4dde118462d2e70f11b88419f81bd5be418
    Deleted: sha256:b214e50dd599163790fe9e0a6e10b6795205da28830cc3927534dbdc5349042e
    Deleted: sha256:9b78b2626e37f3d03ff0e4894ed1440a8515f413387a4f04e33771f2fb8c183f
    
    
    
    

    测试链码:
    1.安装链码
    2.实例化链码
    3.调用链码
    3.1 query
    3.2 invoke
    put
    delete

    相关文章

      网友评论

          本文标题:005 hypeledger-fabric 启动网络(自动)

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