Hyperledger Fabric安装

系统环境及工具

  • VMware 12
  • Ubuntu 20.04.1 LTS
  • Xshell 6

一、更新Ubuntu软件

1、更新Ubuntu软件镜像源

cd /etc/apt 
sudo mv /etc/apt/sources.list /etc/apt/sources.list.bak
sudo vi /etc/apt/sources.list  

#  清华大学源
deb http://mirrors.tuna.tsinghua.edu.cn/ubuntu/ focal main restricted
deb http://mirrors.tuna.tsinghua.edu.cn/ubuntu/ focal-updates main restricted
deb http://mirrors.tuna.tsinghua.edu.cn/ubuntu/ focal universe
deb http://mirrors.tuna.tsinghua.edu.cn/ubuntu/ focal-updates universe
deb http://mirrors.tuna.tsinghua.edu.cn/ubuntu/ focal multiverse
deb http://mirrors.tuna.tsinghua.edu.cn/ubuntu/ focal-updates multiverse
deb http://mirrors.tuna.tsinghua.edu.cn/ubuntu/ focal-backports main restricted universe multiverse
deb http://mirrors.tuna.tsinghua.edu.cn/ubuntu/ focal-security main restricted
deb http://mirrors.tuna.tsinghua.edu.cn/ubuntu/ focal-security universe
deb http://mirrors.tuna.tsinghua.edu.cn/ubuntu/ focal-security multiverse

2、更新软件

sudo apt update
sudo apt upgrade

3、安装curl

sudo apt install curl

4、安装git

sudo apt install git

5、安装jq

sudo apt install jq

二、安装GO

Go语言中文网:https://studygolang.com/dl

cd /usr/local/src
sudo wget -c https://studygolang.com/dl/golang/go1.14.linux-amd64.tar.gz
sudo tar -xzvf go1.14.linux-amd64.tar.gz -C ../

# 配置环境变量
sudo vim /etc/profile

# 在文件尾加入
export GOROOT=/usr/local/go
export GOPATH=$HOME/go
export PATH=$PATH:$GOROOT/bin

# 使环境变量生效
source /etc/profile

# 查看版本
go version
go version go1.14 linux/amd64

# 更新包镜像源(可选操作)
go env -w GO111MODULE=on #开启 MODULE
go env -w GOPROXY=https://goproxy.cn,https://goproxy.io,direct

三、安装NodeJS

cd /usr/local/src/
sudo wget -c https://nodejs.org/dist/v12.18.3/node-v12.18.3-linux-x64.tar.xz
sudo xz -d node-v12.18.3-linux-x64.tar.xz
sudo tar -xvf node-v12.18.3-linux-x64.tar
sudo mv node-v12.18.3-linux-x64 ../node-v12.18.3
cd /usr/local/bin
sudo ln -s /usr/local/node-v12.18.3/bin/node node
sudo ln -s /usr/local/node-v12.18.3/bin/npm npm
sudo ln -s /usr/local/node-v12.18.3/lib/node_modules/ node_modules
node -v
v12.18.3
npm -v
6.14.6

四、安装Docker

Docker安装参考文章:Get Docker CE for Ubuntu

1、安装社区版docker-ce

# 更新 apt 包索引
sudo apt update

# 下载安装工具
sudo apt install apt-transport-https ca-certificates gnupg-agent software-properties-common

# 添加官方密钥
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add -

# 加入 apt 仓库
sudo add-apt-repository "deb [arch=amd64] https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable"

# 更新 apt 包索引
sudo apt update

# 安装 Docker-CE
sudo apt install docker-ce

# 验证版本
sudo docker version

#将非root组加入 docker 组
sudo usermod -aG docker 当前用户名

# 添加阿里云Docker镜像
sudo mkdir -p /etc/docker
sudo vi /etc/docker/daemon.json

#将下面内容添加到该文件中
{
 "registry-mirrors": ["https://obou6wyb.mirror.aliyuncs.com"]
}

# 重启 Docker
sudo systemctl daemon-reload
sudo systemctl restart docker

2、安装Docker-compose

# 下载Docker Compose二进制文件
sudo curl -L "https://github.com/docker/compose/releases/download/1.23.2/docker-compose-$(uname -s)-$(uname -m)" -o /usr/local/bin/docker-compose

