Hyperledger Fabric v1.1.0环境搭建

限于喜欢 提交于 2020-01-14 00:42:07

一、搭建基础环境

参考:https://www.cnblogs.com/sky-cheng/p/12150822.html

二、下载Hyperledger Fabric 源代码

查看$GOPATH环境变量

[root@localhost home]# echo $GOPATH
/home/go

在/home/go下建立如下目录

[root@localhost home]# mkdir -p /home/go/src/github.com/hyperledger
[root@localhost home]# 

进入新建的目录,下载Fabric源代码

[root@localhost home]# cd /home/go/src/github.com/hyperledger/
[root@localhost hyperledger]# git clone https://github.com/hyperledger/fabric.git
正克隆到 'fabric'...
remote: Enumerating objects: 12, done.
remote: Counting objects: 100% (12/12), done.
remote: Compressing objects: 100% (11/11), done.
remote: Total 125935 (delta 2), reused 1 (delta 1), pack-reused 125923
接收对象中: 100% (125935/125935), 101.50 MiB | 124.00 KiB/s, done.
处理 delta 中: 100% (85366/85366), done.
[root@localhost hyperledger]# 

进入源代码目录,用git checkout 切换到V1.1.0分支,用git status 当前分支,用git tag查看所有分支

[root@localhost fabric]# cd fabric/
[root@localhost fabric]# git checkout v1.1.0
Note: checking out 'v1.1.0'.

You are in 'detached HEAD' state. You can look around, make experimental
changes and commit them, and you can discard any commits you make in this
state without impacting any branches by performing another checkout.

If you want to create a new branch to retain commits you create, you may
do so (now or later) by using -b with the checkout command again. Example:

  git checkout -b new_branch_name

HEAD 目前位于 523f644... [FAB-8883] Prepare for Fabric v1.1.0 release
[root@localhost fabric]# 
[root@localhost fabric]# git status
# 头指针分离于 v1.1.0
无文件要提交,干净的工作区

进入scripts目录,bootstrap.sh脚本的作用是下载一些工具文件用于辅助生成证书、秘钥、以及各种相关配置文件等,打开bootstrap.sh脚本

# current version of fabric released
export VERSION=${1:-1.0.4}

这里设置了版本号的VERSION环境变量,我们修改成1.1.0版本,保存退出

# current version of fabric released
export VERSION=${1:-1.1.0}

三、运行bootstrap.sh脚本

[root@localhost scripts]# ./bootstrap.sh 
===> Downloading platform specific fabric binaries
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
100 35.4M  100 35.4M    0     0  19040      0  0:32:30  0:32:30 --:--:-- 23981
===> Downloading platform specific fabric-ca-client binary
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
100 6109k  100 6109k    0     0  16023      0  0:06:30  0:06:30 --:--:-- 21829
===> Pulling fabric Images
==> FABRIC IMAGE: peer

x86_64-1.1.0: Pulling from hyperledger/fabric-peer
Digest: sha256:57417699ddf50c5ebd47a9a2cc74c0324fbba0281eb1104b9ddd05a67776b01f
Status: Image is up to date for hyperledger/fabric-peer:x86_64-1.1.0
docker.io/hyperledger/fabric-peer:x86_64-1.1.0
==> FABRIC IMAGE: orderer

x86_64-1.1.0: Pulling from hyperledger/fabric-orderer
Digest: sha256:0c3a3b5ecfd24b513da22bbb77da7b3f5bca9c121cc0ac5c46ba04c97c163654
Status: Image is up to date for hyperledger/fabric-orderer:x86_64-1.1.0
docker.io/hyperledger/fabric-orderer:x86_64-1.1.0
==> FABRIC IMAGE: ccenv

x86_64-1.1.0: Pulling from hyperledger/fabric-ccenv
Digest: sha256:07818367dc6d4264472d24b21819f9dc4e16e890d81ddfacee0341a22d72050b
Status: Image is up to date for hyperledger/fabric-ccenv:x86_64-1.1.0
docker.io/hyperledger/fabric-ccenv:x86_64-1.1.0
==> FABRIC IMAGE: javaenv

x86_64-1.1.0: Pulling from hyperledger/fabric-javaenv
Digest: sha256:d2588c0556b6fc79131f638b02a7a77337363e2c2f38a9c47798a6d99bd2f20e
Status: Image is up to date for hyperledger/fabric-javaenv:x86_64-1.1.0
docker.io/hyperledger/fabric-javaenv:x86_64-1.1.0
==> FABRIC IMAGE: tools

x86_64-1.1.0: Pulling from hyperledger/fabric-tools
Digest: sha256:36d7fa8e8ddcc19fed8e1c3c06bc6ae1dac18c35e8a884188d2c08df3e5a4472
Status: Image is up to date for hyperledger/fabric-tools:x86_64-1.1.0
docker.io/hyperledger/fabric-tools:x86_64-1.1.0
===> Pulling fabric ca Image
==> FABRIC CA IMAGE

x86_64-1.1.0: Pulling from hyperledger/fabric-ca
Digest: sha256:92f44d0811cddb0d335f7879f7e3b3c4b631f31740c76f3e7b85438c244b03f4
Status: Image is up to date for hyperledger/fabric-ca:x86_64-1.1.0
docker.io/hyperledger/fabric-ca:x86_64-1.1.0
===> Pulling thirdparty docker images
==> THIRDPARTY DOCKER IMAGE: couchdb

