【猫翻】 建立你的第一个hyperledger网络(上)

in #cn7 years ago (edited)

hyperledger介绍

超级账本(hyperledger)是Linux基金会于2015年发起的推进区块链数字技术和交易验证的开源项目,加入成员包括:荷兰银行(ABN AMRO)、埃森哲(Accenture)等十几个不同利益体,目标是让成员共同合作,共建开放平台,满足来自多个不同行业各种用户案例,并简化业务流程。由于点对点网络的特性,分布式账本技术是完全共享、透明和去中心化的,故非常适合于在金融行业的应用,以及其他的例如制造、银行、保险、物联网等无数个其他行业。通过创建分布式账本的公开标准,实现虚拟和数字形式的价值交换,例如资产合约、能源交易、结婚证书、能够安全和高效低成本的进行追踪和交易。

建立你的第一个网络

These instructions have been verified to work against thelatest stable Docker images and the pre-compiledsetup utilities within the supplied tar file. If you runthese commands with images or tools from the current masterbranch, it is possible that you will see configuration and panic errors.

这些指令已经过验证,可以在所提供的tar文件中针对最新的稳定Docker镜像和预编译的安装实用程序工作。如果使用当前主分支中的图像或工具运行这些命令,则可能会看到配置和警告错误。

The build your first network (BYFN) scenario provisions a sample HyperledgerFabric network consisting of two organizations, each maintaining two peernodes, and a “solo” ordering service.

构建您的第一个网络(BYFN)方案提供了一个示例Hyperledger Fabric网络,由两个组织组成,每个组织都维护两个节点,并提供solo(单节点共识)服务。

安装前提

Before we begin, if you haven’t already done so, you may wish to check thatyou have all the Prerequisites installed on the platform(s)on which you’ll be developing blockchain applications and/or operating Hyperledger Fabric.

在您开始这一切之前,您应该检查是否已经安装了开发区块链应用程序和操作Hyperledger Fabric的平台上所需要的前提。

You will also need to download and install the Hyperledger Fabric Samples. You will noticethat there are a number of samples included in the fabric-samplesrepository. We will be using the first-network sample. Let’s open thatsub-directory now.

您还需要下载并安装Hyperledger Fabric Samples。您会注意到fabric-samples 存储库中包含了大量示例。我们将使用该first-network做示范。现在打开那个子目录。

    cd fabric-samples/first-network

The supplied commands in this documentationMUST be run from your first-network sub-directoryof the fabric-samples repository clone. If you elect to run thecommands from a different location, the various provided scriptswill be unable to find the binaries.

本文档中提供的命令必须从first-network子目录运行fabric-samples。如果您选择从其他位置运行命令,则提供的各种脚本将无法找到对应的二进制文件。

想现在运行它?

We provide a fully annotated script - byfn.sh - that leverages these Dockerimages to quickly bootstrap a Hyperledger Fabric network comprised of 4 peersrepresenting two different organizations, and an orderer node. It will alsolaunch a container to run a scripted execution that will join peers to achannel, deploy and instantiate chaincode and drive execution of transactionsagainst the deployed chaincode.

我们提供了一个全注释的脚本文件 - byfn.sh。利用这些Docker镜像快速引导由代表两个不同组织的4个节点和一个共识节点成的Hyperledger Fabric网络。它还将启动一个容器来运行一个脚本,该脚本将把节点加入到一个通道中,部署和实例化chaincode,并执行chaincode的transactions against。

Here’s the help text for the byfn.sh script:

这里是byfn.sh脚本的帮助说明

./byfn.sh --help
  Usage:
  byfn.sh -m up|down|restart|generate [-c <channel name>] [-t <timeout>] [-d <delay>] [-f <docker-compose-file>] [-s <dbtype>]
  byfn.sh -h|--help (print this message)
  -m <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
  -c <channel name> - channel name to use (defaults to "mychannel")
  -t <timeout> - CLI timeout duration in seconds (defaults to 10000)
  -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

  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

If you choose not to supply a channel name, then thescript will use a default name of mychannel. The CLI timeout parameter(specified with the -t flag) is an optional value; if you choose not to setit, then your CLI container will exit after the default setting of 10000 seconds.

如果您选择不写频道名称,则脚本将使用默认名称mychannel。CLI超时参数(使用-t指定)是一个可选值; 如果您选择不设置它,那么您的CLI容器将在默认设置10000秒后退出。

生成网络配置项

Ready to give it a go? Okay then! Execute the following command:

准备好了吗?好吧!执行以下命令:

./byfn.sh -m generate

You will see a brief description as to what will occur, along with a yes/no command lineprompt. Respond with a y to execute the described action.

您会看到一个简要说明,以及一个 yes/no 命令行提示。回应一个y继续执行。

Generating certs and genesis block for with channel 'mychannel' and CLI timeout of '10000'

Continue (y/n)?y
proceeding ...
/Users/xxx/dev/fabric-samples/bin/cryptogen

##########################################################
##### Generate certificates using cryptogen tool #########
##########################################################
org1.example.com
2017-06-12 21:01:37.334 EDT [bccsp] GetDefault -> WARN 001 Before using BCCSP, please call InitFactories(). Falling back to bootBCCSP.
...

/Users/xxx/dev/fabric-samples/bin/configtxgen
##########################################################
######### Generating Orderer Genesis block ##############
##########################################################
2017-06-12 21:01:37.558 EDT [common/configtx/tool] main -> INFO 001 Loading configuration
2017-06-12 21:01:37.562 EDT [msp] getMspConfig -> INFO 002 intermediate certs folder not found at [/Users/xxx/dev/byfn/crypto-config/ordererOrganizations/example.com/msp/intermediatecerts]. Skipping.: [stat /Users/xxx/dev/byfn/crypto-config/ordererOrganizations/example.com/msp/intermediatecerts: no such file or directory]
...
2017-06-12 21:01:37.588 EDT [common/configtx/tool] doOutputBlock -> INFO 00b Generating genesis block
2017-06-12 21:01:37.590 EDT [common/configtx/tool] doOutputBlock -> INFO 00c Writing genesis block

