Hyperledger Fabric 1.0快速搭建 ---运行frist_network项目实践

在上一篇运行e2e_cli项目之后,这次运行fabric-samples中的frist_network项目测试

下一篇:Hyperledger Fabric 1.0 快速搭建 -------- 多机部署准备篇

开始

我们在$GOPATH/src/github.com/hyperledger中拉取fabric-samples项目

因为我们上一篇是基于fabricv1.0.0的,下载的镜像也都是1.0.0的,所以我们这里也要确保fabric-samples的版本不要太高

fabric是正式项目。fabric-samples是纯测试项目,这个项目是官方文档中Building Your First Network

https://hyperledger-fabric.readthedocs.io/en/latest/build_network.html官方文档

[root@localhost hyperledger]# cd $GOPATH/src/github.com/hyperledger

[root@localhost hyperledger]# git clone https://github.com/hyperledger/fabric-samples.git 
//这里我们下载的是最新的版本的项目,我们用的是1.0.2版本的,因为最低的好像就是1.0.2了 没有1.0.0

[root@localhost fabric-samples]# git tag  //查看所有版本分支

[root@localhost fabric-samples]# git checkout -b v1.0.2

[root@localhost fabric-samples]# git branch //已经切换到v1.0.2版本中了
* (detached from v1.0.2)
  release-1.2


//下载好以后

[root@localhost hyperledger]# cd fabric-samples/first-network
[root@localhost first-network]# ll
total 48
drwxr-xr-x. 2 root root    60 Sep  2 03:57 base
-rwxr-xr-x. 1 root root 14613 Sep  2 03:57 byfn.sh
drwxr-xr-x. 2 root root    22 Sep  2 05:51 channel-artifacts
-rw-r--r--. 1 root root  5013 Sep  2 03:57 configtx.yaml
-rw-r--r--. 1 root root  3858 Sep  2 03:57 crypto-config.yaml
-rw-r--r--. 1 root root  2867 Sep  2 03:57 docker-compose-cli.yaml
-rw-r--r--. 1 root root  4560 Sep  2 03:54 docker-compose-couch.yaml
-rw-r--r--. 1 root root  2724 Sep  2 03:57 docker-compose-e2e-template.yaml
-rw-r--r--. 1 root root   217 Sep  2 03:57 README.md
drwxr-xr-x. 2 root root    23 Sep  2 03:57 scripts

//这里是我们要运行的first-network项目结构
//byfn.sh就是我们要运行的脚本
[root@localhost hyperledger]# bash byfn.sh -m generate //这条命令是创建密钥文件
//他会去调用cryptogen这个工具来生成,我们将使用该cryptogen工具为各种网络实体生成加密材料(x509证书和签名密钥)。这些证书代表身份,它们允许在我们的实体进行通信和交易时进行签名/验证身份验证。



但是这个时候会遇到以下错误

[root@localhost first-network]# bash byfn.sh -m generate
Generating certs and genesis block for with channel 'mychannel' and CLI timeout of '10000'
Continue (y/n)? y
proceeding ...
which: no cryptogen in (/opt/gopath/src/github.com/hyperledger/fabric-samples/first-network/../bin:/opt/gopath/src/github.com/hyperledger/fabric-samples/first-network:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/root/bin)
cryptogen tool not found. exiting

错误显示:他找不到这个工具在opt/gopath/src/github.com/hyperledger/fabric-samples/first-network/../bin这个路径下(其实是在fbaric-samples下 他的../bin应该是往上翻了一个目录),这个bin目录在第一次下载farbic-samples时是没有的需要我们自己去找下载好以后传上去

解决办法:在我们上一篇文章中fabric项目目录下/scripts中有个bootstrap-1.0.0.sh 脚本

[root@localhost scripts]# vi bootstrap-1.0.0.sh
//用vi进到这个脚本中后会找到这么一句话, echo "下载下载平台二进制文件"
echo "===> Downloading platform binaries"
curl https://nexus.hyperledger.org/content/repositories/releases/org/hyperledger/fabric/hyperledger-fabric/${ARCH}-${VERSION}/hyperledger-fabric-${ARCH}-${VERSION}.tar.gz | tar xz
//https://nexus.hyperledger.org/content/repositories/releases/org/hyperledger/fabric/hyperledger-fabric/    这个就是我们可以在网页上找到我们所需要的对应版本的二进制文件的地址了

//你要是不想在网页中下载,可以把bootstrap-1.0.0.sh这个脚本复制到fabric-samples的根目录下运行这个脚本

//我有直接下载好的:https://download.csdn.net/download/qq_36956154/10641378 这个是v1.0.0的

//https://download.csdn.net/download/qq_36956154/10641481  这个是v1.0.2版本的

//如需其他本版通过上面的那个网页下载自己所需要的版本就可以了

我们把下载的这个bin目录上传到fabric-samples根目录下