x86_64-0.4.6: Pulling from hyperledger/fabric-couchdb
Digest: sha256:4278269b115cfd0f24251b5381407be9ccdf396c1470c69e1ee2ff16917ac882
Status: Image is up to date for hyperledger/fabric-couchdb:x86_64-0.4.6
docker.io/hyperledger/fabric-couchdb:x86_64-0.4.6
==> THIRDPARTY DOCKER IMAGE: kafka

x86_64-0.4.6: Pulling from hyperledger/fabric-kafka
Digest: sha256:738bb79f02aa505a9ab0553a865122605ffba91d1b5de6eb0429f7287e83ac7c
Status: Image is up to date for hyperledger/fabric-kafka:x86_64-0.4.6
docker.io/hyperledger/fabric-kafka:x86_64-0.4.6
==> THIRDPARTY DOCKER IMAGE: zookeeper

x86_64-0.4.6: Pulling from hyperledger/fabric-zookeeper
Digest: sha256:7fda667f6c39d6cb87125c132962fc3e434a8e6b2b16ee798d6fa94f970531a2
Status: Image is up to date for hyperledger/fabric-zookeeper:x86_64-0.4.6
docker.io/hyperledger/fabric-zookeeper:x86_64-0.4.6

===> List out hyperledger docker images
hyperledger/fabric-ca          latest              72617b4fa9b4        22 months ago       299MB
hyperledger/fabric-ca          x86_64-1.1.0        72617b4fa9b4        22 months ago       299MB
hyperledger/fabric-tools       latest              b7bfddf508bc        22 months ago       1.46GB
hyperledger/fabric-tools       x86_64-1.1.0        b7bfddf508bc        22 months ago       1.46GB
hyperledger/fabric-orderer     latest              ce0c810df36a        22 months ago       180MB
hyperledger/fabric-orderer     x86_64-1.1.0        ce0c810df36a        22 months ago       180MB
hyperledger/fabric-peer        latest              b023f9be0771        22 months ago       187MB
hyperledger/fabric-peer        x86_64-1.1.0        b023f9be0771        22 months ago       187MB
hyperledger/fabric-javaenv     latest              82098abb1a17        22 months ago       1.52GB
hyperledger/fabric-javaenv     x86_64-1.1.0        82098abb1a17        22 months ago       1.52GB
hyperledger/fabric-ccenv       latest              c8b4909d8d46        22 months ago       1.39GB
hyperledger/fabric-ccenv       x86_64-1.1.0        c8b4909d8d46        22 months ago       1.39GB
hyperledger/fabric-zookeeper   latest              92cbb952b6f8        23 months ago       1.39GB
hyperledger/fabric-zookeeper   x86_64-0.4.6        92cbb952b6f8        23 months ago       1.39GB
hyperledger/fabric-kafka       latest              554c591b86a8        23 months ago       1.4GB
hyperledger/fabric-kafka       x86_64-0.4.6        554c591b86a8        23 months ago       1.4GB
hyperledger/fabric-couchdb     latest              7e73c828fc5b        23 months ago       1.56GB
hyperledger/fabric-couchdb     x86_64-0.4.6        7e73c828fc5b        23 months ago       1.56GB
[root@localhost scripts]# 

首先下载相关工具二进制文件,其次再拉取v1.1.0相关版本的镜像文件。二进制文件保存在scripts/bin 目录里,把它移动到/home/go/src/github.com/hyperledger/下,并设置好PATH变量

[root@localhost scripts]# mv bin/ /home/go/src/github.com/hyperledger/
[root@localhost bin]# echo "export PATH=$PATH:/home/go/src/github.com/hyperledger/bin">>/etc/profile
[root@localhost bin]# source /etc/profile
[root@localhost bin]# echo $PATH
/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/opt/dell/srvadmin/bin:/opt/dell/srvadmin/sbin:/home/mysql-5.7.26/bin/:/root/bin:/usr/local/go/bin:/root/bin:/home/go/src/github.com/hyperledger/bin:/home/go/src/github.com/hyperledger/bin
[root@localhost bin]# 

四、下载fabric-sample项目源代码 

[root@localhost hyperledger]# cd /home/go/src/github.com/hyperledger
[root@localhost hyperledger]# git clone https://github.com/hyperledger/fabric-samples.git
正克隆到 'fabric-samples'...
remote: Enumerating objects: 4430, done.
remote: Total 4430 (delta 0), reused 0 (delta 0), pack-reused 4430
接收对象中: 100% (4430/4430), 1.61 MiB | 8.00 KiB/s, done.
处理 delta 中: 100% (2181/2181), done.
[root@localhost hyperledger]# ll
总用量 8
drwxrwxr-x  2 mysql mysql  142 3月  16 2018 bin
drwxr-xr-x 27 root  root  4096 1月  13 17:03 fabric
drwxr-xr-x 16 root  root  4096 1月  13 22:32 fabric-samples
[root@localhost hyperledger]# 

切换到v1.1.0版本

[root@localhost hyperledger]# cd fabric-samples/
[root@localhost fabric-samples]# git checkout v1.1.0
Note: checking out 'v1.1.0'.

You are in 'detached HEAD' state. You can look around, make experimental
changes and commit them, and you can discard any commits you make in this
state without impacting any branches by performing another checkout.

If you want to create a new branch to retain commits you create, you may
do so (now or later) by using -b with the checkout command again. Example:

  git checkout -b new_branch_name

HEAD 目前位于 1252c7a... [FAB-8920] Pin fabric-samples to node.js "~1.1.0"
[root@localhost fabric-samples]# git status
# 头指针分离于 v1.1.0
无文件要提交,干净的工作区
[root@localhost fabric-samples]# 