#################################################################
### Generating channel configuration transaction 'channel.tx' ###
#################################################################
2017-06-12 21:01:37.634 EDT [common/configtx/tool] main -> INFO 001 Loading configuration
2017-06-12 21:01:37.644 EDT [common/configtx/tool] doOutputChannelCreateTx -> INFO 002 Generating new channel configtx
2017-06-12 21:01:37.645 EDT [common/configtx/tool] doOutputChannelCreateTx -> INFO 003 Writing new channel tx

#################################################################
####### Generating anchor peer update for Org1MSP ##########
#################################################################
2017-06-12 21:01:37.674 EDT [common/configtx/tool] main -> INFO 001 Loading configuration
2017-06-12 21:01:37.678 EDT [common/configtx/tool] doOutputAnchorPeersUpdate -> INFO 002 Generating anchor peer update
2017-06-12 21:01:37.679 EDT [common/configtx/tool] doOutputAnchorPeersUpdate -> INFO 003 Writing anchor peer update

#################################################################
####### Generating anchor peer update for Org2MSP ##########
#################################################################
2017-06-12 21:01:37.700 EDT [common/configtx/tool] main -> INFO 001 Loading configuration
2017-06-12 21:01:37.704 EDT [common/configtx/tool] doOutputAnchorPeersUpdate -> INFO 002 Generating anchor peer update
2017-06-12 21:01:37.704 EDT [common/configtx/tool] doOutputAnchorPeersUpdate -> INFO 003 Writing anchor peer update

This first step generates all of the certificates and keys for our various network entities, the genesis block used to bootstrap the ordering service,and a collection of configuration transactions required to configure a Channel.

第一步为我们的网络实体生成所有证书和密钥,创世区块使用引导共识服务以及配置一个通道所需的一系列配置事务。

启动网络

Next, you can bring the network up with one of the following commands:

下一步,你可以启动网络通过下面的命令:

./byfn.sh -m up

The above command will compile Golang chaincode images and spin up the corresponding containers. Go is the default chaincode language, however there is also supportfor Node.js chaincode. If you’d like to run through this tutorial with node chaincode, pass the following command instead:

上面的命令将编译Golang的chaincode镜像,并启动相应的容器。Go是默认的chaincode语言,但是也支持Node.js chaincode。如果您想通过节点chaincode来学习本教程,请改为使用以下命令:

# we use the -l flag to specify the chaincode language
# forgoing the -l flag will default to Golang

./byfn.sh -m up -l node

View the Hyperledger Fabric Shim documentation for more info on the node.js chaincode shim APIs.

查看Hyperledger Fabric Shim 文档以获取关于node.js chaincode shim API的更多信息。

Once again, you will be prompted as to whether you wish to continue or abort.Respond with a y:

再一次,你会被提示是否希望继续,回应y:

Starting with channel 'mychannel' and CLI timeout of '10000'
Continue (y/n)?y
proceeding ...
Creating network "net_byfn" with the default driver
Creating peer0.org1.example.com
Creating peer1.org1.example.com
Creating peer0.org2.example.com
Creating orderer.example.com
Creating peer1.org2.example.com
Creating cli


____ _____ _ ____ _____
/ ___| |_ _| / \ | _ \ |_ _|
\___ \ | | / _ \ | |_) | | |
___) | | | / ___ \ | _ < | |
|____/ |_| /_/ \_\ |_| \_\ |_|

Channel name : mychannel
Creating channel...

You can scroll through these logs to see the various transactions. If you don’tget this result, then jump down to the Troubleshooting section and let’s seewhether we can help you discover what went wrong.

您可以滚动浏览这些日志以查看各种事务。如果你没有得到这个结果,那么跳到故障排除部分,看看我们能否帮助你发现哪里出了问题。

停止网络

Finally, let’s bring it all down so we can explore the network setup one stepat a time. The following will kill your containers, remove the crypto materialand four artifacts, and delete the chaincode images from your Docker Registry:

最后,让我们把它全部停下来,这样我们就可以逐步探索网络设置。以下将关闭您的容器,删除加密材料和四个工件,并从您的Docker中删除chaincode镜像:

./byfn.sh -m down
Once again, you will be prompted to continue, respond with a y:
Stopping with channel 'mychannel' and CLI timeout of '10000'
Continue (y/n)?y
proceeding ...
WARNING: The CHANNEL_NAME variable is not set. Defaulting to a blank string.
WARNING: The TIMEOUT variable is not set. Defaulting to a blank string.
Removing network net_byfn
468aaa6201ed
...
Untagged: dev-peer1.org2.example.com-mycc-1.0:latest
Deleted: sha256:ed3230614e64e1c83e510c0c282e982d2b06d148b1c498bbdcc429e2b2531e91
...

If you’d like to learn more about the underlying tooling and bootstrap mechanics,continue reading. In these next sections we’ll walk through the various stepsand requirements to build a fully-functional Hyperledger Fabric network.

如果您想了解更多关于底层工具和引导机制的信息,请继续阅读。在接下来的部分中,我们将介绍构建功能齐全的Hyperledger Fabric网络的各个步骤和要求。

未完待续。。。。

下面是我的公众号
image.png
感谢你的关注
@lanzhizhuxia

Coin Marketplace

STEEM 0.21
TRX 0.20
JST 0.033
BTC 91905.77
ETH 3091.66
USDT 1.00
SBD 3.09