[root@localhost fabric-samples]# cd bin/
[root@localhost bin]# ll
total 81576
-rwxr-xr-x. 1 root root 15260341 Sep  1  2017 configtxgen
-rwxr-xr-x. 1 root root 16710484 Sep  1  2017 configtxlator
-rwxr-xr-x. 1 root root  7657096 Sep  1  2017 cryptogen
-rwxr-xr-x. 1 root root      441 Sep  1  2017 get-byfn.sh
-rwxr-xr-x. 1 root root      757 Sep  1  2017 get-docker-images.sh
-rwxr-xr-x. 1 root root 20458850 Sep  1  2017 orderer
-rwxr-xr-x. 1 root root 23429725 Sep  1  2017 peer

我们要给cryptogen执行的权限,在这里我是傻瓜式的把所有的文件以及文件夹都给了执行权限,这里不给执行权限,后面会遇到一个权限不足的错误

 chmod +x configtx configtxgen configtxlator cryptogen get-byfn.sh get-docker-images.sh orderer peer 

回到frist-network下 再此执行  bash byfn.sh -m generate 这个命令来生成密钥、创世区块等

[root@localhost first-network]# bash byfn.sh -m generate
Generating certs and genesis block for with channel 'mychannel' and CLI timeout of '10000'
Continue (y/n)? y
proceeding ...
/opt/gopath/src/github.com/hyperledger/fabric-samples/bin/cryptogen

##########################################################
##### Generate certificates using cryptogen tool #########
##########################################################
org1.example.com
org2.example.com

/opt/gopath/src/github.com/hyperledger/fabric-samples/bin/configtxgen
##########################################################
#########  Generating Orderer Genesis block ##############
##########################################################
2018-09-02 05:48:02.987 EDT [common/configtx/tool] main -> INFO 001 Loading configuration
2018-09-02 05:48:03.010 EDT [common/configtx/tool] doOutputBlock -> INFO 002 Generating genesis block
2018-09-02 05:48:03.012 EDT [common/configtx/tool] doOutputBlock -> INFO 003 Writing genesis block

#################################################################
### Generating channel configuration transaction 'channel.tx' ###
#################################################################
2018-09-02 05:48:03.053 EDT [common/configtx/tool] main -> INFO 001 Loading configuration
2018-09-02 05:48:03.056 EDT [common/configtx/tool] doOutputChannelCreateTx -> INFO 002 Generating new channel configtx
2018-09-02 05:48:03.056 EDT [common/configtx/tool] doOutputChannelCreateTx -> INFO 003 Writing new channel tx

#################################################################
#######    Generating anchor peer update for Org1MSP   ##########
#################################################################
2018-09-02 05:48:03.101 EDT [common/configtx/tool] main -> INFO 001 Loading configuration
2018-09-02 05:48:03.104 EDT [common/configtx/tool] doOutputAnchorPeersUpdate -> INFO 002 Generating anchor peer update
2018-09-02 05:48:03.104 EDT [common/configtx/tool] doOutputAnchorPeersUpdate -> INFO 003 Writing anchor peer update

#################################################################
#######    Generating anchor peer update for Org2MSP   ##########
#################################################################
2018-09-02 05:48:03.152 EDT [common/configtx/tool] main -> INFO 001 Loading configuration
2018-09-02 05:48:03.155 EDT [common/configtx/tool] doOutputAnchorPeersUpdate -> INFO 002 Generating anchor peer update
2018-09-02 05:48:03.155 EDT [common/configtx/tool] doOutputAnchorPeersUpdate -> INFO 003 Writing anchor peer update

生成这些以后,运行bash byfn.sh -m up

[root@localhost first-network]# bash byfn.sh -m up
..
..
.
.
.
.
2018-09-02 09:51:00.955 UTC [msp] GetLocalMSP -> DEBU 001 Returning existing local MSP
2018-09-02 09:51:00.955 UTC [msp] GetDefaultSigningIdentity -> DEBU 002 Obtaining default signing identity
2018-09-02 09:51:00.955 UTC [chaincodeCmd] checkChaincodeCmdParams -> INFO 003 Using default escc
2018-09-02 09:51:00.955 UTC [chaincodeCmd] checkChaincodeCmdParams -> INFO 004 Using default vscc
2018-09-02 09:51:00.955 UTC [msp/identity] Sign -> DEBU 005 Sign: plaintext: 0A95070A6708031A0C0884E5AEDC0510...6D7963631A0A0A0571756572790A0161 
2018-09-02 09:51:00.955 UTC [msp/identity] Sign -> DEBU 006 Sign: digest: 7B56836702E95B52F1125C07B0B9F58A43111C366EFA1A435F07555A384860A3 
Query Result: 90
2018-09-02 09:51:10.284 UTC [main] main -> INFO 007 Exiting.....
===================== Query on PEER3 on channel 'mychannel' is successful ===================== 

========= All GOOD, BYFN execution completed =========== 


 _____   _   _   ____   
| ____| | \ | | |  _ \  
|  _|   |  \| | | | | | 
| |___  | |\  | | |_| | 
|_____| |_| \_| |____/  

这时我们会看到跟上一篇博文中一样的结束 all good  正确的启动了网络并且测试通过

bash byfn.sh -m down 关闭和清除容器以及一些文件

你可能感兴趣的:(Hyperledger,Fabric)