五、启动网络

进入first-network目录

root@localhost fabric-samples]# cd first-network/
[root@localhost first-network]# ll
总用量 72
drwxr-xr-x 2 root root    60 1月  13 22:34 base
-rwxr-xr-x 1 root root 20114 1月  13 22:34 byfn.sh
drwxr-xr-x 2 root root    22 1月  13 22:32 channel-artifacts
-rw-r--r-- 1 root root  7912 1月  13 22:34 configtx.yaml
-rw-r--r-- 1 root root  3906 1月  13 22:34 crypto-config.yaml
-rw-r--r-- 1 root root  2971 1月  13 22:34 docker-compose-cli.yaml
-rw-r--r-- 1 root root  2345 1月  13 22:34 docker-compose-couch-org3.yaml
-rw-r--r-- 1 root root  4560 1月  13 22:34 docker-compose-couch.yaml
-rw-r--r-- 1 root root  2883 1月  13 22:32 docker-compose-e2e-template.yaml
-rw-r--r-- 1 root root  3493 1月  13 22:34 docker-compose-org3.yaml
-rwxr-xr-x 1 root root 10627 1月  13 22:34 eyfn.sh
drwxr-xr-x 2 root root    51 1月  13 22:34 org3-artifacts
-rw-r--r-- 1 root root   335 1月  13 22:32 README.md
drwxr-xr-x 2 root root   168 1月  13 22:34 scripts

运行byfn.sh脚本,启动网络

[root@localhost first-network]# ./byfn.sh -m up -c firstchannel
Starting with channel 'firstchannel' and CLI timeout of '10' seconds and CLI delay of '3' seconds
Continue? [Y/n] y
proceeding ...
2020-01-13 14:52:39.329 UTC [main] main -> INFO 001 Exiting.....
LOCAL_VERSION=1.1.0
DOCKER_IMAGE_VERSION=1.1.0
/home/go/src/github.com/hyperledger/bin/cryptogen

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

/home/go/src/github.com/hyperledger/bin/configtxgen
##########################################################
#########  Generating Orderer Genesis block ##############
##########################################################
+ configtxgen -profile TwoOrgsOrdererGenesis -outputBlock ./channel-artifacts/genesis.block
2020-01-13 22:52:39.977 CST [common/tools/configtxgen] main -> INFO 001 Loading configuration
2020-01-13 22:52:40.002 CST [msp] getMspConfig -> INFO 002 Loading NodeOUs
2020-01-13 22:52:40.003 CST [msp] getMspConfig -> INFO 003 Loading NodeOUs
2020-01-13 22:52:40.003 CST [common/tools/configtxgen] doOutputBlock -> INFO 004 Generating genesis block
2020-01-13 22:52:40.004 CST [common/tools/configtxgen] doOutputBlock -> INFO 005 Writing genesis block
+ res=0
+ set +x

#################################################################
### Generating channel configuration transaction 'channel.tx' ###
#################################################################
+ configtxgen -profile TwoOrgsChannel -outputCreateChannelTx ./channel-artifacts/channel.tx -channelID firstchannel
2020-01-13 22:52:40.031 CST [common/tools/configtxgen] main -> INFO 001 Loading configuration
2020-01-13 22:52:40.054 CST [common/tools/configtxgen] doOutputChannelCreateTx -> INFO 002 Generating new channel configtx
2020-01-13 22:52:40.055 CST [msp] getMspConfig -> INFO 003 Loading NodeOUs
2020-01-13 22:52:40.056 CST [msp] getMspConfig -> INFO 004 Loading NodeOUs
2020-01-13 22:52:40.143 CST [common/tools/configtxgen] doOutputChannelCreateTx -> INFO 005 Writing new channel tx
+ res=0
+ set +x

#################################################################
#######    Generating anchor peer update for Org1MSP   ##########
#################################################################
+ configtxgen -profile TwoOrgsChannel -outputAnchorPeersUpdate ./channel-artifacts/Org1MSPanchors.tx -channelID firstchannel -asOrg Org1MSP
2020-01-13 22:52:40.170 CST [common/tools/configtxgen] main -> INFO 001 Loading configuration
2020-01-13 22:52:40.193 CST [common/tools/configtxgen] doOutputAnchorPeersUpdate -> INFO 002 Generating anchor peer update
2020-01-13 22:52:40.193 CST [common/tools/configtxgen] doOutputAnchorPeersUpdate -> INFO 003 Writing anchor peer update
+ res=0
+ set +x

#################################################################
#######    Generating anchor peer update for Org2MSP   ##########
#################################################################
+ configtxgen -profile TwoOrgsChannel -outputAnchorPeersUpdate ./channel-artifacts/Org2MSPanchors.tx -channelID firstchannel -asOrg Org2MSP
2020-01-13 22:52:40.220 CST [common/tools/configtxgen] main -> INFO 001 Loading configuration
2020-01-13 22:52:40.243 CST [common/tools/configtxgen] doOutputAnchorPeersUpdate -> INFO 002 Generating anchor peer update
2020-01-13 22:52:40.244 CST [common/tools/configtxgen] doOutputAnchorPeersUpdate -> INFO 003 Writing anchor peer update
+ res=0
+ set +x

Creating network "net_byfn" with the default driver
Creating volume "net_orderer.example.com" with default driver
Creating volume "net_peer0.org1.example.com" with default driver
Creating volume "net_peer1.org1.example.com" with default driver
Creating volume "net_peer0.org2.example.com" with default driver
Creating volume "net_peer1.org2.example.com" with default driver
Creating peer1.org2.example.com ... done
Creating peer1.org1.example.com ... done
Creating orderer.example.com    ... done
Creating peer0.org1.example.com ... done
Creating peer0.org2.example.com ... done
Creating cli                    ... done

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

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

