接下来的操作都将在hyperledge环境安装构建的虚拟机的环境下进行

参考https://hyperledgercn.github.io/hyperledgerDocs/build_network_zh/

 

1》运行实例

先下载hyperledger fabric samples示例

vagrant@ubuntu-xenial:~$ git clone https://github.com/hyperledger/fabric-samples.git
Cloning into 'fabric-samples'...
remote: Enumerating objects: 2705, done.
remote: Total 2705 (delta 0), reused 0 (delta 0), pack-reused 2705
Receiving objects: 100% (2705/2705), 923.26 KiB | 323.00 KiB/s, done.
Resolving deltas: 100% (1350/1350), done.
Checking connectivity... done.

然后进入其的first-network目录,因为下面要运行的目录都必须运行在这个目录下,否则提供的一些脚本可能无法找到对应的二进制:

vagrant@ubuntu-xenial:~$ ls
fabric-samples
vagrant@ubuntu-xenial:~$ cd fabric-samples/first-network/
vagrant@ubuntu-xenial:~/fabric-samples/first-network$ ls
base                docker-compose-cli.yaml           docker-compose-org3.yaml
byfn.sh             docker-compose-couch-org3.yaml    eyfn.sh
channel-artifacts   docker-compose-couch.yaml         org3-artifacts
configtx.yaml       docker-compose-e2e-template.yaml  README.md
crypto-config.yaml  docker-compose-kafka.yaml         scripts

在这个文档中提供一个完全注释的脚本byfn.sh,利用这些Docker镜像可以快速引导一个由4个代表2个不同组织的peer节点以及一个排序服务节点的Hyperledger fabric网络。它还将启动一个容器来运行一个将peer节点加入channel、部署实例化链码服务以及驱动已经部署的链码执行交易的脚本

首先我们能够使用命令./byfn.sh -h来查看脚本的帮助信息:

vagrant@ubuntu-xenial:~/fabric-samples/first-network$ ./byfn.sh -h
Usage: 
  byfn.sh <mode> [-c <channel name>] [-t <timeout>] [-d <delay>] [-f <docker-compose-file>] [-s <dbtype>] [-l <language>] [-o <consensus-type>] [-i <imagetag>] [-v]
    <mode> - one of 'up', 'down', 'restart', 'generate' or 'upgrade'
      - '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 version 1.3.x to 1.4.0
    -c <channel name> - channel name to use (defaults to "mychannel")
    -t <timeout> - CLI timeout duration in seconds (defaults to 10),即如果你选择不设置它,那么CLI容器将会在脚本执行完之后退出
    -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
    -o <consensus-type> - the consensus-type of the ordering service: solo (default) or kafka
    -i <imagetag> - the tag to be used to launch the network (defaults to "latest")
    -v - verbose mode
  byfn.sh -h (print this message)

一般来说,应该先生成需要的证书和创世区块,然后运行该网络,如:
(下面使用自定义的channel名,指明使用数据库couchdb,镜像标签为1.4.0,并声明使用node语言) byfn.sh generate -c mychannel byfn.sh up -c mychannel -s couchdb byfn.sh up -c mychannel -s couchdb -i 1.4.0 byfn.sh up -l node byfn.sh down -c mychannel byfn.sh upgrade -c mychannel 当然,你也可以完全使用默认的配置: byfn.sh generate byfn.sh up byfn.sh down

 

1)generate

首先我们先将需要的证书和创世区块构建好,运行的过程中出现一个问题:

vagrant@ubuntu-xenial:~/fabric-samples/first-network$ ./byfn.sh 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 ...
cryptogen tool not found. exiting

需要知道什么是cryptogen,可见:hyperledge工具-cryptogen

运行该./byfn.sh generate命令会执行三个函数:

  •   generateCerts :先生成证书
  •   replacePrivateKey :然后使用docker-compose-e2e-template.yaml文件,用上面那一步使用cryptogen工具生成的私钥文件名来替换docker-compose-e2e-template.yaml文件中的常量,即CA1_PRIVATE_KEY和CA2_PRIVATE_KEY,并输出到特定于此配置的docker-compose-e2e.yaml文件中,来构建docker-compose-e2e.yaml文件
  •   generateChannelArtifacts :生成排序服务节点使用的创世区块、创建通道使用的通道配置交易以及更新通道用的锚节点交易

