超级详细Hyperledger Fabric1.4.4 环境搭建部署

超详细的Hyperledger Fabric1.4.4 环境搭建部署

第一部分:Fabric1.4.4 环境搭建部署
一、系统版本:
//系统版本

[root@ecs-344386 ~]# cat /etc/redhat-release
CentOS Linux release 7.9.2009 (Core)

//内核版本
[root@ecs-344386 ~]# cat /proc/version
Linux version 3.10.0-1160.53.1.el7.x86_64 (mockbuild@kbuilder.bsys.centos.org) (gcc version 4.8.5 20150623 (Red Hat 4.8.5-44) (GCC) ) #1 SMP Fri Jan 14 13:59:45 UTC 2022

//操作系统位数
[root@ecs-344386 ~]# uname -r
3.10.0-1160.53.1.el7.x86_64

二、安装docker
https://www.cnblogs.com/Horsonce/p/16798391.html

三、安装docker-compose
sudo curl -L https://github.com/docker/compose/releases/download/1.27.3/docker-compose-'uname -s'-'uname -m' -o /usr/local/bin/docker-compose

//如果慢的话使用以下网址
curl -L "https://get.daocloud.io/docker/compose/releases/download/1.27.3/docker-compose-$(uname -s)-$(uname -m)" -o /usr/local/bin/docker-compose

-rw-r--r-- 1 root root 12219168 10月 7 20:59 docker-compose

//下载完成后,将文件更改为可执行权限:
sudo chmod +x /usr/local/bin/docker-compose
chmod +x就是赋予用户文件的执行权限
//下载包   拉到/usr/local/bin下
docker-compose -v

[root@iZbp11g4dg2q98o4v5eunvZ ~]# docker-compose -v
docker-compose version 1.27.3, build 4092ae5d

四、安装go环境
根据电脑版本,下载合适GoSDK,下载地址:https://golang.google.cn/dl/

下载安装包go1.15.14.linux-amd64.tar.gz,拉去linux系统/usr/local

cd /usr/local
//解压,生成go文件
wget https://golang.google.cn/dl/go1.15.14.linux-amd64.tar.gz
100%[====================================>] 121,105,361 1.30MB/s 用时 85s
2022-10-07 21:51:07 (1.36 MB/s) - 已保存 “go1.15.14.linux-amd64.tar.gz” [121105361/121105361])

tar -zxvf go1.15.14.linux-amd64.tar.gz
//rm -rf go1.15.14.linux-amd64.tar.gz

//创建文件夹子/usr/local/gopath中,用来作为GOPATH
//设置GOPATH、GOROOT、PATH,该目录下创建三个文件夹
mkdir gopath
cd gopath  
mkdir src bin pkg

vim /etc/profile //打开文件夹,a插入模式,//注意:gopath不用添加到PATH
//末尾添加,注意等号别加空格及/:
export GOROOT=/usr/local/go
export PATH=$PATH:$GOROOT/bin
export GOPATH=/usr/local/gopath

//执行配置文件
source /etc/profile
//查看版本号
go version
go version go1.15.14 linux/amd64

//查看go环境
go env
//换国内代理,不然后面Fabric运行会报错
go env -w GOPROXY=https://goproxy.cn
export GOPROXY=https://goproxy.cn

五、安装工具包(git、curl、gcc、pip)
yum install -y git
[root@ecs-344386 local]# git version
git version 1.8.3.1

yum install -y curl
[root@ecs-344386 local]# curl --version
curl 7.29.0 (x86_64-redhat-linux-gnu) libcurl/7.29.0 NSS/3.53.1 zlib/1.2.7 libidn/1.28 libssh2/1.8.0

yum install -y gcc
[root@ecs-344386 local]# gcc --version
gcc (GCC) 4.8.5 20150623 (Red Hat 4.8.5-44)

yum -y install epel-release
sudo yum -y install python-pip
pip --version #查看pip版本
[root@ecs-344386 local]# pip --version
pip 8.1.2 from /usr/lib/python2.7/site-packages (python 2.7)
#若要更新pip,可以使用命令pip install --upgrade pip

六、安装node

在 /usr/local目录下
# 第一步:下载

