参考链接:https://hyperledger-fabric.readthedocs.io/en/release-1.4/build_network.html
在上一篇文章通过 ./byfn.sh up
脚本自动执行了first-network,这里博主将参考byfn.sh
脚本里的内容手动部署first-network,这也有助于我们更好地理解Fabric网络的部署流程。
该实例中包括一个命令行客户端,一个orderer排序节点,两个组织(Org1和Org2),其中每个组织包含两个peer节点。
准备工作
进入first-samples
目录,若之前运行过first-network,将网络关闭
cd $GOPATH/src/github.com/hyperledger/fabric/scripts/fabric-samples/first-network
./byfn.sh down
检查bin
目录内是否存在所需的工具:
ls ../bin
若出现如下结果,则无问题:
configtxgen cryptogen fabric-ca-client idemixgen peer
configtxlator discover get-docker-images.sh orderer
生成MSP证书
使用cryptogen
工具,根据crypto-config.yaml
配置文件生成证书:
../bin/cryptogen generate --config=./crypto-config.yaml
执行成功后会出现如下的结果
org1.example.com
org2.example.com
同时当前目录中会生成crypto-config
文件夹,文件夹中包括ordererOrganizations
和peerOrganizations
两个文件夹,其中包含了排序服务组织机构的证书和Peer节点的证书。
生成排序服务创世区块
export FABRIC_CFG_PATH=$PWD
../bin/configtxgen -profile TwoOrgsOrdererGenesis -channelID byfn-sys-channel -outputBlock ./channel-artifacts/genesis.block
命令执行结果:
2019-04-18 20:04:37.630 CST [common.tools.configtxgen] main -> INFO 001 Loading configuration
2019-04-18 20:04:37.658 CST [common.tools.configtxgen.localconfig] completeInitialization -> INFO 002 orderer type: solo
2019-04-18 20:04:37.658 CST [common.tools.configtxgen.localconfig] Load -> INFO 003 Loaded configuration: /home/dwm/go/src/github.com/hyperledger/fabric/scripts/fabric-samples/first-network/configtx.yaml
2019-04-18 20:04:37.683 CST [common.tools.configtxgen.localconfig] completeInitialization -> INFO 004 orderer type: solo
2019-04-18 20:04:37.683 CST [common.tools.configtxgen.localconfig] LoadTopLevel -> INFO 005 Loaded configuration: /home/dwm/go/src/github.com/hyperledger/fabric/scripts/fabric-samples/first-network/configtx.yaml
2019-04-18 20:04:37.685 CST [common.tools.configtxgen] doOutputBlock -> INFO 006 Generating genesis block
2019-04-18 20:04:37.685 CST [common.tools.configtxgen] doOutputBlock -> INFO 007 Writing genesis block
成功后将会在当前目录中生成channel-artifacts
文件夹,并在该文件夹中生成排序服务创世区块genesis.block
。
创建通道配置交易
export CHANNEL_NAME=mychannel
../bin/configtxgen -profile TwoOrgsChannel -outputCreateChannelTx ./channel-artifacts/channel.tx -channelID $CHANNEL_NAME
命令执行结果:
2019-04-18 20:05:07.770 CST [common.tools.configtxgen] main -> INFO 001 Loading configuration
2019-04-18 20:05:07.793 CST [common.tools.configtxgen.localconfig] Load -> INFO 002 Loaded configuration: /home/dwm/go/src/github.com/hyperledger/fabric/scripts/fabric-samples/first-network/configtx.yaml
2019-04-18 20:05:07.822 CST [common.tools.configtxgen.localconfig] completeIni