Channel name : firstchannel
Creating channel...
CORE_PEER_TLS_ROOTCERT_FILE=/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org1.example.com/peers/peer0.org1.example.com/tls/ca.crt
CORE_PEER_TLS_KEY_FILE=/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org1.example.com/peers/peer0.org1.example.com/tls/server.key
CORE_PEER_LOCALMSPID=Org1MSP
CORE_VM_ENDPOINT=unix:///host/var/run/docker.sock
CORE_PEER_TLS_CERT_FILE=/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org1.example.com/peers/peer0.org1.example.com/tls/server.crt
CORE_PEER_TLS_ENABLED=true
CORE_PEER_MSPCONFIGPATH=/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org1.example.com/users/Admin@org1.example.com/msp
CORE_PEER_ID=cli
CORE_LOGGING_LEVEL=INFO
CORE_PEER_ADDRESS=peer0.org1.example.com:7051
+ peer channel create -o orderer.example.com:7050 -c firstchannel -f ./channel-artifacts/channel.tx --tls true --cafile /opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/ordererOrganizations/example.com/orderers/orderer.example.com/msp/tlscacerts/tlsca.example.com-cert.pem
+ res=0
+ set +x
2020-01-13 14:52:47.158 UTC [channelCmd] InitCmdFactory -> INFO 001 Endorser and orderer connections initialized
2020-01-13 14:52:47.226 UTC [channelCmd] InitCmdFactory -> INFO 002 Endorser and orderer connections initialized
2020-01-13 14:52:47.432 UTC [main] main -> INFO 003 Exiting.....
===================== Channel "firstchannel" is created successfully ===================== 

Having all peers join the channel...
CORE_PEER_TLS_ROOTCERT_FILE=/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org1.example.com/peers/peer0.org1.example.com/tls/ca.crt
CORE_PEER_TLS_KEY_FILE=/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org1.example.com/peers/peer0.org1.example.com/tls/server.key
CORE_PEER_LOCALMSPID=Org1MSP
CORE_VM_ENDPOINT=unix:///host/var/run/docker.sock
CORE_PEER_TLS_CERT_FILE=/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org1.example.com/peers/peer0.org1.example.com/tls/server.crt
CORE_PEER_TLS_ENABLED=true
CORE_PEER_MSPCONFIGPATH=/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org1.example.com/users/Admin@org1.example.com/msp
CORE_PEER_ID=cli
CORE_LOGGING_LEVEL=INFO
CORE_PEER_ADDRESS=peer0.org1.example.com:7051
+ peer channel join -b firstchannel.block
+ res=0
+ set +x
2020-01-13 14:52:47.586 UTC [channelCmd] InitCmdFactory -> INFO 001 Endorser and orderer connections initialized
2020-01-13 14:52:47.747 UTC [channelCmd] executeJoin -> INFO 002 Successfully submitted proposal to join channel
2020-01-13 14:52:47.747 UTC [main] main -> INFO 003 Exiting.....
===================== peer0.org1 joined on the channel "firstchannel" ===================== 

CORE_PEER_TLS_ROOTCERT_FILE=/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org1.example.com/peers/peer0.org1.example.com/tls/ca.crt
CORE_PEER_TLS_KEY_FILE=/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org1.example.com/peers/peer0.org1.example.com/tls/server.key
CORE_PEER_LOCALMSPID=Org1MSP
CORE_VM_ENDPOINT=unix:///host/var/run/docker.sock
CORE_PEER_TLS_CERT_FILE=/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org1.example.com/peers/peer0.org1.example.com/tls/server.crt
CORE_PEER_TLS_ENABLED=true
CORE_PEER_MSPCONFIGPATH=/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org1.example.com/users/Admin@org1.example.com/msp
CORE_PEER_ID=cli
CORE_LOGGING_LEVEL=INFO
CORE_PEER_ADDRESS=peer1.org1.example.com:7051
+ peer channel join -b firstchannel.block
+ res=0
+ set +x
2020-01-13 14:52:50.900 UTC [channelCmd] InitCmdFactory -> INFO 001 Endorser and orderer connections initialized
2020-01-13 14:52:51.065 UTC [channelCmd] executeJoin -> INFO 002 Successfully submitted proposal to join channel
2020-01-13 14:52:51.065 UTC [main] main -> INFO 003 Exiting.....
===================== peer1.org1 joined on the channel "firstchannel" ===================== 

CORE_PEER_TLS_ROOTCERT_FILE=/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org2.example.com/peers/peer0.org2.example.com/tls/ca.crt
CORE_PEER_TLS_KEY_FILE=/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org1.example.com/peers/peer0.org1.example.com/tls/server.key
CORE_PEER_LOCALMSPID=Org2MSP
CORE_VM_ENDPOINT=unix:///host/var/run/docker.sock
CORE_PEER_TLS_CERT_FILE=/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org1.example.com/peers/peer0.org1.example.com/tls/server.crt
CORE_PEER_TLS_ENABLED=true
CORE_PEER_MSPCONFIGPATH=/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org2.example.com/users/Admin@org2.example.com/msp
CORE_PEER_ID=cli
CORE_LOGGING_LEVEL=INFO
CORE_PEER_ADDRESS=peer0.org2.example.com:7051
+ peer channel join -b firstchannel.block
+ res=0
+ set +x
2020-01-13 14:52:54.200 UTC [channelCmd] InitCmdFactory -> INFO 001 Endorser and orderer connections initialized
2020-01-13 14:52:54.367 UTC [channelCmd] executeJoin -> INFO 002 Successfully submitted proposal to join channel
2020-01-13 14:52:54.367 UTC [main] main -> INFO 003 Exiting.....
===================== peer0.org2 joined on the channel "firstchannel" ===================== 