wget https://nodejs.org/dist/v9.9.0/node-v9.9.0-linux-x64.tar.gz
# 第二步:
tar -xzvf node-v9.9.0-linux-x64.tar.gz
mv node-v9.9.0-linux-x64 node
# 第三步:建立软连接,变为全局
ln -s /usr/local/node/bin/node /usr/bin/node
ln -s /usr/local/node/bin/npm /usr/bin/npm
ln -s /usr/local/node/bin/npx /usr/bin/npx
# 第四步:查看版本
node -v
npm -v
npx -v
# 第五步:修改环境变量
vim /etc/profile
# node
export NODE_HOME=/usr/local/node
export PATH=$NODE_HOME/bin:$PATH
export NODE_PATH=$NODE_HOME/lib/node_modules:$PATH

# 生效node
source /etc/profile

注意:如果这里出现问题,请关闭防火墙

七、安装源码

第一种方法:使用命令执行:

进入/usr/local/gopath/src/github.com/hyperledger/fabric/scripts

输入:./bootstrap.sh

注意:因为访问国外资源,所以很慢,建议使用手动安装方式,这样可以了解自己执行每个命令是什么意思

 

第二种方法:手动创建

(1)创建文件夹并拉取源码

//创建文件夹子usr/local/gopath中,用来作为GOPATH

echo $GOPATH # 打印出自己本地的GOPATH
/usr/local/gopath
mkdir -p $GOPATH/src/github.com/hyperledger
cd $GOPATH/src/github.com/hyperledger

#当前路径:/root/go/src/github.com/hyperledger
[root@localhost hyperledger]# git clone -b v1.4.4 https://github.com/hyperledger/fabric
[root@localhost hyperledger]# git clone -b v1.4.4 https://github.com/hyperledger/fabric-samples
#【版本切换】若不放心版本,可分别进入这两个文件夹内再手动切换下版本
[root@localhost fabric]# git checkout -b v1.4.4
[root@localhost fabric-samples]# git checkout -b v1.4.4

#【检测】主要还是对检查版本是否为 1.4.4 的,若能如下显示则表示正常
[root@localhost fabric]# git branch
* v1.4.4
[root@localhost fabric-samples]# git branch
* v1.4.4

注意:如果上面方法安装不成功,

# 使用镜像会更快(我使用的方法):拉取fabric包
git clone https://gitee.com/mirrors/hyperledger-fabric.git

mv hyperledger-fabric/ fabric  

[root@iZbp11g4dg2q98o4v5eunvZ fabric]# git checkout -b v1.4.4
切换到一个新分支 'v1.4.4'

[root@iZbp11g4dg2q98o4v5eunvZ scripts]# git branch
main
* v1.4.4

 

拉取源码

# 第一步:fabric-samples 源码克隆到当前目录下,并切换到指定版本:

进入:/usr/local/gopath/src/github.com/hyperledger/fabric/scripts

git clone https://gitee.com/Alikx/fabric-samples.git

cd fabric-samples
#更换版本号
git checkout v1.4.4

# 第二步:下载可执行二进制文件:压缩包内有 bin 文件夹,将两个 bin 文件夹内的二进制文件汇总在一个 bin 文件夹内。 最后将 bin 和 config 文件夹复制到 fabric-samples 文件夹内。

然后下载两个包:

fabric下载链接为:https://github.com/hyperledger/fabric/releases/download/v1.4.4/hyperledger-fabric-linux-amd64-1.4.4.tar.gz
fabric-ca的下载链接为:https://github.com/hyperledger/fabric-ca/releases/download/v1.4.4/hyperledger-fabric-ca-linux-amd64-1.4.4.tar.gz

使用命令下载:

wget https://github.com/hyperledger/fabric/releases/download/v1.4.4/hyperledger-fabric-linux-amd64-1.4.4.tar.gz

wget https://github.com/hyperledger/fabric-ca/releases/download/v1.4.4/hyperledger-fabric-ca-linux-amd64-1.4.4.tar.gz

解压 :

tar -xzvf hyperledger-fabric-linux-amd64-1.4.4.tar.gz

tar -xzvf hyperledger-fabric-ca-linux-amd64-1.4.4.tar.gz

# 第三步:下载 Docker镜像
# 执行 bootstrap.sh 脚本:

./bootstrap.sh 1.4.4 1.4.4 0.4.18