# 允许其他用户执行compose相关命令
sudo chmod +x /usr/local/bin/docker-compose

# 验证版本
docker-compose -version
docker-compose version 1.23.2, build 1110ad01

从git上下载慢时,可以修改一下/etc/hosts,在网站 https://www.ipaddress.com/ 分别搜索域名github.global.ssl.fastly.netgithub.com,然后得到他们的ip地址,在hosts文件中添加:
199.232.69.194 github.global.ssl.fastly.net
140.82.114.3 github.com
service network-manager restart重启网络即可。
安装过程中,如果有长时间的等待,或者失败了,可以使用翻墙试试。

五、安装Fabric

1、克隆fabric仓库

#创建目录
sudo mkdir -p ~/go/src/github.com/hyperledger
#进入该目录
cd ~/go/src/github.com/hyperledger
#下载fabric 
sudo git clone https://github.com.cnpmjs.org/hyperledger/fabric.git

2、克隆fabric-samples测试仓库
运行~/go/src/github.com/hyperledger/fabric/scripts/bootstrap.sh,因为这个文件中需要下载一些二进制的文件,但是这些文件又存放在国外的网站上,所以下载速度非常慢,所以不能通过直接运行bootstrap.sh文件来安装 fabric 所需的工具和镜像。通过查看该文件发现该文件主要做了三件事:

  • 克隆fabric-samples测试仓库到 fabric 目录下;
  • 下载相关的二进制文件;
  • 下载相关的 docker 镜像。

接下来我们可以手动完成这三个步骤。

2.1 手动克隆fabric-samples测试仓库

cd ~/go/src/github.com/hyperledger/fabric/
#下载 fabric-samples
sudo git clone https://github.com.cnpmjs.org/hyperledger/fabric-samples.git
cd fabric-samples
sudo git checkout -b sample v1.4.0

2.2、下载相关的二进制文件

cd ~/go/src/github.com/hyperledger/fabric/fabric-samples
sudo wget -c --no-check-certificate https://github.com.cnpmjs.org/hyperledger/fabric/releases/download/v1.4.0/hyperledger-fabric-linux-amd64-1.4.0.tar.gz
sudo wget -c --no-check-certificate https://github.com.cnpmjs.org/hyperledger/fabric-ca/releases/download/v1.4.0/hyperledger-fabric-ca-linux-amd64-1.4.0.tar.gz
sudo tar -xzvf hyperledger-fabric-linux-amd64-1.4.0.tar.gz
sudo tar -xzvf hyperledger-fabric-ca-linux-amd64-1.4.0.tar.gz

#将fabric可执行文件夹加入PATH
sudo vi /etc/profile
export PATH=$PATH:$GOROOT/bin:$GOPATH/src/github.com/hyperledger/fabric/fabric-samples/bin
source /etc/profile

解压完成之后会在这个目录下面生成一个 /bin 文件夹,bin目录下面存放的都是一些生成fabric网络所需的工具。如下图所示:

2.3、下载docker镜像

cd ~/go/src/github.com/hyperledger/fabric/scripts
# 安装Fabric、Fabric-ca以及第三方Docker镜像(./bootstrap.sh <fabric> <fabric-ca> <thirdparty>)
sudo ./bootstrap.sh 1.4.0 1.4.0 0.4.14 

下载完成后,会看到终端输出已安装的 docker 镜像:

如果由于网络问题,此处通过bootstrap.sh脚本安装可能会出错,此时可进行手动安装:

# 将指定版本的Hyperledger Fabric特定于平台的二进制文件和配置文件安装到fabric-samples的bin和config目录中
sudo docker pull hyperledger/fabric-peer:1.4.0
sudo docker tag hyperledger/fabric-peer:1.4.0 hyperledger/fabric-peer:latest

sudo docker pull hyperledger/fabric-orderer:1.4.0
sudo docker tag hyperledger/fabric-orderer:1.4.0 hyperledger/fabric-orderer:latest

sudo docker pull hyperledger/fabric-ccenv:1.4.0
sudo docker tag hyperledger/fabric-ccenv:1.4.0 hyperledger/fabric-ccenv:latest