CORE_PEER_TLS_ROOTCERT_FILE=/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org2.example.com/peers/peer0.org2.example.com/tls/ca.crt
CORE_PEER_TLS_KEY_FILE=/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org1.example.com/peers/peer0.org1.example.com/tls/server.key
CORE_PEER_LOCALMSPID=Org2MSP
CORE_VM_ENDPOINT=unix:///host/var/run/docker.sock
CORE_PEER_TLS_CERT_FILE=/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org1.example.com/peers/peer0.org1.example.com/tls/server.crt
CORE_PEER_TLS_ENABLED=true
CORE_PEER_MSPCONFIGPATH=/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org2.example.com/users/Admin@org2.example.com/msp
CORE_PEER_ID=cli
CORE_LOGGING_LEVEL=INFO
CORE_PEER_ADDRESS=peer1.org2.example.com:7051
+ peer channel join -b firstchannel.block
+ res=0
+ set +x
2020-01-13 14:52:57.503 UTC [channelCmd] InitCmdFactory -> INFO 001 Endorser and orderer connections initialized
2020-01-13 14:52:57.680 UTC [channelCmd] executeJoin -> INFO 002 Successfully submitted proposal to join channel
2020-01-13 14:52:57.680 UTC [main] main -> INFO 003 Exiting.....
===================== peer1.org2 joined on the channel "firstchannel" ===================== 

Updating anchor peers for org1...
CORE_PEER_TLS_ROOTCERT_FILE=/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org1.example.com/peers/peer0.org1.example.com/tls/ca.crt
CORE_PEER_TLS_KEY_FILE=/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org1.example.com/peers/peer0.org1.example.com/tls/server.key
CORE_PEER_LOCALMSPID=Org1MSP
CORE_VM_ENDPOINT=unix:///host/var/run/docker.sock
CORE_PEER_TLS_CERT_FILE=/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org1.example.com/peers/peer0.org1.example.com/tls/server.crt
CORE_PEER_TLS_ENABLED=true
CORE_PEER_MSPCONFIGPATH=/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org1.example.com/users/Admin@org1.example.com/msp
CORE_PEER_ID=cli
CORE_LOGGING_LEVEL=INFO
CORE_PEER_ADDRESS=peer0.org1.example.com:7051
+ peer channel update -o orderer.example.com:7050 -c firstchannel -f ./channel-artifacts/Org1MSPanchors.tx --tls true --cafile /opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/ordererOrganizations/example.com/orderers/orderer.example.com/msp/tlscacerts/tlsca.example.com-cert.pem
+ res=0
+ set +x
2020-01-13 14:53:00.815 UTC [channelCmd] InitCmdFactory -> INFO 001 Endorser and orderer connections initialized
2020-01-13 14:53:00.848 UTC [channelCmd] update -> INFO 002 Successfully submitted channel update
2020-01-13 14:53:00.848 UTC [main] main -> INFO 003 Exiting.....
===================== Anchor peers for org "Org1MSP" on "firstchannel" is updated successfully ===================== 

Updating anchor peers for org2...
CORE_PEER_TLS_ROOTCERT_FILE=/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org2.example.com/peers/peer0.org2.example.com/tls/ca.crt
CORE_PEER_TLS_KEY_FILE=/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org1.example.com/peers/peer0.org1.example.com/tls/server.key
CORE_PEER_LOCALMSPID=Org2MSP
CORE_VM_ENDPOINT=unix:///host/var/run/docker.sock
CORE_PEER_TLS_CERT_FILE=/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org1.example.com/peers/peer0.org1.example.com/tls/server.crt
CORE_PEER_TLS_ENABLED=true
CORE_PEER_MSPCONFIGPATH=/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org2.example.com/users/Admin@org2.example.com/msp
CORE_PEER_ID=cli
CORE_LOGGING_LEVEL=INFO
CORE_PEER_ADDRESS=peer0.org2.example.com:7051
+ peer channel update -o orderer.example.com:7050 -c firstchannel -f ./channel-artifacts/Org2MSPanchors.tx --tls true --cafile /opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/ordererOrganizations/example.com/orderers/orderer.example.com/msp/tlscacerts/tlsca.example.com-cert.pem
+ res=0
+ set +x
2020-01-13 14:53:03.986 UTC [channelCmd] InitCmdFactory -> INFO 001 Endorser and orderer connections initialized
2020-01-13 14:53:04.016 UTC [channelCmd] update -> INFO 002 Successfully submitted channel update
2020-01-13 14:53:04.016 UTC [main] main -> INFO 003 Exiting.....
===================== Anchor peers for org "Org2MSP" on "firstchannel" is updated successfully ===================== 

