johnnian/Blog

区块链学习—Hyberledger Fabric 网络搭建入门

Opened this issue · 0 comments

Hyperledger Fabric 网络搭建

1开发环境搭建

1.1 Linux环境搭建

虚拟机初始化Linux系统

初始化CentOS

​ 硬件要求:至少有 8G 内存,100G硬盘

Windows 操作系统下安装 VMware Workstation+Centos 来得到 Linux 环境

官网下载,自行安装即可

​ Centos7下载,自行安装即可,参照一下注意事项

step1: 进入下载页,选择阿里云站点进行下载

​ 阿里云站点:http://mirrors.aliyun.com/centos/7.8.2003/isos/x86_64/

​ PS:每个链接都包括了镜像文件的地址、类型及版本号等信息,选择当前国家资源区站点下载,获取资源速度比较快

step2: 进入阿里云站点,选择 CentOS-7-x86_64-DVD-2003.iso 下载

宿主机与虚机共享文件

​ 具体操作步骤可参照共享目录

Linux系统配置优化

安装wget
yum -y install wget
更新yum源

1、备份本地源

mv /etc/yum.repos.d/CentOS-Base.repo /etc/yum.repos.d/CentOS-Base.repo_bak

2 、获取阿里源配置文件

wget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-7.repo

3 、更新epel仓库

wget -O /etc/yum.repos.d/epel.repo http://mirrors.aliyun.com/repo/epel-7.repo

4 、更新cache

yum makecache
yum -y update

1.2 辅助环境安装配置

前置软件Git curl

curl 已内置

安装Git:

yum install -y git

安装Docker及配置

基本要求:虚拟机装的Centos7,linux 3.10 内核,docker官方说至少3.8以上,建议3.10以上

1、root账户登录,查看内核版本如下

 uname -a

Linux localhost.localdomain 3.10.0-957.el7.x86_64 #1 SMP Thu Nov 8 23:39:32 UTC 2018 x86_64 x86_64 x86_64 GNU/Linux

2、安装需要的软件包, yum-util 提供yum-config-manager功能,另外两个是devicemapper驱动依赖的

yum install -y yum-utils device-mapper-persistent-data lvm2


Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile

 * base: mirrors.aliyun.com
 * extras: mirrors.aliyun.com
 * updates: mirrors.aliyun.com
Package device-mapper-persistent-data-0.8.5-2.el7.x86_64 already installed and latest version
Package 7:lvm2-2.02.186-7.el7_8.2.x86_64 already installed and latest version
Resolving Dependencies
--> Running transaction check
---> Package yum-utils.noarch 0:1.1.31-54.el7_8 will be installed
--> Processing Dependency: python-kitchen for package: yum-utils-1.1.31-54.el7_8.noarch
--> Processing Dependency: libxml2-python for package: yum-utils-1.1.31-54.el7_8.noarch
--> Running transaction check
---> Package libxml2-python.x86_64 0:2.9.1-6.el7.4 will be installed
---> Package python-kitchen.noarch 0:1.1.1-5.el7 will be installed
--> Processing Dependency: python-chardet for package: python-kitchen-1.1.1-5.el7.noarch
--> Running transaction check
---> Package python-chardet.noarch 0:2.2.1-3.el7 will be installed
--> Finished Dependency Resolution

3、设置yum源(选择其中一个,任何一个均可)

yum-config-manager --add-repo http://download.docker.com/linux/centos/docker-ce.repo(**仓库)

yum-config-manager --add-repo http://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo(阿里仓库)

yum-config-manager --add-repo http://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo

​	Loaded plugins: fastestmirror
​	adding repo from: http://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo
​	grabbing file http://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo to /etc/yum.repos.d/docker-ce.repo
​	repo saved to /etc/yum.repos.d/docker-ce.repo

4、可以查看所有仓库中所有docker版本,并选择特定版本安装

yum list docker-ce --showduplicates | sort -r

5、安装Docker,命令:yum install docker-ce-版本号,我选的是docker-ce-18.06.3.ce,如下

yum -y install docker-ce-18.06.3.ce


Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile

 * base: mirrors.aliyun.com
 * extras: mirrors.aliyun.com
 * updates: mirrors.aliyun.com