hyperledge工具-configtxgen

然后现在重新运行一次该命令:

Using docker-compose-e2e-template.yaml, replace constants with private key file names generated by the cryptogen tool and output a docker-compose.yaml specific to this configuration



vagrant@ubuntu-xenial:~/fabric-samples/first-network$ ls #一开始的文档情况
base                docker-compose-cli.yaml           docker-compose-org3.yaml
byfn.sh             docker-compose-couch-org3.yaml    eyfn.sh
channel-artifacts   docker-compose-couch.yaml         org3-artifacts
configtx.yaml       docker-compose-e2e-template.yaml  README.md
crypto-config.yaml  docker-compose-kafka.yaml         scripts

vagrant@ubuntu-xenial:~/fabric-samples/first-network$ ./byfn.sh 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 ...
/hyperledger/fabric/.build/bin/cryptogen #开始生成证书

##########################################################
##### Generate certificates using cryptogen tool #########
##########################################################
+ cryptogen generate --config=./crypto-config.yaml
org1.example.com
org2.example.com
+ res=0
+ set +x

/hyperledger/fabric/.build/bin/configtxgen
##########################################################
#########  Generating Orderer Genesis block ##############
##########################################################
CONSENSUS_TYPE=solo
+ '[' solo == solo ']'
+ configtxgen -profile TwoOrgsOrdererGenesis -channelID byfn-sys-channel -outputBlock ./channel-artifacts/genesis.block
2019-03-08 09:31:11.852 UTC [common.tools.configtxgen] main -> INFO 001 Loading configuration
2019-03-08 09:31:11.980 UTC [common.tools.configtxgen.localconfig] completeInitialization -> INFO 002 orderer type: solo
2019-03-08 09:31:11.981 UTC [common.tools.configtxgen.localconfig] Load -> INFO 003 Loaded configuration: /home/vagrant/fabric-samples/first-network/configtx.yaml
2019-03-08 09:31:12.009 UTC [common.tools.configtxgen.localconfig] completeInitialization -> INFO 004 orderer type: solo
2019-03-08 09:31:12.009 UTC [common.tools.configtxgen.localconfig] LoadTopLevel -> INFO 005 Loaded configuration: /home/vagrant/fabric-samples/first-network/configtx.yaml
2019-03-08 09:31:12.034 UTC [common.tools.configtxgen] doOutputBlock -> INFO 006 Generating genesis block
2019-03-08 09:31:12.040 UTC [common.tools.configtxgen] doOutputBlock -> INFO 007 Writing genesis block
+ res=0
+ set +x

#################################################################
### Generating channel configuration transaction 'channel.tx' ###
#################################################################
+ configtxgen -profile TwoOrgsChannel -outputCreateChannelTx ./channel-artifacts/channel.tx -channelID mychannel
2019-03-08 09:31:12.181 UTC [common.tools.configtxgen] main -> INFO 001 Loading configuration
2019-03-08 09:31:12.230 UTC [common.tools.configtxgen.localconfig] Load -> INFO 002 Loaded configuration: /home/vagrant/fabric-samples/first-network/configtx.yaml
2019-03-08 09:31:12.260 UTC [common.tools.configtxgen.localconfig] completeInitialization -> INFO 003 orderer type: solo
2019-03-08 09:31:12.260 UTC [common.tools.configtxgen.localconfig] LoadTopLevel -> INFO 004 Loaded configuration: /home/vagrant/fabric-samples/first-network/configtx.yaml
2019-03-08 09:31:12.261 UTC [common.tools.configtxgen] doOutputChannelCreateTx -> INFO 005 Generating new channel configtx
2019-03-08 09:31:12.262 UTC [common.tools.configtxgen.encoder] NewChannelGroup -> WARN 006 Default policy emission is deprecated, please include policy specifications for the channel group in configtx.yaml
2019-03-08 09:31:12.274 UTC [common.tools.configtxgen.encoder] NewChannelGroup -> WARN 007 Default policy emission is deprecated, please include policy specifications for the channel group in configtx.yaml
2019-03-08 09:31:12.281 UTC [common.tools.configtxgen] doOutputChannelCreateTx -> INFO 008 Writing new channel tx
+ res=0
+ set +x

