hyperledger-fabric1.4


在利用脚本建立第一个网络之前,需要先下载fabric-sample。如果安装环境是时候使用bootstrap.sh默认安装,则fabric-sample是已经下载的了。否则进入目录 /opt/opt/gopath/src/github.com/hyperledger/ 下克隆fabric-sample项目。以下教程默认已经安装fabric-sample


1. 进入first-network目录
1
2
cd /opt/opt/gopath/src/github.com/hyperledger/fabric-sample/first-network
ls

可以看到目录下存在名为byfn.sh的脚本文件,下面将利用该脚本文件启动fabric网络

1
2
3
4
5
[root@localhost first-network]# ls
base ccp-template.yaml connection-org1.yaml connection-org3.yaml docker-compose-couch-org3.yaml docker-compose-kafka.yaml README.md
byfn.sh channel-artifacts connection-org2.json crypto-config.yaml docker-compose-couch.yaml docker-compose-org3.yaml scripts
ccp-generate.sh configtx.yaml connection-org2.yaml docker-compose-ca.yaml docker-compose-e2e-template.yaml eyfn.sh
ccp-template.json connection-org1.json connection-org3.json docker-compose-cli.yaml docker-compose-etcdraft2.yaml org3-artifacts
2. 创建实体证书和配置交易
1
./byfn.sh generate

