zoukankan      html  css  js  c++  java
  • 菜鸟系列Fabric——Fabric 1.2 单机部署(2)

    Fabric 1.2单机部署

    https://hyperledger-fabric.readthedocs.io/en/release-1.2/whatis.html

    • 创建目录
    sudo mkdir -p $GOPATH/src/github.com/hyperledger/ && cd $GOPATH/src/github.com/hyperledger
    
    • 克隆代码
    git clone https://github.com/hyperledger/fabric.git
    查看分支及切换分支
    cd fabric/
    git branch -a  (此处若不是1.2 可 git checkout release-1.2)
    
    • 下载fabric-samples
    cd ..
    git clone https://github.com/hyperledger/fabric-samples.git
    git branch -a
    cd fabric-samples/
    git branch -a
    git checkout release-1.2
    
    • 下载镜像和要执行的二进制文件
    // [ ***需要FQ, 需要FQ, 需要FQ, 需要FQ, 需要FQ,*** ]
    $ curl -sSL http://bit.ly/2ysbOFE | bash -s 1.2.1 1.2.1 0.4.10
    	- http://bit.ly/2ysbOFE: 该地址必须FQ才能访问
    // ***不FQ的方式***
    $ curl -sSL https://raw.githubusercontent.com/hyperledger/fabric/master/scripts/bootstrap.sh | bash -s 1.2.1 1.2.1 0.4.10
    
    note:设置普通用户可以使用docker
    
    • 脚本执行
    ./byfn.sh generate
    ./byfn.sh up
    ./byfn.sh down
    
    • 分步执行
    1. 为组织和实体生成证书
      运行cryptogen工具,生成的证书和密钥将被保存到名为crypto-config的文件夹中
    cryptogen generate --config=./crypto-config.yaml
    
    1. 交易生成器 创世区块 通道及不同组织对应的锚节点配置文件
      configtxgen tool用于创建4个配置工作: order的genesis block, channel的channel configuration transaction, * 以及两个anchor peer transactions一个对应一个Peer组织。
      configtxgen命令允许用户创建和检查与通道配置相关的工件。生成的工件的内容由configtx.yaml的内容决定。
    export FABRIC_CFG_PATH=$PWD
    ../bin/configtxgen -profile TwoOrgsOrdererGenesis -outputBlock ./channel-artifacts/genesis.block
    export CHANNEL_NAME=mychannel
    ../bin/configtxgen -profile TwoOrgsChannel -outputCreateChannelTx ./channel-artifacts/channel.tx -channelID $CHANNEL_NAME
    ../bin/configtxgen -profile TwoOrgsChannel -outputAnchorPeersUpdate ./channel-artifacts/Org1MSPanchors.tx -channelID $CHANNEL_NAME -asOrg Org1MSP
    ../bin/configtxgen -profile TwoOrgsChannel -outputAnchorPeersUpdate ./channel-artifacts/Org2MSPanchors.tx -channelID $CHANNEL_NAME -asOrg Org2MSP
    

    3、启动网络

    CHANNEL_NAME=$CHANNEL_NAME TIMEOUT=120 docker-compose -f docker-compose-cli.yaml up -d
    

    4、创建通道

    docker exec -it cli bash
    export CHANNEL_NAME=mychannel
    peer channel create -o orderer.example.com:7050 -c $CHANNEL_NAME -f ./channel-artifacts/channel.tx --tls $CORE_PEER_TLS_ENABLED --cafile /opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/ordererOrganizations/example.com/orderers/orderer.example.com/msp/tlscacerts/tlsca.example.com-cert.pem
    

    5、加入通道

    peer channel join -b <channel-ID.block>
    需修改配置文件环境变量指向其他节点,在加入通道
    CORE_PEER_MSPCONFIGPATH=/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org2.example.com/users/Admin@org2.example.com/msp
    CORE_PEER_ADDRESS=peer1.org2.example.com:7051
    CORE_PEER_LOCALMSPID="Org2MSP"
    CORE_PEER_TLS_ROOTCERT_FILE=/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org2.example.com/peers/peer1.org2.example.com/tls/ca.crt
    
    CORE_PEER_MSPCONFIGPATH=/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org1.example.com/users/Admin@org1.example.com/msp
    CORE_PEER_ADDRESS=peer1.org1.example.com:7051
    CORE_PEER_LOCALMSPID="Org1MSP"
    CORE_PEER_TLS_ROOTCERT_FILE=/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org1.example.com/peers/peer1.org1.example.com/tls/ca.crt
    

    6、安装和实例化链码

    peer chaincode install -n mycc -v 1.0 -p github.com/chaincode/chaincode_example02/go
    
    peer chaincode instantiate -o orderer.example.com:7050 --tls $CORE_PEER_TLS_ENABLED --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 $CHANNEL_NAME -n mycc -v 1.0 -c '{"Args":["init","a", "100", "b","200"]}' -P "OR ('Org1MSP.member','Org2MSP.member')"
    

    7、查询链码

    peer chaincode query -C $CHANNEL_NAME -n mycc -c '{"Args":["query","a"]}'
    

    8、调用链码

    peer chaincode invoke -o orderer.example.com:7050  --tls $CORE_PEER_TLS_ENABLED --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 $CHANNEL_NAME -n mycc -c '{"Args":["invoke","a","b","10"]}'
    
    有兴趣的关注IT程序员客栈哦

    如果你觉得写的不错,请移步www.itkezhan.top或者关注公众号IT程序员客栈
  • 相关阅读:
    数论知识点整理
    《STL 源码剖析》 list 实现原理
    《STL 源码剖析》 vector 实现原理
    用户偏爱曲风分析(二)
    C++ 静态库 与 动态库
    用户偏爱曲风分析(一)
    C++ 编程中 的性能问题
    《C++API 设计》4.6 类设计
    《C++ API设计》 4.5 架构设计
    Boost 时间库使用 笔记
  • 原文地址:https://www.cnblogs.com/i-dandan/p/10848109.html
Copyright © 2011-2022 走看看