===> List out hyperledger docker images
hyperledger/fabric-ca 1.4 62a60c5459ae 2 years ago 150MB
hyperledger/fabric-ca 1.4.4 62a60c5459ae 2 years ago 150MB
hyperledger/fabric-ca latest 62a60c5459ae 2 years ago 150MB
hyperledger/fabric-tools 1.4 7552e1968c0b 2 years ago 1.49GB
hyperledger/fabric-tools 1.4.4 7552e1968c0b 2 years ago 1.49GB
hyperledger/fabric-tools latest 7552e1968c0b 2 years ago 1.49GB
hyperledger/fabric-ccenv 1.4 ca4780293e4c 2 years ago 1.37GB
hyperledger/fabric-ccenv 1.4.4 ca4780293e4c 2 years ago 1.37GB
hyperledger/fabric-ccenv latest ca4780293e4c 2 years ago 1.37GB
hyperledger/fabric-orderer 1.4 dbc9f65443aa 2 years ago 120MB
hyperledger/fabric-orderer 1.4.4 dbc9f65443aa 2 years ago 120MB
hyperledger/fabric-orderer latest dbc9f65443aa 2 years ago 120MB
hyperledger/fabric-peer 1.4 9756aed98c6b 2 years ago 128MB
hyperledger/fabric-peer 1.4.4 9756aed98c6b 2 years ago 128MB
hyperledger/fabric-peer latest 9756aed98c6b 2 years ago 128MB

测试网络

#执行
cd first-network
#启动网络
./byfn.sh up