#################################################################
#######    Generating anchor peer update for Org1MSP   ##########
#################################################################
+ configtxgen -profile TwoOrgsChannel -outputAnchorPeersUpdate ./channel-artifacts/Org1MSPanchors.tx -channelID mychannel -asOrg Org1MSP
2019-03-08 09:31:12.424 UTC [common.tools.configtxgen] main -> INFO 001 Loading configuration
2019-03-08 09:31:12.472 UTC [common.tools.configtxgen.localconfig] Load -> INFO 002 Loaded configuration: /home/vagrant/fabric-samples/first-network/configtx.yaml
2019-03-08 09:31:12.498 UTC [common.tools.configtxgen.localconfig] completeInitialization -> INFO 003 orderer type: solo
2019-03-08 09:31:12.499 UTC [common.tools.configtxgen.localconfig] LoadTopLevel -> INFO 004 Loaded configuration: /home/vagrant/fabric-samples/first-network/configtx.yaml
2019-03-08 09:31:12.501 UTC [common.tools.configtxgen] doOutputAnchorPeersUpdate -> INFO 005 Generating anchor peer update
2019-03-08 09:31:12.506 UTC [common.tools.configtxgen] doOutputAnchorPeersUpdate -> INFO 006 Writing anchor peer update
+ res=0
+ set +x

#################################################################
#######    Generating anchor peer update for Org2MSP   ##########
#################################################################
+ configtxgen -profile TwoOrgsChannel -outputAnchorPeersUpdate ./channel-artifacts/Org2MSPanchors.tx -channelID mychannel -asOrg Org2MSP
2019-03-08 09:31:12.650 UTC [common.tools.configtxgen] main -> INFO 001 Loading configuration
2019-03-08 09:31:12.703 UTC [common.tools.configtxgen.localconfig] Load -> INFO 002 Loaded configuration: /home/vagrant/fabric-samples/first-network/configtx.yaml
2019-03-08 09:31:12.729 UTC [common.tools.configtxgen.localconfig] completeInitialization -> INFO 003 orderer type: solo
2019-03-08 09:31:12.729 UTC [common.tools.configtxgen.localconfig] LoadTopLevel -> INFO 004 Loaded configuration: /home/vagrant/fabric-samples/first-network/configtx.yaml
2019-03-08 09:31:12.729 UTC [common.tools.configtxgen] doOutputAnchorPeersUpdate -> INFO 005 Generating anchor peer update
2019-03-08 09:31:12.734 UTC [common.tools.configtxgen] doOutputAnchorPeersUpdate -> INFO 006 Writing anchor peer update
+ res=0
+ set +x

vagrant@ubuntu-xenial:~/fabric-samples/first-network$ ls #生成了一个新文件夹crypto-config,一个文件docker-compose-e2e.yaml,文件夹channel-artifacts中也有变动
base                docker-compose-cli.yaml           docker-compose-org3.yaml
byfn.sh             docker-compose-couch-org3.yaml    eyfn.sh
channel-artifacts   docker-compose-couch.yaml         org3-artifacts
configtx.yaml       docker-compose-e2e-template.yaml  README.md
crypto-config       docker-compose-e2e.yaml           scripts
crypto-config.yaml  docker-compose-kafka.yaml
View Code

相关文章:

  • 2021-11-30
  • 2021-06-23
  • 2021-06-07
  • 2022-12-23
  • 2021-09-03
  • 2021-04-12
  • 2021-07-16
  • 2021-07-27
猜你喜欢
  • 2021-06-24
  • 2021-12-07
  • 2021-11-06
  • 2022-12-23
  • 2021-04-26
  • 2021-09-05
  • 2021-08-31
相关资源
相似解决方案