sudo docker pull hyperledger/fabric-tools:1.4.0
sudo docker tag hyperledger/fabric-tools:1.4.0 hyperledger/fabric-tools:latest

sudo docker pull hyperledger/fabric-baseos:1.4.0
sudo docker tag hyperledger/fabric-baseos:1.4.0 hyperledger/fabric-baseos:latest

# 下载Fabric第三方镜像(fabric-couchdb、fabric-kafka、fabric-zookeeper),此处以fabric-couchdb为例,其他镜像同理
sudo docker pull hyperledger/fabric-couchdb:0.4.14
sudo docker tag hyperledger/fabric-couchdb:0.4.14 hyperledger/fabric-couchdb:latest
     
# 下载Fabric CA镜像
sudo docker pull hyperledger/fabric-ca:1.4.0
sudo docker tag hyperledger/fabric-ca:1.4.0 hyperledger/fabric-ca:latest

# 查看镜像列表
sudo docker images

# 重启系统
sudo reboot

(可选)镜像的备份与恢复

# 将上述Docker镜像存储到fabric-images文件中
sudo docker save $(docker images | grep fabric | grep latest | awk '{print $1}') -o fabric-images
# 若需要多机部署,则通过下列命令将其分发到其他机器
scp fabric-images ubuntu@192.168.70.21:~
# 在192.168.70.21上加载上述镜像
docker load -o fabric-images

到目前为止,运行 fabric 网络所需的工具都已安装完成,下面进行第一次网络的运行。

六、构建第一个Fabric网络并测试

1、启动测试网络

#进入下面这个目录
cd ~/go/src/github.com/hyperledger/fabric/fabric-samples/first-network/

# 编译通过Golang开发的chaincode并启动相关的容器
sudo ./byfn.sh up
   
# sudo ./byfn.sh up -l node
   
# sudo ./byfn.sh up -o kafka
   

2、启动过程分析

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.0
DOCKER_IMAGE_VERSION=1.4.0
/home/simon/go/src/github.com/hyperledger/fabric/fabric-samples/first-network/../bin/cryptogen

##########################################################
##### Generate certificates using cryptogen tool #########
使用加密工具为org1、org2生成证书
##########################################################
+ cryptogen generate --config=./crypto-config.yaml
org1.example.com
org2.example.com
+ res=0
+ set +x

/home/simon/go/src/github.com/hyperledger/fabric/fabric-samples/first-network/../bin/configtxgen
##########################################################
#########  Generating Orderer Genesis block ##############
创建Orderer创世区块,加载配置文件configtx.yaml
##########################################################
CONSENSUS_TYPE=solo
+ '[' solo == solo ']'
+ configtxgen -profile TwoOrgsOrdererGenesis -channelID byfn-sys-channel -outputBlock ./channel-artifacts/genesis.block
2020-08-28 11:05:47.212 CST [common.tools.configtxgen] main -> INFO 001 Loading configuration
2020-08-28 11:05:47.257 CST [common.tools.configtxgen.localconfig] completeInitialization -> INFO 002 orderer type: solo
2020-08-28 11:05:47.258 CST [common.tools.configtxgen.localconfig] Load -> INFO 003 Loaded configuration: /home/simon/go/src/github.com/hyperledger/fabric/fabric-samples/first-network/configtx.yaml
2020-08-28 11:05:47.289 CST [common.tools.configtxgen.localconfig] completeInitialization -> INFO 004 orderer type: solo
2020-08-28 11:05:47.289 CST [common.tools.configtxgen.localconfig] LoadTopLevel -> INFO 005 Loaded configuration: /home/simon/go/src/github.com/hyperledger/fabric/fabric-samples/first-network/configtx.yaml
2020-08-28 11:05:47.303 CST [common.tools.configtxgen] doOutputBlock -> INFO 006 Generating genesis block
2020-08-28 11:05:47.304 CST [common.tools.configtxgen] doOutputBlock -> INFO 007 Writing genesis block
+ res=0
+ set +x