[root@iZbp11g4dg2q98o4v5eunvZ first-network]# ./byfn.sh up
Starting for channel 'mychannel' with CLI timeout of '10' seconds and CLI delay of '3' seconds
Continue? [Y/n] y
proceeding ...
WARNING: IPv4 forwarding is disabled. Networking will not work.
LOCAL_VERSION=1.4.4
DOCKER_IMAGE_VERSION=1.4.4
/usr/local/gopath/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
/usr/local/gopath/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
2022-10-26 11:38:16.690 CST [common.tools.configtxgen] main -> INFO 001 Loading configuration
2022-10-26 11:38:16.802 CST [common.tools.configtxgen.localconfig] completeInitialization -> INFO 002 orderer type: solo
2022-10-26 11:38:16.802 CST [common.tools.configtxgen.localconfig] Load -> INFO 003 Loaded configuration: /usr/local/gopath/src/github.com/hyperledger/fabric/scripts/fabric-samples/first-network/configtx.yaml
2022-10-26 11:38:16.918 CST [common.tools.configtxgen.localconfig] completeInitialization -> INFO 004 orderer type: solo
2022-10-26 11:38:16.918 CST [common.tools.configtxgen.localconfig] LoadTopLevel -> INFO 005 Loaded configuration: /usr/local/gopath/src/github.com/hyperledger/fabric/scripts/fabric-samples/first-network/configtx.yaml
2022-10-26 11:38:16.920 CST [common.tools.configtxgen] doOutputBlock -> INFO 006 Generating genesis block
2022-10-26 11:38:16.920 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
2022-10-26 11:38:16.953 CST [common.tools.configtxgen] main -> INFO 001 Loading configuration
2022-10-26 11:38:17.067 CST [common.tools.configtxgen.localconfig] Load -> INFO 002 Loaded configuration: /usr/local/gopath/src/github.com/hyperledger/fabric/scripts/fabric-samples/first-network/configtx.yaml
2022-10-26 11:38:17.181 CST [common.tools.configtxgen.localconfig] completeInitialization -> INFO 003 orderer type: solo
2022-10-26 11:38:17.181 CST [common.tools.configtxgen.localconfig] LoadTopLevel -> INFO 004 Loaded configuration: /usr/local/gopath/src/github.com/hyperledger/fabric/scripts/fabric-samples/first-network/configtx.yaml
2022-10-26 11:38:17.181 CST [common.tools.configtxgen] doOutputChannelCreateTx -> INFO 005 Generating new channel configtx
2022-10-26 11:38:17.183 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
2022-10-26 11:38:17.217 CST [common.tools.configtxgen] main -> INFO 001 Loading configuration
2022-10-26 11:38:17.336 CST [common.tools.configtxgen.localconfig] Load -> INFO 002 Loaded configuration: /usr/local/gopath/src/github.com/hyperledger/fabric/scripts/fabric-samples/first-network/configtx.yaml
2022-10-26 11:38:17.458 CST [common.tools.configtxgen.localconfig] completeInitialization -> INFO 003 orderer type: solo
2022-10-26 11:38:17.458 CST [common.tools.configtxgen.localconfig] LoadTopLevel -> INFO 004 Loaded configuration: /usr/local/gopath/src/github.com/hyperledger/fabric/scripts/fabric-samples/first-network/configtx.yaml
2022-10-26 11:38:17.458 CST [common.tools.configtxgen] doOutputAnchorPeersUpdate -> INFO 005 Generating anchor peer update
2022-10-26 11:38:17.458 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
2022-10-26 11:38:17.492 CST [common.tools.configtxgen] main -> INFO 001 Loading configuration
2022-10-26 11:38:17.616 CST [common.tools.configtxgen.localconfig] Load -> INFO 002 Loaded configuration: /usr/local/gopath/src/github.com/hyperledger/fabric/scripts/fabric-samples/first-network/configtx.yaml
2022-10-26 11:38:17.732 CST [common.tools.configtxgen.localconfig] completeInitialization -> INFO 003 orderer type: solo
2022-10-26 11:38:17.732 CST [common.tools.configtxgen.localconfig] LoadTopLevel -> INFO 004 Loaded configuration: /usr/local/gopath/src/github.com/hyperledger/fabric/scripts/fabric-samples/first-network/configtx.yaml
2022-10-26 11:38:17.732 CST [common.tools.configtxgen] doOutputAnchorPeersUpdate -> INFO 005 Generating anchor peer update
2022-10-26 11:38:17.732 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 peer0.org1.example.com ... done
Creating orderer.example.com    ... done
Creating peer0.org2.example.com ... done
Creating peer1.org1.example.com ... done
Creating peer1.org2.example.com ... done
Creating cli                    ... done
CONTAINER ID   IMAGE                               COMMAND             CREATED                  STATUS                  PORTS                                           NAMES
73a8ac0ed27b   hyperledger/fabric-tools:latest     "/bin/bash"         Less than a second ago   Up Less than a second                                                   cli
2dc2cadd79ff   hyperledger/fabric-peer:latest      "peer node start"   2 seconds ago            Up Less than a second   0.0.0.0:10051->10051/tcp, :::10051->10051/tcp   peer1.org2.example.com
ca633e433f07   hyperledger/fabric-peer:latest      "peer node start"   2 seconds ago            Up Less than a second   0.0.0.0:8051->8051/tcp, :::8051->8051/tcp       peer1.org1.example.com
a00b1bb8e844   hyperledger/fabric-peer:latest      "peer node start"   2 seconds ago            Up Less than a second   0.0.0.0:9051->9051/tcp, :::9051->9051/tcp       peer0.org2.example.com
94a5ec1bdc7a   hyperledger/fabric-peer:latest      "peer node start"   2 seconds ago            Up Less than a second   0.0.0.0:7051->7051/tcp, :::7051->7051/tcp       peer0.org1.example.com
42085d71453f   hyperledger/fabric-orderer:latest   "orderer"           2 seconds ago            Up Less than a second   0.0.0.0:7050->7050/tcp, :::7050->7050/tcp       orderer.example.com

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

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

+ 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
Channel name : mychannel
Creating channel...
+ res=0
+ set +x
2022-10-26 03:38:20.836 UTC [channelCmd] InitCmdFactory -> INFO 001 Endorser and orderer connections initialized
2022-10-26 03:38:20.866 UTC [cli.common] readBlock -> INFO 002 Received block: 0
===================== Channel 'mychannel' created ===================== 