Installing chaincode on peer0.org1...
CORE_PEER_TLS_ROOTCERT_FILE=/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org1.example.com/peers/peer0.org1.example.com/tls/ca.crt
CORE_PEER_TLS_KEY_FILE=/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org1.example.com/peers/peer0.org1.example.com/tls/server.key
CORE_PEER_LOCALMSPID=Org1MSP
CORE_VM_ENDPOINT=unix:///host/var/run/docker.sock
CORE_PEER_TLS_CERT_FILE=/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org1.example.com/peers/peer0.org1.example.com/tls/server.crt
CORE_PEER_TLS_ENABLED=true
CORE_PEER_MSPCONFIGPATH=/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org1.example.com/users/Admin@org1.example.com/msp
CORE_PEER_ID=cli
CORE_LOGGING_LEVEL=INFO
CORE_PEER_ADDRESS=peer0.org1.example.com:7051
+ peer chaincode install -n mycc -v 1.0 -l golang -p github.com/chaincode/chaincode_example02/go/
+ res=0
+ set +x
2020-01-13 14:53:07.168 UTC [chaincodeCmd] checkChaincodeCmdParams -> INFO 001 Using default escc
2020-01-13 14:53:07.168 UTC [chaincodeCmd] checkChaincodeCmdParams -> INFO 002 Using default vscc
2020-01-13 14:53:07.508 UTC [main] main -> INFO 003 Exiting.....
===================== Chaincode is installed on peer0.org1 ===================== 

Install chaincode on peer0.org2...
CORE_PEER_TLS_ROOTCERT_FILE=/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org2.example.com/peers/peer0.org2.example.com/tls/ca.crt
CORE_PEER_TLS_KEY_FILE=/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org1.example.com/peers/peer0.org1.example.com/tls/server.key
CORE_PEER_LOCALMSPID=Org2MSP
CORE_VM_ENDPOINT=unix:///host/var/run/docker.sock
CORE_PEER_TLS_CERT_FILE=/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org1.example.com/peers/peer0.org1.example.com/tls/server.crt
CORE_PEER_TLS_ENABLED=true
CORE_PEER_MSPCONFIGPATH=/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org2.example.com/users/Admin@org2.example.com/msp
CORE_PEER_ID=cli
CORE_LOGGING_LEVEL=INFO
CORE_PEER_ADDRESS=peer0.org2.example.com:7051
+ peer chaincode install -n mycc -v 1.0 -l golang -p github.com/chaincode/chaincode_example02/go/
+ res=0
+ set +x
2020-01-13 14:53:07.645 UTC [chaincodeCmd] checkChaincodeCmdParams -> INFO 001 Using default escc
2020-01-13 14:53:07.646 UTC [chaincodeCmd] checkChaincodeCmdParams -> INFO 002 Using default vscc
2020-01-13 14:53:07.999 UTC [main] main -> INFO 003 Exiting.....
===================== Chaincode is installed on peer0.org2 ===================== 

Instantiating chaincode on peer0.org2...
CORE_PEER_TLS_ROOTCERT_FILE=/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org2.example.com/peers/peer0.org2.example.com/tls/ca.crt
CORE_PEER_TLS_KEY_FILE=/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org1.example.com/peers/peer0.org1.example.com/tls/server.key
CORE_PEER_LOCALMSPID=Org2MSP
CORE_VM_ENDPOINT=unix:///host/var/run/docker.sock
CORE_PEER_TLS_CERT_FILE=/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org1.example.com/peers/peer0.org1.example.com/tls/server.crt
CORE_PEER_TLS_ENABLED=true
CORE_PEER_MSPCONFIGPATH=/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org2.example.com/users/Admin@org2.example.com/msp
CORE_PEER_ID=cli
CORE_LOGGING_LEVEL=INFO
CORE_PEER_ADDRESS=peer0.org2.example.com:7051
+ peer chaincode instantiate -o orderer.example.com:7050 --tls true --cafile /opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/ordererOrganizations/example.com/orderers/orderer.example.com/msp/tlscacerts/tlsca.example.com-cert.pem -C firstchannel -n mycc -l golang -v 1.0 -c '{"Args":["init","a","100","b","200"]}' -P 'OR       ('\''Org1MSP.peer'\'','\''Org2MSP.peer'\'')'
+ res=0
+ set +x
2020-01-13 14:53:08.146 UTC [chaincodeCmd] checkChaincodeCmdParams -> INFO 001 Using default escc
2020-01-13 14:53:08.146 UTC [chaincodeCmd] checkChaincodeCmdParams -> INFO 002 Using default vscc
2020-01-13 14:53:28.997 UTC [main] main -> INFO 003 Exiting.....
===================== Chaincode Instantiation on peer0.org2 on channel 'firstchannel' is successful ===================== 

Querying chaincode on peer0.org1...
CORE_PEER_TLS_ROOTCERT_FILE=/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org1.example.com/peers/peer0.org1.example.com/tls/ca.crt
CORE_PEER_TLS_KEY_FILE=/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org1.example.com/peers/peer0.org1.example.com/tls/server.key
CORE_PEER_LOCALMSPID=Org1MSP
CORE_VM_ENDPOINT=unix:///host/var/run/docker.sock
CORE_PEER_TLS_CERT_FILE=/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org1.example.com/peers/peer0.org1.example.com/tls/server.crt
CORE_PEER_TLS_ENABLED=true
CORE_PEER_MSPCONFIGPATH=/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org1.example.com/users/Admin@org1.example.com/msp
CORE_PEER_ID=cli
CORE_LOGGING_LEVEL=INFO
CORE_PEER_ADDRESS=peer0.org1.example.com:7051
===================== Querying on peer0.org1 on channel 'firstchannel'... ===================== 
Attempting to Query peer0.org1 ...3 secs
+ peer chaincode query -C firstchannel -n mycc -c '{"Args":["query","a"]}'
+ res=0
+ set +x