#################################################################
### Generating channel configuration transaction 'channel.tx' ###
生成通道配置事务channel.tx,Channel名为mychannel,加载配置文件configtx.yaml
#################################################################
+ configtxgen -profile TwoOrgsChannel -outputCreateChannelTx ./channel-artifacts/channel.tx -channelID mychannel
2020-08-28 11:05:47.352 CST [common.tools.configtxgen] main -> INFO 001 Loading configuration
2020-08-28 11:05:47.382 CST [common.tools.configtxgen.localconfig] Load -> INFO 002 Loaded configuration: /home/simon/go/src/github.com/hyperledger/fabric/fabric-samples/first-network/configtx.yaml
2020-08-28 11:05:47.414 CST [common.tools.configtxgen.localconfig] completeInitialization -> INFO 003 orderer type: solo
2020-08-28 11:05:47.415 CST [common.tools.configtxgen.localconfig] LoadTopLevel -> INFO 004 Loaded configuration: /home/simon/go/src/github.com/hyperledger/fabric/fabric-samples/first-network/configtx.yaml
2020-08-28 11:05:47.415 CST [common.tools.configtxgen] doOutputChannelCreateTx -> INFO 005 Generating new channel configtx
2020-08-28 11:05:47.417 CST [common.tools.configtxgen] doOutputChannelCreateTx -> INFO 006 Writing new channel tx
+ res=0
+ set +x

#################################################################
#######    Generating anchor peer update for Org1MSP   ##########
为Org1MSP生成锚节点更新
#################################################################
+ configtxgen -profile TwoOrgsChannel -outputAnchorPeersUpdate ./channel-artifacts/Org1MSPanchors.tx -channelID mychannel -asOrg Org1MSP
2020-08-28 11:05:47.475 CST [common.tools.configtxgen] main -> INFO 001 Loading configuration
2020-08-28 11:05:47.505 CST [common.tools.configtxgen.localconfig] Load -> INFO 002 Loaded configuration: /home/simon/go/src/github.com/hyperledger/fabric/fabric-samples/first-network/configtx.yaml
2020-08-28 11:05:47.539 CST [common.tools.configtxgen.localconfig] completeInitialization -> INFO 003 orderer type: solo
2020-08-28 11:05:47.540 CST [common.tools.configtxgen.localconfig] LoadTopLevel -> INFO 004 Loaded configuration: /home/simon/go/src/github.com/hyperledger/fabric/fabric-samples/first-network/configtx.yaml
2020-08-28 11:05:47.540 CST [common.tools.configtxgen] doOutputAnchorPeersUpdate -> INFO 005 Generating anchor peer update
2020-08-28 11:05:47.541 CST [common.tools.configtxgen] doOutputAnchorPeersUpdate -> INFO 006 Writing anchor peer update
+ res=0
+ set +x

#################################################################
#######    Generating anchor peer update for Org2MSP   ##########
为Org2MSP生成锚节点更新
#################################################################
+ configtxgen -profile TwoOrgsChannel -outputAnchorPeersUpdate ./channel-artifacts/Org2MSPanchors.tx -channelID mychannel -asOrg Org2MSP
2020-08-28 11:05:47.595 CST [common.tools.configtxgen] main -> INFO 001 Loading configuration
2020-08-28 11:05:47.631 CST [common.tools.configtxgen.localconfig] Load -> INFO 002 Loaded configuration: /home/simon/go/src/github.com/hyperledger/fabric/fabric-samples/first-network/configtx.yaml
2020-08-28 11:05:47.667 CST [common.tools.configtxgen.localconfig] completeInitialization -> INFO 003 orderer type: solo
2020-08-28 11:05:47.667 CST [common.tools.configtxgen.localconfig] LoadTopLevel -> INFO 004 Loaded configuration: /home/simon/go/src/github.com/hyperledger/fabric/fabric-samples/first-network/configtx.yaml
2020-08-28 11:05:47.667 CST [common.tools.configtxgen] doOutputAnchorPeersUpdate -> INFO 005 Generating anchor peer update
2020-08-28 11:05:47.667 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 peer1.org2.example.com ... done
Creating peer0.org2.example.com ... done
Creating peer1.org1.example.com ... done
Creating orderer.example.com    ... done
Creating peer0.org1.example.com ... done
Creating cli                    ... done

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

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