Resolving Dependencies
--> Running transaction check
---> Package docker-ce.x86_64 0:18.06.3.ce-3.el7 will be installed

由于repo中默认只开启stable仓库,故这里安装的是最新稳定版18.06.3

6、启动并加入开机启动

sudo systemctl start docker
sudo systemctl enable docker

7、验证安装是否成功(有client和service两部分表示docker安装启动都成功了)

docker version

8、设置国内镜像源

在/etc/docker目录下找到在daemon.json文件(没有就新建),将下面内容写入

{
 "registry-mirrors": ["http://hub-mirror.c.163.com","https://registry.docker-cn.com","https://docker.mirrors.ustc.edu.cn"]
}

9、重启daemon:sudo systemctl daemon-reload

10、重启docker服务:sudo systemctl restart docker

安装Docker-compose

sudo curl -L "https://github.com/docker/compose/releases/download/1.26.0/docker-compose-$(uname -s)-$(uname -m)" -o /usr/local/bin/docker-compose
sudo chmod +x /usr/local/bin/docker-compose
docker-compose --version

安装Golang及配置

建议下载1.13.8以上的版本,否则编译fabric的时候会报错

wget https://dl.google.com/go/go1.14.linux-amd64.tar.gz
tar -xvf go1.14.linux-amd64.tar.gz
mv ./go  /usr/local

创建GO工作目录

mkdir -p /home/go/src

设置环境变量
vim /etc/profile

在最下面添加下面三行代码

export  GOROOT=/usr/local/go
export  GOPATH=/home/go
export  PATH=$PATH:$GOROOT/bin

source /etc/profile

验证Golang版本:go version

安装Docker容器实时日志服务

cp /home/workspace

docker-compose -f dozzle-docker-compose.yml up -d

启动后容器列表

CONTAINER ID        IMAGE                  COMMAND             CREATED             STATUS              PORTS                    NAMES
f3db28970111        amir20/dozzle:latest   "/dozzle"           About an hour ago   Up About an hour    0.0.0.0:9999->8080/tcp   dozzle

1.3 脚本化安装Fabric

mkdir -p $GOPATH/src/github.com/hyperledger

cd $GOPATH/src/github.com/hyperledger

git clone https://github.com/hyperledger/fabric.git

或采用快照加速

git clone https://github.com.cnpmjs.org/hyperledger/fabric.git

cd fabric

# 查看版本号

git tag

*# 切换到1.4.7版本分支下

git checkout v1.4.7

# 查看当前分支

git branch -a

# 可以看到已经切换到1.4.7下


* (detached from v1.4.7)
  master
  remotes/origin/HEAD -> origin/master
  remotes/origin/feature/ca
  remotes/origin/feature/convergence
  remotes/origin/master
  remotes/origin/release-1.0
  remotes/origin/release-1.1
  remotes/origin/release-1.2
  remotes/origin/release-1.3
  remotes/origin/release-1.4
  remotes/origin/release-2.0
  remotes/origin/release-2.1
  remotes/origin/release-2.2
  remotes/origin/v0.6
  remotes/origin/v1.0.0-preview

编译

yum -y install gcc gcc-c++ kernel-devel
make release

编译完成后可得到对应的可执行文件

ls  /home/go/src/github.com/hyperledger/fabric/release/linux-amd64/bin

-rwxr-xr-x. 1 root root 24241952 Jul 10 21:54 configtxgen
-rwxr-xr-x. 1 root root 26716744 Jul 10 21:55 configtxlator
-rwxr-xr-x. 1 root root 16722424 Jul 10 21:55 cryptogen
-rwxr-xr-x. 1 root root 25279184 Jul 10 21:55 discover
-rwxr-xr-x. 1 root root 15109144 Jul 10 21:55 idemixgen
-rwxr-xr-x. 1 root root 37721656 Jul 10 21:55 orderer
-rwxr-xr-x. 1 root root 45093176 Jul 10 21:55 peer

启动网络
进入/home/go/src/github.com/hyperledger/fabric/scripts/fabric-samples/first-network目录,运行./byfn.sh -m up即可启动网络,启动之后可能会出现命令行断开的情况。只需要登录同网段的节点,ssh到fabric节点,重新启动一下网络即可。

