Skip to content
This repository has been archived by the owner on May 9, 2023. It is now read-only.

Latest commit

 

History

History
148 lines (110 loc) · 5.57 KB

File metadata and controls

148 lines (110 loc) · 5.57 KB

构建fabric的网络环境

方式一:自动化脚本实现

使用byfn.sh的自动化脚本构建一个简易的hyperledger fabric网路环境并引导启动

方式二:手动实现

构建第一个hyperledger fabric网络

cd first-network

可以使用 ./byfn.sh --help查看相对应的可用命令

img

  1. 生成证书和密钥

    所有的命令都在fabric-network的子目录first-network中,如果你选择从其他位置运行命令,那么可能提供的一些脚本将无法找到对应的二进制文件

    ./byfn.sh -m generate
    

    root@ubuntu:/hyerledgerFabric/fabric-samples/first-network# ./byfn.sh -m generate
    Generating certs and genesis block for channel 'mychannel' with CLI timeout of '10' seconds and CLI delay of '3' seconds
    Continue? [Y/n] y
    proceeding ...
    /hyerledgerFabric/fabric-samples/first-network/../bin/cryptogen
    
    ##########################################################
    ##### Generate certificates using cryptogen tool #########
    ##########################################################
    + cryptogen generate --config=./crypto-config.yaml
    org1.example.com
    org2.example.com
    + res=0
    + set +x
    
    /hyerledgerFabric/fabric-samples/first-network/../bin/configtxgen
    ##########################################################
    #########  Generating Orderer Genesis block ##############
    ##########################################################
    + configtxgen -profile TwoOrgsOrdererGenesis -outputBlock ./channel-artifacts/genesis.block
    2022-05-07 19:32:30.543 PDT 0001 FATA [common.tools.configtxgen] main -> Missing channelID, please specify it with '-channelID'
    + res=1
    + set +x
    Failed to generate orderer genesis block...
  2. 启动网络

生成所需要的证书和密钥后,需要启动网络来确定hyper ledger fabric网络是否能正常工作,使用byfn.sh脚本

./byfn.sh -m up

记录,这里出现了报错manifest for hyperledger/fabric-peer:latest not found: manifest unknown: manifest unknown

解决:1、进入https://hub.docker.com/r/hyperledger/fabric-orderer,查看Tags

找到最新版本,这里是1.4

2、运行 docker pull hyperledger/fabric-orderer:1.4

等待拉取完成

3、运行 docker tag hyperledger/fabric-orderer:1.4 hyperledger/fabric-orderer:latest

更改fabric-orderer:1.4 名称为 fabric-orderer:latest

4、重新运行./network.sh up,问题解决。

如果fabric-peer、fabric-tools也报同样错误,就重复以上步骤

2.0版本的测试网络fabric-sample

启动测试网络

test-network您可以在存储库的目录中找到启动网络的脚本fabric-samples。使用以下命令导航到测试网络目录:

cd fabric-samples/test-network

在此目录中,您可以找到一个带注释的脚本 ,network.sh它使用本地计算机上的 Docker 映像建立了一个 Fabric 网络。您可以运行 以打印脚本帮助文本:./network.sh -h

root@ubuntu:/hyerledgerFabric/fabric-samples/test-network# ./network.sh -h
Using docker and docker-compose
Usage: 
  network.sh <Mode> [Flags]
    Modes:
      up - Bring up Fabric orderer and peer nodes. No channel is created
      up createChannel - Bring up fabric network with one channel
      createChannel - Create and join a channel after the network is created
      deployCC - Deploy a chaincode to a channel (defaults to asset-transfer-basic)
      down - Bring down the network

    Flags:
    Used with network.sh up, network.sh createChannel:
    -ca <use CAs> -  Use Certificate Authorities to generate network crypto material
    -c <channel name> - Name of channel to create (defaults to "mychannel")
    -s <dbtype> - Peer state database to deploy: goleveldb (default) or couchdb
    -r <max retry> - CLI times out after certain number of attempts (defaults to 5)
    -d <delay> - CLI delays for a certain number of seconds (defaults to 3)
    -verbose - Verbose mode

    Used with network.sh deployCC
    -c <channel name> - Name of channel to deploy chaincode to
    -ccn <name> - Chaincode name.
    -ccl <language> - Programming language of the chaincode to deploy: go, java, javascript, typescript
    -ccv <version>  - Chaincode version. 1.0 (default), v2, version3.x, etc
    -ccs <sequence>  - Chaincode definition sequence. Must be an integer, 1 (default), 2, 3, etc
    -ccp <path>  - File path to the chaincode.
    -ccep <policy>  - (Optional) Chaincode endorsement policy using signature policy syntax. The default policy requires an endorsement from Org1 and Org2
    -cccg <collection-config>  - (Optional) File path to private data collections configuration file
    -cci <fcn name>  - (Optional) Name of chaincode initialization function. When a function is provided, the execution of init will be requested and the function will be invoked.

    -h - Print this message

 Possible Mode and flag combinations
   up -ca -r -d -s -verbose
   up createChannel -ca -c -r -d -s -verbose
   createChannel -c -r -d -verbose
   deployCC -ccn -ccl -ccv -ccs -ccp -cci -r -d -verbose

 Examples:
   network.sh up createChannel -ca -c mychannel -s couchdb
   network.sh createChannel -c channelName
   network.sh deployCC -ccn basic -ccp ../asset-transfer-basic/chaincode-javascript/ -ccl javascript
   network.sh deployCC -ccn mychaincode -ccp ./user/mychaincode -ccv 1 -ccl javascript