Channel name : mychannel
+ 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
Creating channel...
+ res=0
+ set +x
2020-08-28 03:05:52.555 UTC [channelCmd] InitCmdFactory -> INFO 001 Endorser and orderer connections initialized
2020-08-28 03:05:52.600 UTC [cli.common] readBlock -> INFO 002 Received block: 0
+ peer channel join -b mychannel.block
背书节点与排序节点连接初始化,并创建通道mychannel
===================== Channel 'mychannel' created ===================== 

Having all peers join the channel...
+ res=0
+ set +x
2020-08-28 03:05:52.710 UTC [channelCmd] InitCmdFactory -> INFO 001 Endorser and orderer connections initialized
2020-08-28 03:05:52.749 UTC [channelCmd] executeJoin -> INFO 002 Successfully submitted proposal to join channel
将所有节点加入通道mychannel,将这些信息上链mychannel.block
===================== peer0.org1 joined channel 'mychannel' ===================== 

+ peer channel join -b mychannel.block
+ res=0
+ set +x
2020-08-28 03:05:55.854 UTC [channelCmd] InitCmdFactory -> INFO 001 Endorser and orderer connections initialized
2020-08-28 03:05:55.979 UTC [channelCmd] executeJoin -> INFO 002 Successfully submitted proposal to join channel
在mychannel上为Org1MSP锚节点更新,在mychannel上为Org2MSP锚节点更新
===================== peer1.org1 joined channel 'mychannel' ===================== 

+ peer channel join -b mychannel.block
+ res=0
+ set +x
2020-08-28 03:05:59.084 UTC [channelCmd] InitCmdFactory -> INFO 001 Endorser and orderer connections initialized
2020-08-28 03:05:59.140 UTC [channelCmd] executeJoin -> INFO 002 Successfully submitted proposal to join channel
为peer0.org1安装智能合约,escc、vscc
===================== peer0.org2 joined channel 'mychannel' ===================== 

+ peer channel join -b mychannel.block
+ res=0
+ set +x
2020-08-28 03:06:02.242 UTC [channelCmd] InitCmdFactory -> INFO 001 Endorser and orderer connections initialized
2020-08-28 03:06:02.896 UTC [channelCmd] executeJoin -> INFO 002 Successfully submitted proposal to join channel
为peer0.org2安装智能合约,escc、vscc
===================== 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-08-28 03:06:06.004 UTC [channelCmd] InitCmdFactory -> INFO 001 Endorser and orderer connections initialized
2020-08-28 03:06:06.030 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-08-28 03:06:09.178 UTC [channelCmd] InitCmdFactory -> INFO 001 Endorser and orderer connections initialized
2020-08-28 03:06:09.192 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-08-28 03:06:12.320 UTC [chaincodeCmd] checkChaincodeCmdParams -> INFO 001 Using default escc
2020-08-28 03:06:12.320 UTC [chaincodeCmd] checkChaincodeCmdParams -> INFO 002 Using default vscc
2020-08-28 03:06:12.545 UTC [chaincodeCmd] install -> INFO 003 Installed remotely response:<status:200 payload:"OK" > 
智能合约安装
===================== Chaincode is installed on peer0.org1 ===================== 

+ peer chaincode install -n mycc -v 1.0 -l golang -p github.com/chaincode/chaincode_example02/go/
Install chaincode on peer0.org2...
+ res=0
+ set +x
+ 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'\'')'
2020-08-28 03:06:12.651 UTC [chaincodeCmd] checkChaincodeCmdParams -> INFO 001 Using default escc
2020-08-28 03:06:12.651 UTC [chaincodeCmd] checkChaincodeCmdParams -> INFO 002 Using default vscc
2020-08-28 03:06:12.835 UTC [chaincodeCmd] install -> INFO 003 Installed remotely response:<status:200 payload:"OK" > 
===================== Chaincode is installed on peer0.org2 ===================== 

Instantiating chaincode on peer0.org2...
+ res=0
+ set +x
2020-08-28 03:06:12.973 UTC [chaincodeCmd] checkChaincodeCmdParams -> INFO 001 Using default escc
2020-08-28 03:06:12.973 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'... ===================== 
Attempting to Query peer0.org1 ...3 secs
+ peer chaincode query -C mychannel -n mycc -c '{"Args":["query","a"]}'
+ res=0
+ set +x