1.4 编译安装Fabric

编译安装peer组件

cd $GOPATH/src/github.com/hyperledger/fabric/
make peer

计算机输出:

.build/bin/peer
CGO_CFLAGS=" " GOBIN=/home/go/src/github.com/hyperledger/fabric/.build/bin go install -tags "" -ldflags "-X github.com/hyperledger/fabric/common/metadata.Version=1.4.7 -X github.com/hyperledger/fabric/common/metadata.CommitSHA=e0afaa7 -X github.com/hyperledger/fabric/common/metadata.BaseVersion=0.4.20 -X github.com/hyperledger/fabric/common/metadata.BaseDockerLabel=org.hyperledger.fabric -X github.com/hyperledger/fabric/common/metadata.DockerNamespace=hyperledger -X github.com/hyperledger/fabric/common/metadata.BaseDockerNamespace=hyperledger" github.com/hyperledger/fabric/peer
Binary available as .build/bin/peer

根据输出得知编译好的 peer 二进制文件在 ./.build/bin/ 下面,把它复制到 GOPATH/bin 下即可:

cp .build/bin/peer $GOROOT/bin/

然后在任意目录下运行:

peer version

终端返回:

 peer:
 Version: 1.4.7
 Commit SHA: e0afaa7
 Go version: go1.14
 OS/Arch: linux/amd64
 Chaincode:
  Base Image Version: 0.4.20
  Base Docker Namespace: hyperledger
  Base Docker Label: org.hyperledger.fabric
  Docker Namespace: hyperledger

编译安装 fabric-order 组件

cd $GOPATH/src/github.com/hyperledger/fabric/
make orderer

计算机输出:

.build/bin/orderer
CGO_CFLAGS=" " GOBIN=/home/go/src/github.com/hyperledger/fabric/.build/bin go install -tags "" -ldflags "-X github.com/hyperledger/fabric/common/metadata.Version=1.4.7 -X github.com/hyperledger/fabric/common/metadata.CommitSHA=e0afaa7 -X github.com/hyperledger/fabric/common/metadata.BaseVersion=0.4.20 -X github.com/hyperledger/fabric/common/metadata.BaseDockerLabel=org.hyperledger.fabric -X github.com/hyperledger/fabric/common/metadata.DockerNamespace=hyperledger -X github.com/hyperledger/fabric/common/metadata.BaseDockerNamespace=hyperledger" github.com/hyperledger/fabric/orderer
Binary available as .build/bin/orderer

同样把它移到 $GOPATH/bin

cp .build/bin/orderer $GOROOT/bin

验证是否安装成功:

orderer version

终端返回:

 orderer:
 Version: 1.4.7
 Commit SHA: e0afaa7
 Go version: go1.14
 OS/Arch: linux/amd64

编译安装 fabric-ca 组件

拉取 fabric-ca 代码:

git clone https://github.com/hyperledger/fabric-ca.git
或快照加速
git clone https://github.com.cnpmjs.org/hyperledger/fabric-ca.git

过一阵子代码就下载到了 $GOPATH/src/github.com/hyperledger/fabric-ca/ 下面了,进入该目录,即可开始安装 fabric-ca 组件。

切换目标分支

git tag
git checkout v1.4.7
git branch -a

编译 fabric-ca-server:

cd $GOPATH/src/github.com/hyperledger/fabric-ca/


make fabric-ca-server

计算机输出:

Building fabric-ca-server in bin directory ...
Built bin/fabric-ca-server

复制到 $GOPATH/bin/

cp ./bin/fabric-ca-server $GOROOT/bin

验证是否安装成功:

 fabric-ca-server version
  fabric-ca-server:
 Version: 1.4.7
 Go version: go1.14
 OS/Arch: linux/amd64

同样安装 fabric-ca-client:

 make fabric-ca-client

后续步骤和安装 fabric-ca-server 相同。

编译其他辅助工具

cryptogen(用于生成组织机构和身份文件)、configtxgen(生成配置区块和配置交易)、configtxlator(解读配置信息)、discover(服务发现命令行工具)、idemixgen(MSP配置生成器,fabric的零知识身份证明有两种方法,一个是通过CA,另一个是通过idemixgen)等:

