《Hyperledger Fabric菜鸟进阶攻略》 —1.4.2 构建你的第一个Hyperledger Fabric网络
1.4.2 构建你的第一个Hyperledger Fabric网络
1.生成证书和密钥
byfn.sh自动化脚本文件为各种Hyperledger Fabric网络实体生成所有证书和密钥,并且可以实现引导服务启动及配置通道所需的一系列配置文件:
$ sudo ./byfn.sh -m generate
命令成功执行后会生成1个Orderer + 4个Peer + 1个CLI的网络结构,4个Peer包含在2个Org中。
根据提示输入y,之后终端输出类似如下的日志内容:
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 ...
/home/kevin/hyfa/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
/home/kevin/hyfa/fabric-samples/first-network/../bin/configtxgen
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
# # # # # # # # # Generating Orderer Genesis block # # # # # # # # # # # # # #
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
+ configtxgen -profile TwoOrgsOrdererGenesis -outputBlock ./channel-artifacts/
genesis.block
……
doOutputAnchorPeersUpdate -> INFO 003 Writing anchor peer update
+ res=0
+ set +x
2.启动网络
生成所需要的证书及密钥之后,需要启动网络来确认Hyperledger Fabric网络环境是否能够正常工作,使用byfn.sh脚本来实现网络的启动,命令如下:
$ sudo ./byfn.sh -m up
命令执行后,终端会输出一个提示信息,根据提示输入y,如果输出如下类似内容,则代表网络启动且测试成功:
Starting for channel 'mychannel' with CLI timeout of '10' seconds and CLI
delay of '3' seconds
Continue [Y/n] y
proceeding ...
LOCAL_VERSION=1.2.0
DOCKER_IMAGE_VERSION=1.2.0
Creating network "net_byfn" with the default driver
Creating volume "net_peer0.org2.example.com" with default driver
Creating volume "net_peer1.org2.example.com" with default driver
Creating volume "net_peer1.org1.example.com" with default driver
Creating volume "net_peer0.org1.example.com" with default driver
Creating volume "net_orderer.example.com" with default driver
Creating peer0.org2.example.com
Creating peer0.org1.example.com
Creating peer1.org2.example.com
Creating orderer.example.com
Creating peer1.org1.example.com
Creating cli
____ _____ _ ____ _____
/ ___| |_ _| / \ | _ \ |_ _|
\___ \ | | / _ \ | |_) | | |
___) | | | / ___ \ | _ < | |
|____/ |_| /_/ \_\ |_| \_\ |_|
Build your first network (BYFN) end-to-end test
……
========Query successful on peer1.org2 on channel 'mychannel'==========
========= All GOOD, BYFN execution completed ===========
_____ _ _ ____
| ____| | \ | | | _ \
| _| | \| | | | | |
| |___ | |\ | | |_| |
|_____| |_| \_| |____/
3.关闭网络
网络测试成功后,为了方便后期的操作,最好将其关闭,以防止后期启动网络时造成的冲突错误,关闭网络可执行如下命令:
$ sudo ./byfn.sh -m down
根据提示输入y,命令执行后终端输出类似如下的日志内容:
Stopping for channel 'mychannel' with CLI timeout of '10' seconds and CLI
delay of '3' seconds
Continue [Y/n] y
proceeding ...
Stopping cli ... done
Stopping peer1.org1.example.com ... done
……
Removing cli ... done
Removing peer1.org1.example.com ... done
……
7fb4e7907b3c
708576aff44f
0a8805ff393d
Untagged: dev-peer1.org2.example.com-mycc-1.0-26c2ef32838554aac4f7ad6f100aca86
5e87959c9a126e86d764c8d01f8346ab:latest
Deleted: sha256:687d517a67c1b236724deb84c50e310fb87f39341de5c66857e3049222a99504
Deleted: sha256:be2477e444d06842e81fb691e4e94f7ed4a547aeb8ba4a963660356a915b61c7
……
使用byfn.sh脚本关闭网络之后,将关闭容器,且删除加密文件,并从Docker Registry中删除链码图像。
在网络不再使用时,请务必关闭网络,以防止后期启动网络时引起冲突的错误。
FAQ
如果启动网络失败怎么办?
如果启动网络时发生错误,则执行关闭命令后重新生成组织结构及证书,然后再次执行启动网络的命令。
- 点赞
- 收藏
- 关注作者
评论(0)