100
A的余额为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:7051 --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-08-28 03:06:58.888 UTC [chaincodeCmd] chaincodeInvokeOrQuery -> INFO 001 Chaincode invoke successful. result: status:200 
调用智能合约,A向B转账10
===================== 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-08-28 03:06:58.975 UTC [chaincodeCmd] checkChaincodeCmdParams -> INFO 001 Using default escc
2020-08-28 03:06:58.975 UTC [chaincodeCmd] checkChaincodeCmdParams -> INFO 002 Using default vscc
2020-08-28 03:06:59.447 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'... ===================== 
Attempting to Query peer1.org2 ...3 secs
+ peer chaincode query -C mychannel -n mycc -c '{"Args":["query","a"]}'
+ res=0
+ set +x

90
查询A的余额,还有90
===================== Query successful on peer1.org2 on channel 'mychannel' ===================== 

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


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

如上所示,就说明我们已经安装成功了,并启动了第一个测试网络。
再来查看一下容器情况:

sudo docker ps

CONTAINER ID        IMAGE                                                                                                  COMMAND                  CREATED             STATUS              PORTS                                              NAMES
1e3fd4c272bc        dev-peer1.org2.example.com-mycc-1.0-26c2ef32838554aac4f7ad6f100aca865e87959c9a126e86d764c8d01f8346ab   "chaincode -peer.add…"   32 minutes ago      Up 32 minutes                                                          dev-peer1.org2.example.com-mycc-1.0
bb050d7f8f48        dev-peer0.org1.example.com-mycc-1.0-384f11f484b9302df90b453200cfb25174305fce8f53f4e94d45ee3b6cab0ce9   "chaincode -peer.add…"   32 minutes ago      Up 32 minutes                                                          dev-peer0.org1.example.com-mycc-1.0
016c1b16856b        dev-peer0.org2.example.com-mycc-1.0-15b571b3ce849066b7ec74497da3b27e54e0df1345daff3951b94245ce09c42b   "chaincode -peer.add…"   33 minutes ago      Up 33 minutes                                                          dev-peer0.org2.example.com-mycc-1.0
36011e108b35        hyperledger/fabric-tools:latest                                                                        "/bin/bash"              33 minutes ago      Up 33 minutes                                                          cli
8ddf97e058a4        hyperledger/fabric-peer:latest                                                                         "peer node start"        33 minutes ago      Up 33 minutes       0.0.0.0:7051->7051/tcp, 0.0.0.0:7053->7053/tcp     peer0.org1.example.com
f0a569d0cf5c        hyperledger/fabric-orderer:latest                                                                      "orderer"                33 minutes ago      Up 33 minutes       0.0.0.0:7050->7050/tcp                             orderer.example.com
21c41ae96a07        hyperledger/fabric-peer:latest                                                                         "peer node start"        33 minutes ago      Up 33 minutes       0.0.0.0:8051->7051/tcp, 0.0.0.0:8053->7053/tcp     peer1.org1.example.com
733a9bb74a5f        hyperledger/fabric-peer:latest                                                                         "peer node start"        33 minutes ago      Up 33 minutes       0.0.0.0:10051->7051/tcp, 0.0.0.0:10053->7053/tcp   peer1.org2.example.com
28644c83f022        hyperledger/fabric-peer:latest                                                                         "peer node start"        33 minutes ago      Up 33 minutes       0.0.0.0:9051->7051/tcp, 0.0.0.0:9053->7053/tcp     peer0.org2.example.com

从上面我们可以了解到,一个节点分配一个容器,cli为一个独立容器,一个智能合约一个容器,Orderer节点为一个独立的容器。

3、关闭网络

#停止first-network网络中所有的容器,删除crypto材料和4个artifacts(genesis.block、mychannel.block、Org1MSPanchor.tx、Org2MSPanchor.tx)以及chaincode镜像
sudo ./byfn.sh down

到这里,就完成了 Fabric 的安装和第一次运行。

七、附安装完后的版本信息

fabric 1.4.0
go version go1.14 linux/amd64
git version 2.25.1
docker-ce 19.03.12
docker-compose version 1.23.2, build 1110ad01
node v12.18.3
npm 6.14.6