执行结果如下:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
[root@localhost 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 ...
/opt/gopath/src/github.com/hyperledger/fabric/release/linux-amd64/bin/cryptogen

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

Generate CCP files for Org1 and Org2
/opt/gopath/src/github.com/hyperledger/fabric/release/linux-amd64/bin/configtxgen
##########################################################
######### Generating Orderer Genesis block ##############
##########################################################
CONSENSUS_TYPE=solo
+ '[' solo == solo ']'
+ configtxgen -profile TwoOrgsOrdererGenesis -channelID byfn-sys-channel -outputBlock ./channel-artifacts/genesis.block
2019-10-19 11:01:15.267 CST [common.tools.configtxgen] main -> INFO 001 Loading configuration
2019-10-19 11:01:15.324 CST [common.tools.configtxgen.localconfig] completeInitialization -> INFO 002 orderer type: solo
2019-10-19 11:01:15.324 CST [common.tools.configtxgen.localconfig] Load -> INFO 003 Loaded configuration: /opt/gopath/src/github.com/hyperledger/fabric-samples/first-network/configtx.yaml
2019-10-19 11:01:15.376 CST [common.tools.configtxgen.localconfig] completeInitialization -> INFO 004 orderer type: solo
2019-10-19 11:01:15.376 CST [common.tools.configtxgen.localconfig] LoadTopLevel -> INFO 005 Loaded configuration: /opt/gopath/src/github.com/hyperledger/fabric-samples/first-network/configtx.yaml
2019-10-19 11:01:15.378 CST [common.tools.configtxgen] doOutputBlock -> INFO 006 Generating genesis block
2019-10-19 11:01:15.378 CST [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-10-19 11:01:15.401 CST [common.tools.configtxgen] main -> INFO 001 Loading configuration
2019-10-19 11:01:15.454 CST [common.tools.configtxgen.localconfig] Load -> INFO 002 Loaded configuration: /opt/gopath/src/github.com/hyperledger/fabric-samples/first-network/configtx.yaml
2019-10-19 11:01:15.507 CST [common.tools.configtxgen.localconfig] completeInitialization -> INFO 003 orderer type: solo
2019-10-19 11:01:15.507 CST [common.tools.configtxgen.localconfig] LoadTopLevel -> INFO 004 Loaded configuration: /opt/gopath/src/github.com/hyperledger/fabric-samples/first-network/configtx.yaml
2019-10-19 11:01:15.507 CST [common.tools.configtxgen] doOutputChannelCreateTx -> INFO 005 Generating new channel configtx
2019-10-19 11:01:15.509 CST [common.tools.configtxgen] doOutputChannelCreateTx -> INFO 006 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-10-19 11:01:15.554 CST [common.tools.configtxgen] main -> INFO 001 Loading configuration
2019-10-19 11:01:15.606 CST [common.tools.configtxgen.localconfig] Load -> INFO 002 Loaded configuration: /opt/gopath/src/github.com/hyperledger/fabric-samples/first-network/configtx.yaml
2019-10-19 11:01:15.658 CST [common.tools.configtxgen.localconfig] completeInitialization -> INFO 003 orderer type: solo
2019-10-19 11:01:15.658 CST [common.tools.configtxgen.localconfig] LoadTopLevel -> INFO 004 Loaded configuration: /opt/gopath/src/github.com/hyperledger/fabric-samples/first-network/configtx.yaml
2019-10-19 11:01:15.658 CST [common.tools.configtxgen] doOutputAnchorPeersUpdate -> INFO 005 Generating anchor peer update
2019-10-19 11:01:15.658 CST [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-10-19 11:01:15.678 CST [common.tools.configtxgen] main -> INFO 001 Loading configuration
2019-10-19 11:01:15.731 CST [common.tools.configtxgen.localconfig] Load -> INFO 002 Loaded configuration: /opt/gopath/src/github.com/hyperledger/fabric-samples/first-network/configtx.yaml
2019-10-19 11:01:15.783 CST [common.tools.configtxgen.localconfig] completeInitialization -> INFO 003 orderer type: solo
2019-10-19 11:01:15.783 CST [common.tools.configtxgen.localconfig] LoadTopLevel -> INFO 004 Loaded configuration: /opt/gopath/src/github.com/hyperledger/fabric-samples/first-network/configtx.yaml
2019-10-19 11:01:15.783 CST [common.tools.configtxgen] doOutputAnchorPeersUpdate -> INFO 005 Generating anchor peer update
2019-10-19 11:01:15.783 CST [common.tools.configtxgen] doOutputAnchorPeersUpdate -> INFO 006 Writing anchor peer update
+ res=0
+ set +x

该步骤执行以下命令

  1. 为网络实体生成证书和密钥
  2. 生成启动排序服务的创世区块
  3. 生成配置通道所需要的配置交易集合
3. 启动网络
1
./byfn.sh up

该命令默认编译并启动golang链码镜像如果使用node.js或者java链码,可以使用以下命令:

1
2
./byfn.sh -l node //node.js链码启动命令
./byfn.sh -l java //java链码启动命令

执行结果:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
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 ... done
Creating orderer.example.com ... done
Creating peer1.org2.example.com ... done
Creating peer1.org1.example.com ... done
Creating peer0.org1.example.com ... done
Creating cli ... done
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
7bccf9fbbdfc hyperledger/fabric-tools:latest "/bin/bash" 1 second ago Up Less than a second cli
5965f6980409 hyperledger/fabric-peer:latest "peer node start" 3 seconds ago Up Less than a second 0.0.0.0:7051->7051/tcp peer0.org1.example.com
c0b4948a2120 hyperledger/fabric-peer:latest "peer node start" 3 seconds ago Up Less than a second 0.0.0.0:8051->8051/tcp peer1.org1.example.com
36d1b4ee086a hyperledger/fabric-peer:latest "peer node start" 3 seconds ago Up Less than a second 0.0.0.0:10051->10051/tcp peer1.org2.example.com
990eb2e086df hyperledger/fabric-orderer:latest "orderer" 3 seconds ago Up Less than a second 0.0.0.0:7050->7050/tcp orderer.example.com
13dbf13c7a50 hyperledger/fabric-peer:latest "peer node start" 3 seconds ago Up 1 second 0.0.0.0:9051->9051/tcp peer0.org2.example.com

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

Build your first network (BYFN) end-to-end test

Channel name : mychannel
Creating channel...
1
2
3
4
5
6
7
8
========= All GOOD, BYFN execution completed =========== 


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

至此,我们的第一个fabric网络启动成功,查看正在运行的docker容器如下:

1
2
3
4
5
6
7
8
9
10
11
[root@localhost first-network]# docker ps -a
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
6fcfd0974e3b dev-peer1.org2.example.com-mycc-1.0-26c2ef32838554aac4f7ad6f100aca865e87959c9a126e86d764c8d01f8346ab "chaincode -peer.add…" 4 minutes ago Up 4 minutes dev-peer1.org2.example.com-mycc-1.0
0f84dd3b767d dev-peer0.org1.example.com-mycc-1.0-384f11f484b9302df90b453200cfb25174305fce8f53f4e94d45ee3b6cab0ce9 "chaincode -peer.add…" 4 minutes ago Up 4 minutes dev-peer0.org1.example.com-mycc-1.0
d93f067ed43d dev-peer0.org2.example.com-mycc-1.0-15b571b3ce849066b7ec74497da3b27e54e0df1345daff3951b94245ce09c42b "chaincode -peer.add…" 4 minutes ago Up 4 minutes dev-peer0.org2.example.com-mycc-1.0
7bccf9fbbdfc hyperledger/fabric-tools:latest "/bin/bash" 5 minutes ago Up 5 minutes cli
5965f6980409 hyperledger/fabric-peer:latest "peer node start" 5 minutes ago Up 5 minutes 0.0.0.0:7051->7051/tcp peer0.org1.example.com
c0b4948a2120 hyperledger/fabric-peer:latest "peer node start" 5 minutes ago Up 5 minutes 0.0.0.0:8051->8051/tcp peer1.org1.example.com
36d1b4ee086a hyperledger/fabric-peer:latest "peer node start" 5 minutes ago Up 5 minutes 0.0.0.0:10051->10051/tcp peer1.org2.example.com
990eb2e086df hyperledger/fabric-orderer:latest "orderer" 5 minutes ago Up 5 minutes 0.0.0.0:7050->7050/tcp orderer.example.com
13dbf13c7a50 hyperledger/fabric-peer:latest "peer node start" 5 minutes ago Up 5 minutes 0.0.0.0:9051->9051/tcp peer0.org2.example.com

可以看到已经启动4个peer节点和一个orderer排序节点。同时在三个peer节点上实例化了mycc链码。

4. 关闭网络
1
./byfn.sh down

该命令会停止上述已经运行的容器同时删除上述步骤所生成的所有材料,包括证书,密钥和配置交易。同时将生成的链码镜像同时删除。

最后更新: 2019年10月21日 18:58

原始链接: https://silence-linhl.github.io/blog/2019/10/22/byfn1/

× 请我吃糖~
打赏二维码