这里用 configtxgen 作为示例,其他的把对应名字改为 cryptogen/configtxlator/discover /idemixgen就 ok 了:

cd $GOPATH/src/github.com/hyperledger/fabric
make configtxgen

最后计算机输出是:

.build/bin/configtxgen
CGO_CFLAGS=" " GOBIN=/home/go/src/github.com/hyperledger/fabric/.build/bin go install -tags "" -ldflags "-X github.com/hyperledger/fabric/common/tools/configtxgen/metadata.CommitSHA=e0afaa7" github.com/hyperledger/fabric/common/tools/configtxgen
Binary available as .build/bin/configtxgen

表示成功编译。 执行 ./.build/bin/configtxgen --version 会有以下输出:

configtxgen:
 Version: 1.4.7
 Commit SHA: e0afaa7
 Go version: go1.14
 OS/Arch: linux/amd64

这样,在 Linux 环境下安装好了 Fabric 对应环境。

2 案例运行与模拟使用

2.1 初始化必要组件

# 下载基础镜像以及samples
cd /home/go/src/github.com/hyperledger/fabric/scripts
./bootstrap.sh 1.4.7 -s

# 初始化组件环境变量
# 方式一:
# 复制可执行配置文件至全局:
cp /home/go/src/github.com/hyperledger/fabric/release/linux-amd64/bin/* $GOROOT/bin/
# 赋执行权限:chmod +x $GOROOT/bin/*
# 方式二:
# 复制可执行配置文件至示例项目:
cd /home/go/src/github.com/hyperledger/fabric/scripts/fabric-samples/
cp /home/go/src/github.com/hyperledger/fabric/release/linux-amd64/bin ./
# 赋执行权限:chmod +x ./bin/*

# 进入主目录
cd  first-network/

2.2 启动网络

生成密钥、创世区块(可选)

sh byfn.sh -m 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 ...
/home/go/src/github.com/hyperledger/fabric/scripts/fabric-samples/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
/home/go/src/github.com/hyperledger/fabric/scripts/fabric-samples/bin/configtxgen
##########################################################
#########  Generating Orderer Genesis block ##############
##########################################################
CONSENSUS_TYPE=solo
+ '[' solo == solo ']'
+ configtxgen -profile TwoOrgsOrdererGenesis -channelID byfn-sys-channel -outputBlock ./channel-artifacts/genesis.block
2020-07-11 03:56:18.863 CST [common.tools.configtxgen] main -> INFO 001 Loading configuration
2020-07-11 03:56:18.959 CST [common.tools.configtxgen.localconfig] completeInitialization -> INFO 002 orderer type: solo
2020-07-11 03:56:18.959 CST [common.tools.configtxgen.localconfig] Load -> INFO 003 Loaded configuration: /home/go/src/github.com/hyperledger/fabric/scripts/fabric-samples/first-network/configtx.yaml
2020-07-11 03:56:19.053 CST [common.tools.configtxgen.localconfig] completeInitialization -> INFO 004 orderer type: solo
2020-07-11 03:56:19.053 CST [common.tools.configtxgen.localconfig] LoadTopLevel -> INFO 005 Loaded configuration: /home/go/src/github.com/hyperledger/fabric/scripts/fabric-samples/first-network/configtx.yaml
2020-07-11 03:56:19.057 CST [common.tools.configtxgen] doOutputBlock -> INFO 006 Generating genesis block
2020-07-11 03:56:19.059 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
2020-07-11 03:56:19.089 CST [common.tools.configtxgen] main -> INFO 001 Loading configuration
2020-07-11 03:56:19.181 CST [common.tools.configtxgen.localconfig] Load -> INFO 002 Loaded configuration: /home/go/src/github.com/hyperledger/fabric/scripts/fabric-samples/first-network/configtx.yaml
2020-07-11 03:56:19.273 CST [common.tools.configtxgen.localconfig] completeInitialization -> INFO 003 orderer type: solo
2020-07-11 03:56:19.274 CST [common.tools.configtxgen.localconfig] LoadTopLevel -> INFO 004 Loaded configuration: /home/go/src/github.com/hyperledger/fabric/scripts/fabric-samples/first-network/configtx.yaml
2020-07-11 03:56:19.274 CST [common.tools.configtxgen] doOutputChannelCreateTx -> INFO 005 Generating new channel configtx
2020-07-11 03:56:19.277 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
2020-07-11 03:56:19.307 CST [common.tools.configtxgen] main -> INFO 001 Loading configuration
2020-07-11 03:56:19.402 CST [common.tools.configtxgen.localconfig] Load -> INFO 002 Loaded configuration: /home/go/src/github.com/hyperledger/fabric/scripts/fabric-samples/first-network/configtx.yaml
2020-07-11 03:56:19.488 CST [common.tools.configtxgen.localconfig] completeInitialization -> INFO 003 orderer type: solo
2020-07-11 03:56:19.488 CST [common.tools.configtxgen.localconfig] LoadTopLevel -> INFO 004 Loaded configuration: /home/go/src/github.com/hyperledger/fabric/scripts/fabric-samples/first-network/configtx.yaml
2020-07-11 03:56:19.488 CST [common.tools.configtxgen] doOutputAnchorPeersUpdate -> INFO 005 Generating anchor peer update
2020-07-11 03:56:19.489 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
2020-07-11 03:56:19.525 CST [common.tools.configtxgen] main -> INFO 001 Loading configuration
2020-07-11 03:56:19.614 CST [common.tools.configtxgen.localconfig] Load -> INFO 002 Loaded configuration: /home/go/src/github.com/hyperledger/fabric/scripts/fabric-samples/first-network/configtx.yaml
2020-07-11 03:56:19.701 CST [common.tools.configtxgen.localconfig] completeInitialization -> INFO 003 orderer type: solo
2020-07-11 03:56:19.701 CST [common.tools.configtxgen.localconfig] LoadTopLevel -> INFO 004 Loaded configuration: /home/go/src/github.com/hyperledger/fabric/scripts/fabric-samples/first-network/configtx.yaml
2020-07-11 03:56:19.701 CST [common.tools.configtxgen] doOutputAnchorPeersUpdate -> INFO 005 Generating anchor peer update
2020-07-11 03:56:19.701 CST [common.tools.configtxgen] doOutputAnchorPeersUpdate -> INFO 006 Writing anchor peer update
+ res=0
+ set +x

启动区块链网络:

sh byfn.sh -m up

前台日志
Starting for channel 'mychannel' with CLI timeout of '10' seconds and CLI delay of '3' seconds
Continue? [Y/n] y
proceeding ...
LOCAL_VERSION=1.4.7
DOCKER_IMAGE_VERSION=1.4.7
/home/go/src/github.com/hyperledger/fabric/scripts/fabric-samples/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
/home/go/src/github.com/hyperledger/fabric/scripts/fabric-samples/bin/configtxgen
##########################################################
#########  Generating Orderer Genesis block ##############
##########################################################
CONSENSUS_TYPE=solo
+ '[' solo == solo ']'
+ configtxgen -profile TwoOrgsOrdererGenesis -channelID byfn-sys-channel -outputBlock ./channel-artifacts/genesis.block
2020-07-11 03:12:56.333 CST [common.tools.configtxgen] main -> INFO 001 Loading configuration
2020-07-11 03:12:56.426 CST [common.tools.configtxgen.localconfig] completeInitialization -> INFO 002 orderer type: solo
2020-07-11 03:12:56.426 CST [common.tools.configtxgen.localconfig] Load -> INFO 003 Loaded configuration: /home/go/src/github.com/hyperledger/fabric/scripts/fabric-samples/first-network/configtx.yaml
2020-07-11 03:12:56.517 CST [common.tools.configtxgen.localconfig] completeInitialization -> INFO 004 orderer type: solo
2020-07-11 03:12:56.517 CST [common.tools.configtxgen.localconfig] LoadTopLevel -> INFO 005 Loaded configuration: /home/go/src/github.com/hyperledger/fabric/scripts/fabric-samples/first-network/configtx.yaml
2020-07-11 03:12:56.519 CST [common.tools.configtxgen] doOutputBlock -> INFO 006 Generating genesis block
2020-07-11 03:12:56.519 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
2020-07-11 03:12:56.554 CST [common.tools.configtxgen] main -> INFO 001 Loading configuration
2020-07-11 03:12:56.648 CST [common.tools.configtxgen.localconfig] Load -> INFO 002 Loaded configuration: /home/go/src/github.com/hyperledger/fabric/scripts/fabric-samples/first-network/configtx.yaml
2020-07-11 03:12:56.738 CST [common.tools.configtxgen.localconfig] completeInitialization -> INFO 003 orderer type: solo
2020-07-11 03:12:56.739 CST [common.tools.configtxgen.localconfig] LoadTopLevel -> INFO 004 Loaded configuration: /home/go/src/github.com/hyperledger/fabric/scripts/fabric-samples/first-network/configtx.yaml
2020-07-11 03:12:56.739 CST [common.tools.configtxgen] doOutputChannelCreateTx -> INFO 005 Generating new channel configtx
2020-07-11 03:12:56.741 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
2020-07-11 03:12:56.775 CST [common.tools.configtxgen] main -> INFO 001 Loading configuration
2020-07-11 03:12:56.868 CST [common.tools.configtxgen.localconfig] Load -> INFO 002 Loaded configuration: /home/go/src/github.com/hyperledger/fabric/scripts/fabric-samples/first-network/configtx.yaml
2020-07-11 03:12:56.960 CST [common.tools.configtxgen.localconfig] completeInitialization -> INFO 003 orderer type: solo
2020-07-11 03:12:56.960 CST [common.tools.configtxgen.localconfig] LoadTopLevel -> INFO 004 Loaded configuration: /home/go/src/github.com/hyperledger/fabric/scripts/fabric-samples/first-network/configtx.yaml
2020-07-11 03:12:56.960 CST [common.tools.configtxgen] doOutputAnchorPeersUpdate -> INFO 005 Generating anchor peer update
2020-07-11 03:12:56.960 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
2020-07-11 03:12:56.997 CST [common.tools.configtxgen] main -> INFO 001 Loading configuration
2020-07-11 03:12:57.093 CST [common.tools.configtxgen.localconfig] Load -> INFO 002 Loaded configuration: /home/go/src/github.com/hyperledger/fabric/scripts/fabric-samples/first-network/configtx.yaml
2020-07-11 03:12:57.182 CST [common.tools.configtxgen.localconfig] completeInitialization -> INFO 003 orderer type: solo
2020-07-11 03:12:57.182 CST [common.tools.configtxgen.localconfig] LoadTopLevel -> INFO 004 Loaded configuration: /home/go/src/github.com/hyperledger/fabric/scripts/fabric-samples/first-network/configtx.yaml
2020-07-11 03:12:57.182 CST [common.tools.configtxgen] doOutputAnchorPeersUpdate -> INFO 005 Generating anchor peer update
2020-07-11 03:12:57.182 CST [common.tools.configtxgen] doOutputAnchorPeersUpdate -> INFO 006 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 orderer.example.com    ... done
Creating peer1.org1.example.com ... done
Creating peer0.org1.example.com ... done
Creating peer1.org2.example.com ... done
Creating peer0.org2.example.com ... done
Creating cli                    ... done
CONTAINER ID        IMAGE                               COMMAND             CREATED                  STATUS                  PORTS                      NAMES
65a6945709c7        hyperledger/fabric-tools:latest     "/bin/bash"         Less than a second ago   Up Less than a second                              cli
f75c918d11a9        hyperledger/fabric-peer:latest      "peer node start"   1 second ago             Up Less than a second   0.0.0.0:9051->9051/tcp     peer0.org2.example.com
68b7559fb7c3        hyperledger/fabric-peer:latest      "peer node start"   1 second ago             Up Less than a second   0.0.0.0:10051->10051/tcp   peer1.org2.example.com
1666d9a0fb51        hyperledger/fabric-peer:latest      "peer node start"   1 second ago             Up Less than a second   0.0.0.0:7051->7051/tcp     peer0.org1.example.com
af14960f9de4        hyperledger/fabric-peer:latest      "peer node start"   1 second ago             Up Less than a second   0.0.0.0:8051->8051/tcp     peer1.org1.example.com
f0473fa71bf9        hyperledger/fabric-orderer:latest   "orderer"           1 second ago             Up Less than a second   0.0.0.0:7050->7050/tcp     orderer.example.com
89a33b3147a0        amir20/dozzle:latest                "/dozzle"           About an hour ago        Up About an hour        0.0.0.0:9999->8080/tcp     dozzle

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

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

Channel name : mychannel
Creating channel...
+ peer channel create -o orderer.example.com:7050 -c mychannel -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-07-10 19:12:59.978 UTC [channelCmd] InitCmdFactory -> INFO 001 Endorser and orderer connections initialized
2020-07-10 19:13:00.002 UTC [cli.common] readBlock -> INFO 002 Received block: 0
+ peer channel join -b mychannel.block
===================== Channel 'mychannel' created =====================

Having all peers join the channel...
+ res=0
+ set +x
2020-07-10 19:13:00.063 UTC [channelCmd] InitCmdFactory -> INFO 001 Endorser and orderer connections initialized
2020-07-10 19:13:00.092 UTC [channelCmd] executeJoin -> INFO 002 Successfully submitted proposal to join channel
===================== peer0.org1 joined channel 'mychannel' =====================

+ peer channel join -b mychannel.block
+ res=0
+ set +x
2020-07-10 19:13:03.166 UTC [channelCmd] InitCmdFactory -> INFO 001 Endorser and orderer connections initialized
2020-07-10 19:13:03.198 UTC [channelCmd] executeJoin -> INFO 002 Successfully submitted proposal to join channel
===================== peer1.org1 joined channel 'mychannel' =====================

+ peer channel join -b mychannel.block
+ res=0
+ set +x
2020-07-10 19:13:06.270 UTC [channelCmd] InitCmdFactory -> INFO 001 Endorser and orderer connections initialized
2020-07-10 19:13:06.293 UTC [channelCmd] executeJoin -> INFO 002 Successfully submitted proposal to join channel
===================== peer0.org2 joined channel 'mychannel' =====================

+ peer channel join -b mychannel.block
+ res=0
+ set +x
2020-07-10 19:13:09.369 UTC [channelCmd] InitCmdFactory -> INFO 001 Endorser and orderer connections initialized
2020-07-10 19:13:09.396 UTC [channelCmd] executeJoin -> INFO 002 Successfully submitted proposal to join channel
===================== peer1.org2 joined channel 'mychannel' =====================

Updating anchor peers for org1...
+ peer channel update -o orderer.example.com:7050 -c mychannel -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-07-10 19:13:12.469 UTC [channelCmd] InitCmdFactory -> INFO 001 Endorser and orderer connections initialized
2020-07-10 19:13:12.481 UTC [channelCmd] update -> INFO 002 Successfully submitted channel update
===================== Anchor peers updated for org 'Org1MSP' on channel 'mychannel' =====================

Updating anchor peers for org2...
+ peer channel update -o orderer.example.com:7050 -c mychannel -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-07-10 19:13:15.563 UTC [channelCmd] InitCmdFactory -> INFO 001 Endorser and orderer connections initialized
2020-07-10 19:13:15.574 UTC [channelCmd] update -> INFO 002 Successfully submitted channel update
===================== Anchor peers updated for org 'Org2MSP' on channel 'mychannel' =====================

Installing chaincode on peer0.org1...
+ peer chaincode install -n mycc -v 1.0 -l golang -p github.com/chaincode/chaincode_example02/go/
+ res=0
+ set +x
2020-07-10 19:13:18.657 UTC [chaincodeCmd] checkChaincodeCmdParams -> INFO 001 Using default escc
2020-07-10 19:13:18.657 UTC [chaincodeCmd] checkChaincodeCmdParams -> INFO 002 Using default vscc
2020-07-10 19:13:19.097 UTC [chaincodeCmd] install -> INFO 003 Installed remotely response:<status:200 payload:"OK" >
===================== Chaincode is installed on peer0.org1 =====================

Install chaincode on peer0.org2...
+ peer chaincode install -n mycc -v 1.0 -l golang -p github.com/chaincode/chaincode_example02/go/
+ res=0
+ set +x
2020-07-10 19:13:19.166 UTC [chaincodeCmd] checkChaincodeCmdParams -> INFO 001 Using default escc
2020-07-10 19:13:19.166 UTC [chaincodeCmd] checkChaincodeCmdParams -> INFO 002 Using default vscc
2020-07-10 19:13:19.454 UTC [chaincodeCmd] install -> INFO 003 Installed remotely response:<status:200 payload:"OK" >
===================== Chaincode is installed on peer0.org2 =====================

Instantiating chaincode on peer0.org2...
+ 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 mychannel -n mycc -l golang -v 1.0 -c '{"Args":["init","a","100","b","200"]}' -P 'AND ('\''Org1MSP.peer'\'','\''Org2MSP.peer'\'')'
+ res=0
+ set +x
2020-07-10 19:13:19.569 UTC [chaincodeCmd] checkChaincodeCmdParams -> INFO 001 Using default escc
2020-07-10 19:13:19.569 UTC [chaincodeCmd] checkChaincodeCmdParams -> INFO 002 Using default vscc
===================== Chaincode is instantiated on peer0.org2 on channel 'mychannel' =====================

Querying chaincode on peer0.org1...
===================== Querying on peer0.org1 on channel 'mychannel'... =====================
+ peer chaincode query -C mychannel -n mycc -c '{"Args":["query","a"]}'
Attempting to Query peer0.org1 ...3 secs
+ res=0
+ set +x

100
===================== Query successful on peer0.org1 on channel 'mychannel' =====================
Sending invoke transaction on peer0.org1 peer0.org2...
+ 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 mychannel -n mycc --peerAddresses peer0.org1.example.com:7051 --tlsRootCertFiles /opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org1.example.com/peers/peer0.org1.example.com/tls/ca.crt --peerAddresses peer0.org2.example.com:9051 --tlsRootCertFiles /opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org2.example.com/peers/peer0.org2.example.com/tls/ca.crt -c '{"Args":["invoke","a","b","10"]}'
+ res=0
+ set +x
2020-07-10 19:13:50.271 UTC [chaincodeCmd] chaincodeInvokeOrQuery -> INFO 001 Chaincode invoke successful. result: status:200
===================== Invoke transaction successful on peer0.org1 peer0.org2 on channel 'mychannel' =====================

Installing chaincode on peer1.org2...
+ peer chaincode install -n mycc -v 1.0 -l golang -p github.com/chaincode/chaincode_example02/go/
+ res=0
+ set +x
2020-07-10 19:13:50.333 UTC [chaincodeCmd] checkChaincodeCmdParams -> INFO 001 Using default escc
2020-07-10 19:13:50.333 UTC [chaincodeCmd] checkChaincodeCmdParams -> INFO 002 Using default vscc
2020-07-10 19:13:50.553 UTC [chaincodeCmd] install -> INFO 003 Installed remotely response:<status:200 payload:"OK" >
===================== Chaincode is installed on peer1.org2 =====================

Querying chaincode on peer1.org2...
===================== Querying on peer1.org2 on channel 'mychannel'... =====================
+ peer chaincode query -C mychannel -n mycc -c '{"Args":["query","a"]}'
Attempting to Query peer1.org2 ...3 secs
+ res=0
+ set +x

90
===================== Query successful on peer1.org2 on channel 'mychannel' =====================

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


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





后台链码容器日志

dev-peer0.org1.example.com-mycc-1.0

  • today at 3:13 AM ex02 Invoke
  • today at 3:13 AM Query Response:{"Name":"a","Amount":"100"}
  • today at 3:13 AM ex02 Invoke
  • today at 3:13 AM Aval = 90, Bval = 210

dev-peer0.org2.example.com-mycc-1.0

  • today at 3:13 AM ex02 Init
  • today at 3:13 AM Aval = 100, Bval = 200
  • today at 3:13 AM ex02 Invoke
  • today at 3:13 AM Aval = 90, Bval = 210

dev-peer1.org2.example.com-mycc-1.0

  • today at 3:14 AM ex02 Invoke
  • today at 3:14 AM Query Response:{"Name":"a","Amount":"90"}

2.3 关闭网络

sh byfn.sh -m down
关闭容器、清除容器及文件
> 请在网络不再使用时,务必关闭网络,以防止后期启动网络时造成的错误。