参考:
https://www.jianshu.com/p/be9466370cc4
https://www.chaindesk.cn/witbook/11/98

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
  • 序言:七十年代末,一起剥皮案震惊了整个滨河市,随后出现的几起案子,更是在滨河造成了极大的恐慌,老刑警刘岩,带你破解...
    沈念sama阅读 159,458评论 4 363
  • 序言:滨河连续发生了三起死亡事件,死亡现场离奇诡异,居然都是意外死亡,警方通过查阅死者的电脑和手机,发现死者居然都...
    沈念sama阅读 67,454评论 1 294
  • 文/潘晓璐 我一进店门,熙熙楼的掌柜王于贵愁眉苦脸地迎上来,“玉大人,你说我怎么就摊上这事。” “怎么了?”我有些...
    开封第一讲书人阅读 109,171评论 0 243
  • 文/不坏的土叔 我叫张陵,是天一观的道长。 经常有香客问我,道长,这世上最难降的妖魔是什么? 我笑而不...
    开封第一讲书人阅读 44,062评论 0 207
  • 正文 为了忘掉前任,我火速办了婚礼,结果婚礼上,老公的妹妹穿的比我还像新娘。我一直安慰自己,他们只是感情好,可当我...
    茶点故事阅读 52,440评论 3 287
  • 文/花漫 我一把揭开白布。 她就那样静静地躺着,像睡着了一般。 火红的嫁衣衬着肌肤如雪。 梳的纹丝不乱的头发上,一...
    开封第一讲书人阅读 40,661评论 1 219
  • 那天,我揣着相机与录音,去河边找鬼。 笑死,一个胖子当着我的面吹牛,可吹牛的内容都是我干的。 我是一名探鬼主播,决...
    沈念sama阅读 31,906评论 2 313
  • 文/苍兰香墨 我猛地睁开眼,长吁一口气:“原来是场噩梦啊……” “哼!你这毒妇竟也来了?” 一声冷哼从身侧响起,我...
    开封第一讲书人阅读 30,609评论 0 200
  • 序言:老挝万荣一对情侣失踪,失踪者是张志新(化名)和其女友刘颖,没想到半个月后,有当地人在树林里发现了一具尸体,经...
    沈念sama阅读 34,379评论 1 246
  • 正文 独居荒郊野岭守林人离奇死亡,尸身上长有42处带血的脓包…… 初始之章·张勋 以下内容为张勋视角 年9月15日...
    茶点故事阅读 30,600评论 2 246
  • 正文 我和宋清朗相恋三年,在试婚纱的时候发现自己被绿了。 大学时的朋友给我发了我未婚夫和他白月光在一起吃饭的照片。...
    茶点故事阅读 32,085评论 1 261
  • 序言:一个原本活蹦乱跳的男人离奇死亡,死状恐怖,灵堂内的尸体忽然破棺而出,到底是诈尸还是另有隐情,我是刑警宁泽,带...
    沈念sama阅读 28,409评论 2 254
  • 正文 年R本政府宣布,位于F岛的核电站,受9级特大地震影响,放射性物质发生泄漏。R本人自食恶果不足惜,却给世界环境...
    茶点故事阅读 33,072评论 3 237
  • 文/蒙蒙 一、第九天 我趴在偏房一处隐蔽的房顶上张望。 院中可真热闹,春花似锦、人声如沸。这庄子的主人今日做“春日...
    开封第一讲书人阅读 26,088评论 0 8
  • 文/苍兰香墨 我抬头看了看天上的太阳。三九已至,却和暖如春,着一层夹袄步出监牢的瞬间,已是汗流浃背。 一阵脚步声响...
    开封第一讲书人阅读 26,860评论 0 195
  • 我被黑心中介骗来泰国打工, 没想到刚下飞机就差点儿被人妖公主榨干…… 1. 我叫王不留,地道东北人。 一个月前我还...
    沈念sama阅读 35,704评论 2 276
  • 正文 我出身青楼,却偏偏与公主长得像,于是被迫代替她去往敌国和亲。 传闻我的和亲对象是个残疾皇子,可洞房花烛夜当晚...
    茶点故事阅读 35,608评论 2 270