2020-01-13 14:53:32.179 UTC [chaincodeCmd] checkChaincodeCmdParams -> INFO 001 Using default escc
2020-01-13 14:53:32.180 UTC [chaincodeCmd] checkChaincodeCmdParams -> INFO 002 Using default vscc
Query Result: 100
2020-01-13 14:53:51.935 UTC [main] main -> INFO 003 Exiting.....
===================== Query on peer0.org1 on channel 'firstchannel' is successful ===================== 
Sending invoke transaction on peer0.org1...
CORE_PEER_TLS_ROOTCERT_FILE=/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org1.example.com/peers/peer0.org1.example.com/tls/ca.crt
CORE_PEER_TLS_KEY_FILE=/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org1.example.com/peers/peer0.org1.example.com/tls/server.key
CORE_PEER_LOCALMSPID=Org1MSP
CORE_VM_ENDPOINT=unix:///host/var/run/docker.sock
CORE_PEER_TLS_CERT_FILE=/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org1.example.com/peers/peer0.org1.example.com/tls/server.crt
CORE_PEER_TLS_ENABLED=true
CORE_PEER_MSPCONFIGPATH=/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org1.example.com/users/Admin@org1.example.com/msp
CORE_PEER_ID=cli
CORE_LOGGING_LEVEL=INFO
CORE_PEER_ADDRESS=peer0.org1.example.com:7051
+ peer chaincode invoke -o orderer.example.com:7050 --tls true --cafile /opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/ordererOrganizations/example.com/orderers/orderer.example.com/msp/tlscacerts/tlsca.example.com-cert.pem -C firstchannel -n mycc -c '{"Args":["invoke","a","b","10"]}'
+ res=0
+ set +x
2020-01-13 14:53:52.132 UTC [chaincodeCmd] checkChaincodeCmdParams -> INFO 001 Using default escc
2020-01-13 14:53:52.133 UTC [chaincodeCmd] checkChaincodeCmdParams -> INFO 002 Using default vscc
2020-01-13 14:53:52.150 UTC [chaincodeCmd] chaincodeInvokeOrQuery -> INFO 003 Chaincode invoke successful. result: status:200 
2020-01-13 14:53:52.150 UTC [main] main -> INFO 004 Exiting.....
===================== Invoke transaction on peer0.org1 on channel 'firstchannel' is successful ===================== 

Installing chaincode on peer1.org2...
CORE_PEER_TLS_ROOTCERT_FILE=/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org2.example.com/peers/peer0.org2.example.com/tls/ca.crt
CORE_PEER_TLS_KEY_FILE=/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org1.example.com/peers/peer0.org1.example.com/tls/server.key
CORE_PEER_LOCALMSPID=Org2MSP
CORE_VM_ENDPOINT=unix:///host/var/run/docker.sock
CORE_PEER_TLS_CERT_FILE=/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org1.example.com/peers/peer0.org1.example.com/tls/server.crt
CORE_PEER_TLS_ENABLED=true
CORE_PEER_MSPCONFIGPATH=/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org2.example.com/users/Admin@org2.example.com/msp
CORE_PEER_ID=cli
CORE_LOGGING_LEVEL=INFO
CORE_PEER_ADDRESS=peer1.org2.example.com:7051
+ peer chaincode install -n mycc -v 1.0 -l golang -p github.com/chaincode/chaincode_example02/go/
+ res=0
+ set +x
2020-01-13 14:53:52.296 UTC [chaincodeCmd] checkChaincodeCmdParams -> INFO 001 Using default escc
2020-01-13 14:53:52.297 UTC [chaincodeCmd] checkChaincodeCmdParams -> INFO 002 Using default vscc
2020-01-13 14:53:52.665 UTC [main] main -> INFO 003 Exiting.....
===================== Chaincode is installed on peer1.org2 ===================== 

Querying chaincode on peer1.org2...
CORE_PEER_TLS_ROOTCERT_FILE=/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org2.example.com/peers/peer0.org2.example.com/tls/ca.crt
CORE_PEER_TLS_KEY_FILE=/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org1.example.com/peers/peer0.org1.example.com/tls/server.key
CORE_PEER_LOCALMSPID=Org2MSP
CORE_VM_ENDPOINT=unix:///host/var/run/docker.sock
CORE_PEER_TLS_CERT_FILE=/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org1.example.com/peers/peer0.org1.example.com/tls/server.crt
CORE_PEER_TLS_ENABLED=true
CORE_PEER_MSPCONFIGPATH=/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org2.example.com/users/Admin@org2.example.com/msp
CORE_PEER_ID=cli
CORE_LOGGING_LEVEL=INFO
CORE_PEER_ADDRESS=peer1.org2.example.com:7051
===================== Querying on peer1.org2 on channel 'firstchannel'... ===================== 
Attempting to Query peer1.org2 ...3 secs
+ peer chaincode query -C firstchannel -n mycc -c '{"Args":["query","a"]}'
+ res=0
+ set +x

2020-01-13 14:53:55.859 UTC [chaincodeCmd] checkChaincodeCmdParams -> INFO 001 Using default escc
2020-01-13 14:53:55.860 UTC [chaincodeCmd] checkChaincodeCmdParams -> INFO 002 Using default vscc
Query Result: 90
2020-01-13 14:54:15.800 UTC [main] main -> INFO 003 Exiting.....
===================== Query on peer1.org2 on channel 'firstchannel' is successful ===================== 

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


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

[root@localhost first-network]# 

看到"END",表示网络启动成功,整个启动过程,主要做了4件事情:

1、生成相关CA证书以及组织配置文件

2、创建4个节点的网络(1个order、4个peer)