Having all peers join the channel...
+ peer channel join -b mychannel.block
+ res=0
+ set +x
2022-10-26 03:38:20.929 UTC [channelCmd] InitCmdFactory -> INFO 001 Endorser and orderer connections initialized
2022-10-26 03:38:21.000 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
2022-10-26 03:38:24.062 UTC [channelCmd] InitCmdFactory -> INFO 001 Endorser and orderer connections initialized
2022-10-26 03:38:24.129 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
2022-10-26 03:38:27.190 UTC [channelCmd] InitCmdFactory -> INFO 001 Endorser and orderer connections initialized
2022-10-26 03:38:27.257 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
2022-10-26 03:38:30.320 UTC [channelCmd] InitCmdFactory -> INFO 001 Endorser and orderer connections initialized
2022-10-26 03:38:30.385 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
2022-10-26 03:38:33.448 UTC [channelCmd] InitCmdFactory -> INFO 001 Endorser and orderer connections initialized
2022-10-26 03:38:33.457 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
2022-10-26 03:38:36.519 UTC [channelCmd] InitCmdFactory -> INFO 001 Endorser and orderer connections initialized
2022-10-26 03:38:36.529 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
2022-10-26 03:38:39.593 UTC [chaincodeCmd] checkChaincodeCmdParams -> INFO 001 Using default escc
2022-10-26 03:38:39.594 UTC [chaincodeCmd] checkChaincodeCmdParams -> INFO 002 Using default vscc
2022-10-26 03:38:39.837 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
2022-10-26 03:38:39.898 UTC [chaincodeCmd] checkChaincodeCmdParams -> INFO 001 Using default escc
2022-10-26 03:38:39.898 UTC [chaincodeCmd] checkChaincodeCmdParams -> INFO 002 Using default vscc
2022-10-26 03:38:40.144 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
2022-10-26 03:38:40.214 UTC [chaincodeCmd] checkChaincodeCmdParams -> INFO 001 Using default escc
2022-10-26 03:38:40.214 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
2022-10-26 03:39:27.109 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
2022-10-26 03:39:27.169 UTC [chaincodeCmd] checkChaincodeCmdParams -> INFO 001 Using default escc
2022-10-26 03:39:27.169 UTC [chaincodeCmd] checkChaincodeCmdParams -> INFO 002 Using default vscc
2022-10-26 03:39:27.401 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 =========== 


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

第二部分:使用情况

#查询操作

#首先进入 ctl环境中
docker exec -it ctl  bash
export CHANNEL_NAME=mychannel
root@b02a5a64600d:/opt/gopath/src/github.com/hyperledger/fabric/peer# peer chaincode query -C $CHANNEL_NAME -n mycc -c '{"Args":["query","b"]}'
200

#查看当前通道信息

root@73a8ac0ed27b:/opt/gopath/src/github.com/hyperledger/fabric/peer# peer channel getinfo -c mychannel
2022-10-26 05:37:00.240 UTC [channelCmd] InitCmdFactory -> INFO 001 Endorser and orderer connections initialized
Blockchain info: {"height":5,"currentBlockHash":"grr78hVDtpd2VqI+jtkTxzOTpKbLqrL8mo1CvpppYe8=","previousBlockHash":"SCUOH+U9i8IrsGgXTeQacVNdmEoGagixcklQTpTU6wQ="}

 

#查看通道最新区块信息

root@73a8ac0ed27b:/opt/gopath/src/github.com/hyperledger/fabric/peer# peer channel fetch newest -c mychannel -o orderer.example.com
2022-10-26 05:39:25.958 UTC [channelCmd] InitCmdFactory -> INFO 001 Endorser and orderer connections initialized
2022-10-26 05:39:25.960 UTC [cli.common] readBlock -> INFO 002 Received block: 4

 

#查看已经实例化的链码

root@73a8ac0ed27b:/opt/gopath/src/github.com/hyperledger/fabric/peer# peer chaincode list --instantiated -C mychannel
Get instantiated chaincodes on channel mychannel:
Name: mycc, Version: 1.0, Path: github.com/chaincode/chaincode_example02/go/, Escc: escc, Vscc: vscc

 

#安装完成后 再次查看已经安装的链码列表

root@73a8ac0ed27b:/opt/gopath/src/github.com/hyperledger/fabric/peer# peer chaincode list --installed
Get installed chaincodes on peer:
Name: mycc, Version: 1.0, Path: github.com/chaincode/chaincode_example02/go/, Id: 333a19b11063d0ade7be691f9f22c04ad369baba15660f7ae9511fd1a6488209

 

posted on 2022-10-26 11:43  忆华灯纵博  阅读(663)  评论(0编辑  收藏  举报