3、创建channel以及创世区块,并把节点加入到channel中

4、在背书节点上部署chaincode,并初始化,以及调用方法

六、byfn.sh脚本启动网络过程

打开byfn.sh脚本,到文件最后

#Create the network using docker compose
if [ "${MODE}" == "up" ]; then
  networkUp
elif [ "${MODE}" == "down" ]; then ## Clear the network
  networkDown
elif [ "${MODE}" == "generate" ]; then ## Generate Artifacts
  generateCerts
  replacePrivateKey
  generateChannelArtifacts
elif [ "${MODE}" == "restart" ]; then ## Restart the network
  networkDown
  networkUp
elif [ "${MODE}" == "upgrade" ]; then ## Upgrade the network from v1.0.x to v1.1
  upgradeNetwork
else
  printHelp
  exit 1
fi

可以看到up参数对应执行networkUp函数,搜索networkUp

# Generate the needed certificates, the genesis block and start the network.
function networkUp () {
  checkPrereqs
  # generate artifacts if they don't exist
  if [ ! -d "crypto-config" ]; then
    generateCerts
    replacePrivateKey
    generateChannelArtifacts
  fi
  if [ "${IF_COUCHDB}" == "couchdb" ]; then
    IMAGE_TAG=$IMAGETAG docker-compose -f $COMPOSE_FILE -f $COMPOSE_FILE_COUCH up -d 2>&1
  else
    IMAGE_TAG=$IMAGETAG docker-compose -f $COMPOSE_FILE up -d 2>&1
  fi
  if [ $? -ne 0 ]; then
    echo "ERROR !!!! Unable to start network"
    exit 1
  fi
  # now run the end to end script
  docker exec cli scripts/script.sh $CHANNEL_NAME $CLI_DELAY $LANGUAGE $CLI_TIMEOUT
  if [ $? -ne 0 ]; then
    echo "ERROR !!!! Test failed"
    exit 1
  fi
}

checkPrereqs,检查二进制文件版本跟fabric版本是否一致

generateCerts:使用cryptogen根据crypto-config.yaml文件,为网络中的每个节点以及组织生成证书/秘钥
replacePrivateKey:复制docker-compose-e2e-template.yaml 为docker-compose-e2e.yaml,替换里面的私钥
generateChannelArtifacts:函数主要做了4件事1、生成创世区块 configtxgen -profile TwoOrgsOrdererGenesis -outputBlock ./channel-artifacts/genesis.block2、生成channel配置文件:configtxgen -profile TwoOrgsChannel -outputCreateChannelTx ./channel-artifacts/channel.tx -channelID $CHANNEL_NAME
3、为Org1生成锚节点配置文件: configtxgen -profile TwoOrgsChannel -outputAnchorPeersUpdate ./channel-artifacts/Org1MSPanchors.tx -channelID $CHANNEL_NAME -asOrg Org1MSP4、为Org2生成锚节点配置文件:configtxgen -profile TwoOrgsChannel -outputAnchorPeersUpdate ./channel-artifacts/Org2MSPanchors.tx -channelID $CHANNEL_NAME -asOrg Org2MSP
IMAGE_TAG=$IMAGETAG docker-compose -f $COMPOSE_FILE up -d 2>&1根据docker-compose-cli.yaml里面定义的服务,利用docker-compose启动节点docker exec cli scripts/script.sh $CHANNEL_NAME $CLI_DELAY $LANGUAGE $CLI_TIMEOUT最后,进入cli容器,运行scripts/script.sh脚本,该脚本主要是创建channel、加入channel、设置org1\org2锚节点、安装chaincode、初始化chaincode、调用chaincode、查询chaincode等功能
## Create channel
echo "Creating channel..."
createChannel

## Join all the peers to the channel
echo "Having all peers join the channel..."
joinChannel

## Set the anchor peers for each org in the channel
echo "Updating anchor peers for org1..."
updateAnchorPeers 0 1
echo "Updating anchor peers for org2..."
updateAnchorPeers 0 2

## Install chaincode on peer0.org1 and peer0.org2
echo "Installing chaincode on peer0.org1..."
installChaincode 0 1
echo "Install chaincode on peer0.org2..."
installChaincode 0 2

# Instantiate chaincode on peer0.org2
echo "Instantiating chaincode on peer0.org2..."
instantiateChaincode 0 2
            done
        done
}

## Create channel
echo "Creating channel..."
createChannel

## Join all the peers to the channel
echo "Having all peers join the channel..."
joinChannel

## Set the anchor peers for each org in the channel
echo "Updating anchor peers for org1..."
updateAnchorPeers 0 1
echo "Updating anchor peers for org2..."
updateAnchorPeers 0 2

## Install chaincode on peer0.org1 and peer0.org2
echo "Installing chaincode on peer0.org1..."
installChaincode 0 1
echo "Install chaincode on peer0.org2..."
installChaincode 0 2

# Instantiate chaincode on peer0.org2
echo "Instantiating chaincode on peer0.org2..."
instantiateChaincode 0 2

# Query chaincode on peer0.org1
echo "Querying chaincode on peer0.org1..."
chaincodeQuery 0 1 100

# Invoke chaincode on peer0.org1
echo "Sending invoke transaction on peer0.org1..."
chaincodeInvoke 0 1

## Install chaincode on peer1.org2
echo "Installing chaincode on peer1.org2..."
installChaincode 1 2

# Query on chaincode on peer1.org2, check if the result is 90
echo "Querying chaincode on peer1.org2..."
chaincodeQuery 1 2 90

到此,整个网络启动完毕。

 
 
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!