VMware 中 Centos7 安装 Hyperledge Fabric v2.4.4 测试网络

VMware 中 Centos7 安装 Hyperledge Fabric v2.4.4 测试网络,第1张

0、安装环境

虚拟机:VMware Workstation 15 Pro

虚拟机安装的 *** 作系统:Centos7

前提条件:

(1)安装Git 参考 Centos7 安装 git_瘦身小蚂蚁的博客-CSDN博客_centos7 安装git

(2)安装Go 1.18.2+  参考 Centos7 安装 Go_瘦身小蚂蚁的博客-CSDN博客_centos7安装go

(3)安装Docker 参考 Centos7 安装 Docker_瘦身小蚂蚁的博客-CSDN博客

(4)安装Docker-Compose 参考 Centos7 安装 Docker Compose_瘦身小蚂蚁的博客-CSDN博客

(5)安装Nodejs 16.17.0  参考 安装 Nodejs (CentOS7 与 Windows)_瘦身小蚂蚁的博客-CSDN博客

(6)安装JQ命令 参考 Centos7 安装完需要安装相关命令_瘦身小蚂蚁的博客-CSDN博客_centos7 安装命令

1、下载Fabric(版本2.4.4)

创建并进入Fabric目录

mkdir -p $GOPATH/src/github.com/hyperledger # 创建下载目录

cd $GOPATH/src/github.com/hyperledger #进入目录

[root@localhost ~]# mkdir -p $GOPATH/src/github.com/hyperledger  # 创建下载目录
[root@localhost ~]# cd $GOPATH/src/github.com/hyperledger    #进入目录

官网提供的下载命令:

curl -sSLO https://raw.githubusercontent.com/hyperledger/fabric/main/scripts/install-fabric.sh && chmod +x install-fabric.sh

若下载命令正常执行,忽略下面步骤。若不能正常执行,则执行下面步骤:

链接地址有时并不能有效的访问,即便能够访问,在执行命令时也会出现长时间没有反应,最终报错的问题。因此可以分析一下脚本,直接下载脚本中的文件。如脚本访问不了,可参见 HyperlegerFabric2.4.4安装下载示例时使用的脚本install-fabric.sh-Dapp文档类资源-CSDN下载

将脚本文件install-fabric.sh下载,在下面第(4)步使用。

(0)使用install-fabric.sh脚本下载组件

可以通过install-fabric.sh脚本指定下载的组件

docker    使用docker下载Fabric镜像(以下第(4)步使用)

podman  使用podman下载Fabric镜像

binary     下载Fabric二进制文件

samples 下载fabric-samples示例

示例:

./install-fabric.sh docker samples

./install-fabric.sh d s

(1)下载fabric-sample

使用git下载fabric-sample

git clone -b main https://github.com/hyperledger/fabric-samples.git 

[root@localhost hyperledger]# git clone -b main https://github.com/hyperledger/fabric-samples.git 
Cloning into 'fabric-samples'...
remote: Enumerating objects: 10734, done.
remote: Counting objects: 100% (75/75), done.
remote: Compressing objects: 100% (64/64), done.
remote: Total 10734 (delta 18), reused 52 (delta 9), pack-reused 10659
Receiving objects: 100% (10734/10734), 19.14 MiB | 992.00 KiB/s, done.
Resolving deltas: 100% (5769/5769), done.

若多次执行报错后,可直接在windows中下载,然后上传到centos7对应的目录下。下载地址:GitHub - hyperledger/fabric-samples

(2)下载并解压fabric二进制文件(版本2.4.4) 下载fabric二进制文件

使用wget报错,直接在windows下载,然后上传到centos7中解压。下载地址为:https://github.com/hyperledger/fabric/releases/download/v2.4.4/hyperledger-fabric-linux-amd64-2.4.4.tar.gz

若github下载不了,可参见: 下载Fabric2.4.4二进制文件-Dapp文档类资源-CSDN下载

解压fabric二进制文件

将文件解压到fabric-sample目录中

tar -zxvf hyperledger-fabric-linux-amd64-2.4.4.tar.gz -C fabric-samples/

[root@localhost hyperledger]# tar -zxvf hyperledger-fabric-linux-amd64-2.4.4.tar.gz -C fabric-samples/
bin/
bin/peer
bin/configtxlator
bin/configtxgen
bin/ledgerutil
bin/ccaas_builder/
bin/ccaas_builder/bin/
bin/ccaas_builder/bin/build
bin/ccaas_builder/bin/release
bin/ccaas_builder/bin/detect
bin/orderer
bin/cryptogen
bin/discover
bin/osnadmin
config/
config/core.yaml
config/orderer.yaml
config/configtx.yaml
(3)下载并解压fabric-ca二进制文件(版本1.5.5) 下载fabric-ca二进制文件

使用wget报错,直接在windows下载,然后上传到centos7中解压。下载地址为:https://github.com/hyperledger/fabric-ca/releases/download/v1.5.5/hyperledger-fabric-ca-linux-amd64-1.5.5.tar.gz

若github下载不了,可参见: 下载Fabric2.4.4二进制文件fabric-ca-Dapp文档类资源-CSDN下载

解压fabric-ca二进制文件

将文件解压到fabric-sample目录中

tar -zxvf hyperledger-fabric-ca-linux-amd64-1.5.5.tar.gz -C fabric-samples/

[root@localhost hyperledger]# tar -zxvf hyperledger-fabric-ca-linux-amd64-1.5.5.tar.gz -C fabric-samples/
bin/
bin/fabric-ca-client
bin/fabric-ca-server

前3步都配置完成后,目录结构如下图所示:

查看 fabric-sample/bin目录: 

 ​

查看 fabric-sample/config 目录:

 ​

(4)下载docker镜像 1.4.1、执行脚本下载docker镜像

通过执行install-fabric.sh脚本(参数为“docker”),下载docker镜像,若有下载失败的镜像,执行步骤1.4.2,否则执行步骤1.4.4:

./install-fabric.sh docker

[root@localhost hyperledger]# ./install-fabric.sh docker

Pull Hyperledger Fabric docker images

FABRIC_IMAGES: peer orderer ccenv tools baseos
===> Pulling fabric Images
====>  hyperledger/fabric-peer:2.4.4
2.4.4: Pulling from hyperledger/fabric-peer
2408cc74d12b: Already exists 
6a3ced7e221e: Pull complete 
b9ff1df31cf9: Pull complete 
78b77eac19b1: Pull complete 
048204d9f4c2: Pull complete 
f4fcec0334ed: Pull complete 
cb845d51199e: Pull complete 
Digest: sha256:cb670c569d442dd42bab9d7fdb8cca8ae6e07326187e671d3d8041520fceac41
Status: Downloaded newer image for hyperledger/fabric-peer:2.4.4
docker.io/hyperledger/fabric-peer:2.4.4
====>  hyperledger/fabric-orderer:2.4.4
Error response from daemon: Get "https://registry-1.docker.io/v2/hyperledger/fabric-orderer/manifests/sha256:2a12c6789745c099dc91e7c10c35e6bee7dbfd7b80009fa4c876a7a9cd342bb5": net/http: TLS handshake timeout
Error response from daemon: No such image: hyperledger/fabric-orderer:2.4.4
Error response from daemon: No such image: hyperledger/fabric-orderer:2.4.4
====>  hyperledger/fabric-ccenv:2.4.4
2.4.4: Pulling from hyperledger/fabric-ccenv
2408cc74d12b: Already exists 
ea60b727a1ce: Already exists 
30c4a7721957: Already exists 
4a5a11f84e29: Already exists 
7f0c29549d1e: Already exists 
1d4cfebdfd72: Pull complete 
2310b28b5cf4: Pull complete 
abc5b52e1631: Pull complete 
cab5a0b0a76d: Pull complete 
Digest: sha256:39f4df6cb59f596f0511b13ad9a12e0b4e805012194b9406054a14a3c9b30668
Status: Downloaded newer image for hyperledger/fabric-ccenv:2.4.4
docker.io/hyperledger/fabric-ccenv:2.4.4
====>  hyperledger/fabric-tools:2.4.4
2.4.4: Pulling from hyperledger/fabric-tools
Digest: sha256:fbb12c6e1edc760188cb9057ad68abfa3192a4a6e832dfd0b1ddfa284d28f517
Status: Image is up to date for hyperledger/fabric-tools:2.4.4
docker.io/hyperledger/fabric-tools:2.4.4
====>  hyperledger/fabric-baseos:2.4.4
Error response from daemon: Get "https://registry-1.docker.io/v2/hyperledger/fabric-baseos/manifests/sha256:7d57d726fecf14b4cbe15ce16fcc8c6890d6d0af9337210aa597e4f0ea65485b": net/http: TLS handshake timeout
Error response from daemon: No such image: hyperledger/fabric-baseos:2.4.4
Error response from daemon: No such image: hyperledger/fabric-baseos:2.4.4
===> Pulling fabric ca Image
====>  hyperledger/fabric-ca:1.5.5
1.5.5: Pulling from hyperledger/fabric-ca
Digest: sha256:f93cd9f32702c3a6b9cb305d75bed5edd884cae0674374fd7c26467bf6a0ed9b
Status: Image is up to date for hyperledger/fabric-ca:1.5.5
docker.io/hyperledger/fabric-ca:1.5.5
===> List out hyperledger images
hyperledger/fabric-ca      1.5       93f19fa873cb   5 weeks ago   76.5MB
hyperledger/fabric-ca      1.5.5     93f19fa873cb   5 weeks ago   76.5MB
hyperledger/fabric-ca      latest    93f19fa873cb   5 weeks ago   76.5MB
hyperledger/fabric-tools   2.4       d2f5f013cf70   8 weeks ago   489MB
hyperledger/fabric-tools   2.4.4     d2f5f013cf70   8 weeks ago   489MB
hyperledger/fabric-tools   latest    d2f5f013cf70   8 weeks ago   489MB
hyperledger/fabric-peer    2.4       080114f6c98f   8 weeks ago   64.2MB
hyperledger/fabric-peer    2.4.4     080114f6c98f   8 weeks ago   64.2MB
hyperledger/fabric-peer    latest    080114f6c98f   8 weeks ago   64.2MB
hyperledger/fabric-ccenv   2.4       b01eeb054e4c   8 weeks ago   520MB
hyperledger/fabric-ccenv   2.4.4     b01eeb054e4c   8 weeks ago   520MB
hyperledger/fabric-ccenv   latest    b01eeb054e4c   8 weeks ago   520MB
1.4.2、单独下载失败的镜像

由于网络原因,以上有2个docker镜像下载失败,hyperledger/fabric-orderer:2.4.4 与 hyperledger/fabric-baseos:2.4.4,多次执行命令,仍然下载失败,可单独下载失败的镜像,如果仍然失败,多执行几次:(注:每次下载时失败的镜像不同,查看下载失败的镜像使用docker命令单独下载。)

docker pull hyperledger/fabric-orderer:2.4.4

docker pull hyperledger/fabric-baseos:2.4.4

# 失败
[root@localhost hyperledger]# docker pull hyperledger/fabric-orderer:2.4.4
Error response from daemon: Head "https://registry-1.docker.io/v2/hyperledger/fabric-orderer/manifests/2.4.4": Get "https://auth.docker.io/token?scope=repository%3Ahyperledger%2Ffabric-orderer%3Apull&service=registry.docker.io": net/http: TLS handshake timeout

# 失败
[root@localhost hyperledger]# docker pull hyperledger/fabric-orderer:2.4.4
Error response from daemon: Get "https://registry-1.docker.io/v2/": net/http: TLS handshake timeout

# 成功
[root@localhost hyperledger]# docker pull hyperledger/fabric-orderer:2.4.4
2.4.4: Pulling from hyperledger/fabric-orderer
2408cc74d12b: Already exists 
6a3ced7e221e: Already exists 
b9a3d5e52036: Pull complete 
02f61468e2f2: Pull complete 
7e7e888d9eab: Pull complete 
b3ea10b79973: Pull complete 
f7cb240941e7: Pull complete 
Digest: sha256:2a12c6789745c099dc91e7c10c35e6bee7dbfd7b80009fa4c876a7a9cd342bb5
Status: Downloaded newer image for hyperledger/fabric-orderer:2.4.4
docker.io/hyperledger/fabric-orderer:2.4.4

# 成功
[root@localhost hyperledger]# docker pull hyperledger/fabric-baseos:2.4.4
2.4.4: Pulling from hyperledger/fabric-baseos
2408cc74d12b: Already exists 
6a3ced7e221e: Already exists 
5dec8747365f: Pull complete 
Digest: sha256:7d57d726fecf14b4cbe15ce16fcc8c6890d6d0af9337210aa597e4f0ea65485b
Status: Downloaded newer image for hyperledger/fabric-baseos:2.4.4
docker.io/hyperledger/fabric-baseos:2.4.4
1.4.3、再次install-fabric.sh脚本

若有单独下载的镜像,即执行了上面的docker pull命令,则再次执行下 install-fabric.sh 脚本,此次忽略下载失败的提示,因为所有镜像在上面步骤中都已下载完成了,为的是执行docker tag命令(可参见install-fabric.sh脚本)。

./install-fabric.sh docker

[root@localhost hyperledger]# ./install-fabric.sh docker

Pull Hyperledger Fabric docker images

FABRIC_IMAGES: peer orderer ccenv tools baseos
===> Pulling fabric Images
====>  hyperledger/fabric-peer:2.4.4
Error response from daemon: Head "https://registry-1.docker.io/v2/hyperledger/fabric-peer/manifests/2.4.4": read tcp 192.168.237.150:42142->44.194.5.25:443: read: connection reset by peer
====>  hyperledger/fabric-orderer:2.4.4
2.4.4: Pulling from hyperledger/fabric-orderer
Digest: sha256:2a12c6789745c099dc91e7c10c35e6bee7dbfd7b80009fa4c876a7a9cd342bb5
Status: Image is up to date for hyperledger/fabric-orderer:2.4.4
docker.io/hyperledger/fabric-orderer:2.4.4
====>  hyperledger/fabric-ccenv:2.4.4
Error response from daemon: Head "https://registry-1.docker.io/v2/hyperledger/fabric-ccenv/manifests/2.4.4": Get "https://auth.docker.io/token?scope=repository%3Ahyperledger%2Ffabric-ccenv%3Apull&service=registry.docker.io": net/http: TLS handshake timeout
====>  hyperledger/fabric-tools:2.4.4
2.4.4: Pulling from hyperledger/fabric-tools
Digest: sha256:fbb12c6e1edc760188cb9057ad68abfa3192a4a6e832dfd0b1ddfa284d28f517
Status: Image is up to date for hyperledger/fabric-tools:2.4.4
docker.io/hyperledger/fabric-tools:2.4.4
====>  hyperledger/fabric-baseos:2.4.4
Error response from daemon: Get "https://registry-1.docker.io/v2/": net/http: TLS handshake timeout
===> Pulling fabric ca Image
====>  hyperledger/fabric-ca:1.5.5
Error response from daemon: Head "https://registry-1.docker.io/v2/hyperledger/fabric-ca/manifests/1.5.5": Get "https://auth.docker.io/token?scope=repository%3Ahyperledger%2Ffabric-ca%3Apull&service=registry.docker.io": net/http: TLS handshake timeout
===> List out hyperledger images
hyperledger/fabric-ca        1.5       93f19fa873cb   5 weeks ago   76.5MB
hyperledger/fabric-ca        1.5.5     93f19fa873cb   5 weeks ago   76.5MB
hyperledger/fabric-ca        latest    93f19fa873cb   5 weeks ago   76.5MB
hyperledger/fabric-tools     2.4       d2f5f013cf70   8 weeks ago   489MB
hyperledger/fabric-tools     2.4.4     d2f5f013cf70   8 weeks ago   489MB
hyperledger/fabric-tools     latest    d2f5f013cf70   8 weeks ago   489MB
hyperledger/fabric-peer      2.4       080114f6c98f   8 weeks ago   64.2MB
hyperledger/fabric-peer      2.4.4     080114f6c98f   8 weeks ago   64.2MB
hyperledger/fabric-peer      latest    080114f6c98f   8 weeks ago   64.2MB
hyperledger/fabric-orderer   2.4       9e5c2bd3cd99   8 weeks ago   36.7MB
hyperledger/fabric-orderer   2.4.4     9e5c2bd3cd99   8 weeks ago   36.7MB
hyperledger/fabric-orderer   latest    9e5c2bd3cd99   8 weeks ago   36.7MB
hyperledger/fabric-ccenv     2.4       b01eeb054e4c   8 weeks ago   520MB
hyperledger/fabric-ccenv     2.4.4     b01eeb054e4c   8 weeks ago   520MB
hyperledger/fabric-ccenv     latest    b01eeb054e4c   8 weeks ago   520MB
hyperledger/fabric-baseos    2.4       1c37de9bc07b   8 weeks ago   6.86MB
hyperledger/fabric-baseos    2.4.4     1c37de9bc07b   8 weeks ago   6.86MB
hyperledger/fabric-baseos    latest    1c37de9bc07b   8 weeks ago   6.86MB
1.4.4、查看所有docker镜像(共6个)

docker images

[root@localhost hyperledger]# docker images
REPOSITORY                   TAG       IMAGE ID       CREATED       SIZE
hyperledger/fabric-ca        1.5       93f19fa873cb   5 weeks ago   76.5MB
hyperledger/fabric-ca        1.5.5     93f19fa873cb   5 weeks ago   76.5MB
hyperledger/fabric-ca        latest    93f19fa873cb   5 weeks ago   76.5MB
hyperledger/fabric-tools     2.4       d2f5f013cf70   8 weeks ago   489MB
hyperledger/fabric-tools     2.4.4     d2f5f013cf70   8 weeks ago   489MB
hyperledger/fabric-tools     latest    d2f5f013cf70   8 weeks ago   489MB
hyperledger/fabric-peer      2.4       080114f6c98f   8 weeks ago   64.2MB
hyperledger/fabric-peer      2.4.4     080114f6c98f   8 weeks ago   64.2MB
hyperledger/fabric-peer      latest    080114f6c98f   8 weeks ago   64.2MB
hyperledger/fabric-orderer   2.4       9e5c2bd3cd99   8 weeks ago   36.7MB
hyperledger/fabric-orderer   2.4.4     9e5c2bd3cd99   8 weeks ago   36.7MB
hyperledger/fabric-orderer   latest    9e5c2bd3cd99   8 weeks ago   36.7MB
hyperledger/fabric-ccenv     2.4       b01eeb054e4c   8 weeks ago   520MB
hyperledger/fabric-ccenv     2.4.4     b01eeb054e4c   8 weeks ago   520MB
hyperledger/fabric-ccenv     latest    b01eeb054e4c   8 weeks ago   520MB
hyperledger/fabric-baseos    2.4       1c37de9bc07b   8 weeks ago   6.86MB
hyperledger/fabric-baseos    2.4.4     1c37de9bc07b   8 weeks ago   6.86MB
hyperledger/fabric-baseos    latest    1c37de9bc07b   8 weeks ago   6.86MB
2、运行测试网络 (1)进入test-network目录

cd fabric-samples/test-network

[root@localhost hyperledger]# cd fabric-samples/test-network
[root@localhost test-network]# 
(2)查看测试网络帮助

./network.sh -h

[root@localhost test-network]# ./network.sh -h
Using docker and docker-compose
Usage: 
  network.sh  [Flags]
    Modes:
      up - Bring up Fabric orderer and peer nodes. No channel is created
      up createChannel - Bring up fabric network with one channel
      createChannel - Create and join a channel after the network is created
      deployCC - Deploy a chaincode to a channel (defaults to asset-transfer-basic)
      down - Bring down the network

    Flags:
    Used with network.sh up, network.sh createChannel:
    -ca  -  Use Certificate Authorities to generate network crypto material
    -c  - Name of channel to create (defaults to "mychannel")
    -s  - Peer state database to deploy: goleveldb (default) or couchdb
    -r  - CLI times out after certain number of attempts (defaults to 5)
    -d  - CLI delays for a certain number of seconds (defaults to 3)
    -verbose - Verbose mode

    Used with network.sh deployCC
    -c  - Name of channel to deploy chaincode to
    -ccn  - Chaincode name.
    -ccl  - Programming language of the chaincode to deploy: go, java, javascript, typescript
    -ccv   - Chaincode version. 1.0 (default), v2, version3.x, etc
    -ccs   - Chaincode definition sequence. Must be an integer, 1 (default), 2, 3, etc
    -ccp   - File path to the chaincode.
    -ccep   - (Optional) Chaincode endorsement policy using signature policy syntax. The default policy requires an endorsement from Org1 and Org2
    -cccg   - (Optional) File path to private data collections configuration file
    -cci   - (Optional) Name of chaincode initialization function. When a function is provided, the execution of init will be requested and the function will be invoked.

    -h - Print this message

 Possible Mode and flag combinations
   up -ca -r -d -s -verbose
   up createChannel -ca -c -r -d -s -verbose
   createChannel -c -r -d -verbose
   deployCC -ccn -ccl -ccv -ccs -ccp -cci -r -d -verbose

 Examples:
   network.sh up createChannel -ca -c mychannel -s couchdb
   network.sh createChannel -c channelName
   network.sh deployCC -ccn basic -ccp ../asset-transfer-basic/chaincode-javascript/ -ccl javascript
   network.sh deployCC -ccn mychaincode -ccp ./user/mychaincode -ccv 1 -ccl javascript
(3)关闭测试网络

在启动前先清空下测试网络

./network.sh down

[root@localhost test-network]# ./network.sh down
Using docker and docker-compose
Stopping network
[+] Running 4/0
 ⠿ Volume compose_orderer.example.com     Removed                                                                   0.0s
 ⠿ Volume compose_peer0.org1.example.com  Removed                                                                   0.0s
 ⠿ Volume compose_peer0.org2.example.com  Removed                                                                   0.0s
 ⠿ Volume compose_peer0.org3.example.com  Removed                                                                   0.0s
Error: No such volume: docker_orderer.example.com
Error: No such volume: docker_peer0.org1.example.com
Error: No such volume: docker_peer0.org2.example.com
Removing remaining containers
Removing generated chaincode docker images
"docker kill" requires at least 1 argument.
See 'docker kill --help'.

Usage:  docker kill [OPTIONS] CONTAINER [CONTAINER...]

Kill one or more running containers
Unable to find image 'busybox:latest' locally
latest: Pulling from library/busybox
5cc84ad355aa: Pull complete 
Digest: sha256:5acba83a746c7608ed544dc1533b87c737a0b0fb730301639a0179f9344b1678
Status: Downloaded newer image for busybox:latest
(4)启动测试网络

./network.sh up

[root@localhost test-network]# ./network.sh up
Using docker and docker-compose
Starting nodes with CLI timeout of '5' tries and CLI delay of '3' seconds and using database 'leveldb' with crypto from 'cryptogen'
LOCAL_VERSION=2.4.4
DOCKER_IMAGE_VERSION=2.4.4
/home/gopath/src/github.com/hyperledger/fabric-samples/bin/cryptogen
Generating certificates using cryptogen tool
Creating Org1 Identities
+ cryptogen generate --config=./organizations/cryptogen/crypto-config-org1.yaml --output=organizations
org1.example.com
+ res=0
Creating Org2 Identities
+ cryptogen generate --config=./organizations/cryptogen/crypto-config-org2.yaml --output=organizations
org2.example.com
+ res=0
Creating Orderer Org Identities
+ cryptogen generate --config=./organizations/cryptogen/crypto-config-orderer.yaml --output=organizations
+ res=0
Generating CCP files for Org1 and Org2
[+] Running 8/8
 ⠿ Network fabric_test                      Created                                                                 0.1s
 ⠿ Volume "compose_peer0.org2.example.com"  Created                                                                 0.0s
 ⠿ Volume "compose_orderer.example.com"     Created                                                                 0.0s
 ⠿ Volume "compose_peer0.org1.example.com"  Created                                                                 0.0s
 ⠿ Container peer0.org2.example.com         Started                                                                 1.0s
 ⠿ Container orderer.example.com            Started                                                                 1.2s
 ⠿ Container peer0.org1.example.com         Started                                                                 1.1s
 ⠿ Container cli                            Started                                                                 1.5s
CONTAINER ID   IMAGE                               COMMAND             CREATED        STATUS                  PORTS                                                                                                                             NAMES
c542333ec97c   hyperledger/fabric-tools:latest     "/bin/bash"         1 second ago   Up Less than a second                                                                                                                                     cli
75417c088594   hyperledger/fabric-orderer:latest   "orderer"           1 second ago   Up Less than a second   0.0.0.0:7050->7050/tcp, :::7050->7050/tcp, 0.0.0.0:7053->7053/tcp, :::7053->7053/tcp, 0.0.0.0:9443->9443/tcp, :::9443->9443/tcp   orderer.example.com
82d6f8435d30   hyperledger/fabric-peer:latest      "peer node start"   1 second ago   Up Less than a second   0.0.0.0:7051->7051/tcp, :::7051->7051/tcp, 0.0.0.0:9444->9444/tcp, :::9444->9444/tcp                                              peer0.org1.example.com
3f3344d4a744   hyperledger/fabric-peer:latest      "peer node start"   1 second ago   Up Less than a second   0.0.0.0:9051->9051/tcp, :::9051->9051/tcp, 7051/tcp, 0.0.0.0:9445->9445/tcp, :::9445->9445/tcp                                    peer0.org2.example.com
查看docker容器

docker ps -a

[root@localhost test-network]# docker ps -a
CONTAINER ID   IMAGE                               COMMAND             CREATED         STATUS              PORTS                                                                                                                             NAMES
c542333ec97c   hyperledger/fabric-tools:latest     "/bin/bash"         2 minutes ago   Up About a minute                                                                                                                                     cli
75417c088594   hyperledger/fabric-orderer:latest   "orderer"           2 minutes ago   Up About a minute   0.0.0.0:7050->7050/tcp, :::7050->7050/tcp, 0.0.0.0:7053->7053/tcp, :::7053->7053/tcp, 0.0.0.0:9443->9443/tcp, :::9443->9443/tcp   orderer.example.com
82d6f8435d30   hyperledger/fabric-peer:latest      "peer node start"   2 minutes ago   Up About a minute   0.0.0.0:7051->7051/tcp, :::7051->7051/tcp, 0.0.0.0:9444->9444/tcp, :::9444->9444/tcp                                              peer0.org1.example.com
3f3344d4a744   hyperledger/fabric-peer:latest      "peer node start"   2 minutes ago   Up About a minute   0.0.0.0:9051->9051/tcp, :::9051->9051/tcp, 7051/tcp, 0.0.0.0:9445->9445/tcp, :::9445->9445/tcp                                    peer0.org2.example.com
[root@localhost tes
(5)创建通道(channel)

./network.sh createChannel

[root@localhost test-network]# ./network.sh createChannel
Using docker and docker-compose
Creating channel 'mychannel'.
If network is not up, starting nodes with CLI timeout of '5' tries and CLI delay of '3' seconds and using database 'leveldb 
Network Running Already
Using docker and docker-compose
Generating channel genesis block 'mychannel.block'
/home/gopath/src/github.com/hyperledger/fabric-samples/bin/configtxgen
+ configtxgen -profile TwoOrgsApplicationGenesis -outputBlock ./channel-artifacts/mychannel.block -channelID mychannel
2022-08-14 16:22:05.084 CST 0001 INFO [common.tools.configtxgen] main -> Loading configuration
2022-08-14 16:22:05.091 CST 0002 INFO [common.tools.configtxgen.localconfig] completeInitialization -> orderer type: etcdraft
2022-08-14 16:22:05.091 CST 0003 INFO [common.tools.configtxgen.localconfig] completeInitialization -> Orderer.EtcdRaft.Options unset, setting to tick_interval:"500ms" election_tick:10 heartbeat_tick:1 max_inflight_blocks:5 snapshot_interval_size:16777216 
2022-08-14 16:22:05.091 CST 0004 INFO [common.tools.configtxgen.localconfig] Load -> Loaded configuration: /home/gopath/src/github.com/hyperledger/fabric-samples/test-network/configtx/configtx.yaml
2022-08-14 16:22:05.092 CST 0005 INFO [common.tools.configtxgen] doOutputBlock -> Generating genesis block
2022-08-14 16:22:05.092 CST 0006 INFO [common.tools.configtxgen] doOutputBlock -> Creating application channel genesis block
2022-08-14 16:22:05.093 CST 0007 INFO [common.tools.configtxgen] doOutputBlock -> Writing genesis block
+ res=0
Creating channel mychannel
Using organization 1
+ osnadmin channel join --channelID mychannel --config-block ./channel-artifacts/mychannel.block -o localhost:7053 --ca-file /home/gopath/src/github.com/hyperledger/fabric-samples/test-network/organizations/ordererOrganizations/example.com/tlsca/tlsca.example.com-cert.pem --client-cert /home/gopath/src/github.com/hyperledger/fabric-samples/test-network/organizations/ordererOrganizations/example.com/orderers/orderer.example.com/tls/server.crt --client-key /home/gopath/src/github.com/hyperledger/fabric-samples/test-network/organizations/ordererOrganizations/example.com/orderers/orderer.example.com/tls/server.key
+ res=0
Status: 201
{
	"name": "mychannel",
	"url": "/participation/v1/channels/mychannel",
	"consensusRelation": "consenter",
	"status": "active",
	"height": 1
}

Channel 'mychannel' created
Joining org1 peer to the channel...
Using organization 1
+ peer channel join -b ./channel-artifacts/mychannel.block
+ res=0
2022-08-14 16:22:11.153 CST 0001 INFO [channelCmd] InitCmdFactory -> Endorser and orderer connections initialized
2022-08-14 16:22:11.172 CST 0002 INFO [channelCmd] executeJoin -> Successfully submitted proposal to join channel
Joining org2 peer to the channel...
Using organization 2
+ peer channel join -b ./channel-artifacts/mychannel.block
+ res=0
2022-08-14 16:22:14.217 CST 0001 INFO [channelCmd] InitCmdFactory -> Endorser and orderer connections initialized
2022-08-14 16:22:14.244 CST 0002 INFO [channelCmd] executeJoin -> Successfully submitted proposal to join channel
Setting anchor peer for org1...
Using organization 1
Fetching channel config for channel mychannel
Using organization 1
Fetching the most recent configuration block for the channel
+ peer channel fetch config config_block.pb -o orderer.example.com:7050 --ordererTLSHostnameOverride orderer.example.com -c mychannel --tls --cafile /opt/gopath/src/github.com/hyperledger/fabric/peer/organizations/ordererOrganizations/example.com/tlsca/tlsca.example.com-cert.pem
2022-08-14 08:22:14.388 UTC 0001 INFO [channelCmd] InitCmdFactory -> Endorser and orderer connections initialized
2022-08-14 08:22:14.389 UTC 0002 INFO [cli.common] readBlock -> Received block: 0
2022-08-14 08:22:14.389 UTC 0003 INFO [channelCmd] fetch -> Retrieving last config block: 0
2022-08-14 08:22:14.390 UTC 0004 INFO [cli.common] readBlock -> Received block: 0
Decoding config block to JSON and isolating config to Org1MSPconfig.json
+ configtxlator proto_decode --input config_block.pb --type common.Block --output config_block.json
+ jq '.data.data[0].payload.data.config' config_block.json
Generating anchor peer update transaction for Org1 on channel mychannel
+ jq '.channel_group.groups.Application.groups.Org1MSP.values += {"AnchorPeers":{"mod_policy": "Admins","value":{"anchor_peers": [{"host": "peer0.org1.example.com","port": 7051}]},"version": "0"}}' Org1MSPconfig.json
+ configtxlator proto_encode --input Org1MSPconfig.json --type common.Config --output original_config.pb
+ configtxlator proto_encode --input Org1MSPmodified_config.json --type common.Config --output modified_config.pb
+ configtxlator compute_update --channel_id mychannel --original original_config.pb --updated modified_config.pb --output config_update.pb
+ configtxlator proto_decode --input config_update.pb --type common.ConfigUpdate --output config_update.json
+ jq .
++ cat config_update.json
+ echo '{"payload":{"header":{"channel_header":{"channel_id":"mychannel", "type":2}},"data":{"config_update":{' '"channel_id":' '"mychannel",' '"isolated_data":' '{},' '"read_set":' '{' '"groups":' '{' '"Application":' '{' '"groups":' '{' '"Org1MSP":' '{' '"groups":' '{},' '"mod_policy":' '"",' '"policies":' '{' '"Admins":' '{' '"mod_policy":' '"",' '"policy":' null, '"version":' '"0"' '},' '"Endorsement":' '{' '"mod_policy":' '"",' '"policy":' null, '"version":' '"0"' '},' '"Readers":' '{' '"mod_policy":' '"",' '"policy":' null, '"version":' '"0"' '},' '"Writers":' '{' '"mod_policy":' '"",' '"policy":' null, '"version":' '"0"' '}' '},' '"values":' '{' '"MSP":' '{' '"mod_policy":' '"",' '"value":' null, '"version":' '"0"' '}' '},' '"version":' '"0"' '}' '},' '"mod_policy":' '"",' '"policies":' '{},' '"values":' '{},' '"version":' '"0"' '}' '},' '"mod_policy":' '"",' '"policies":' '{},' '"values":' '{},' '"version":' '"0"' '},' '"write_set":' '{' '"groups":' '{' '"Application":' '{' '"groups":' '{' '"Org1MSP":' '{' '"groups":' '{},' '"mod_policy":' '"Admins",' '"policies":' '{' '"Admins":' '{' '"mod_policy":' '"",' '"policy":' null, '"version":' '"0"' '},' '"Endorsement":' '{' '"mod_policy":' '"",' '"policy":' null, '"version":' '"0"' '},' '"Readers":' '{' '"mod_policy":' '"",' '"policy":' null, '"version":' '"0"' '},' '"Writers":' '{' '"mod_policy":' '"",' '"policy":' null, '"version":' '"0"' '}' '},' '"values":' '{' '"AnchorPeers":' '{' '"mod_policy":' '"Admins",' '"value":' '{' '"anchor_peers":' '[' '{' '"host":' '"peer0.org1.example.com",' '"port":' 7051 '}' ']' '},' '"version":' '"0"' '},' '"MSP":' '{' '"mod_policy":' '"",' '"value":' null, '"version":' '"0"' '}' '},' '"version":' '"1"' '}' '},' '"mod_policy":' '"",' '"policies":' '{},' '"values":' '{},' '"version":' '"0"' '}' '},' '"mod_policy":' '"",' '"policies":' '{},' '"values":' '{},' '"version":' '"0"' '}' '}}}}'
+ configtxlator proto_encode --input config_update_in_envelope.json --type common.Envelope --output Org1MSPanchors.tx
2022-08-14 08:22:14.736 UTC 0001 INFO [channelCmd] InitCmdFactory -> Endorser and orderer connections initialized
2022-08-14 08:22:14.743 UTC 0002 INFO [channelCmd] update -> Successfully submitted channel update
Anchor peer set for org 'Org1MSP' on channel 'mychannel'
Setting anchor peer for org2...
Using organization 2
Fetching channel config for channel mychannel
Using organization 2
Fetching the most recent configuration block for the channel
+ peer channel fetch config config_block.pb -o orderer.example.com:7050 --ordererTLSHostnameOverride orderer.example.com -c mychannel --tls --cafile /opt/gopath/src/github.com/hyperledger/fabric/peer/organizations/ordererOrganizations/example.com/tlsca/tlsca.example.com-cert.pem
2022-08-14 08:22:14.880 UTC 0001 INFO [channelCmd] InitCmdFactory -> Endorser and orderer connections initialized
2022-08-14 08:22:14.882 UTC 0002 INFO [cli.common] readBlock -> Received block: 1
2022-08-14 08:22:14.882 UTC 0003 INFO [channelCmd] fetch -> Retrieving last config block: 1
2022-08-14 08:22:14.883 UTC 0004 INFO [cli.common] readBlock -> Received block: 1
Decoding config block to JSON and isolating config to Org2MSPconfig.json
+ configtxlator proto_decode --input config_block.pb --type common.Block --output config_block.json
+ jq '.data.data[0].payload.data.config' config_block.json
+ jq '.channel_group.groups.Application.groups.Org2MSP.values += {"AnchorPeers":{"mod_policy": "Admins","value":{"anchor_peers": [{"host": "peer0.org2.example.com","port": 9051}]},"version": "0"}}' Org2MSPconfig.json
Generating anchor peer update transaction for Org2 on channel mychannel
+ configtxlator proto_encode --input Org2MSPconfig.json --type common.Config --output original_config.pb
+ configtxlator proto_encode --input Org2MSPmodified_config.json --type common.Config --output modified_config.pb
+ configtxlator compute_update --channel_id mychannel --original original_config.pb --updated modified_config.pb --output config_update.pb
+ configtxlator proto_decode --input config_update.pb --type common.ConfigUpdate --output config_update.json
+ jq .
++ cat config_update.json
+ echo '{"payload":{"header":{"channel_header":{"channel_id":"mychannel", "type":2}},"data":{"config_update":{' '"channel_id":' '"mychannel",' '"isolated_data":' '{},' '"read_set":' '{' '"groups":' '{' '"Application":' '{' '"groups":' '{' '"Org2MSP":' '{' '"groups":' '{},' '"mod_policy":' '"",' '"policies":' '{' '"Admins":' '{' '"mod_policy":' '"",' '"policy":' null, '"version":' '"0"' '},' '"Endorsement":' '{' '"mod_policy":' '"",' '"policy":' null, '"version":' '"0"' '},' '"Readers":' '{' '"mod_policy":' '"",' '"policy":' null, '"version":' '"0"' '},' '"Writers":' '{' '"mod_policy":' '"",' '"policy":' null, '"version":' '"0"' '}' '},' '"values":' '{' '"MSP":' '{' '"mod_policy":' '"",' '"value":' null, '"version":' '"0"' '}' '},' '"version":' '"0"' '}' '},' '"mod_policy":' '"",' '"policies":' '{},' '"values":' '{},' '"version":' '"0"' '}' '},' '"mod_policy":' '"",' '"policies":' '{},' '"values":' '{},' '"version":' '"0"' '},' '"write_set":' '{' '"groups":' '{' '"Application":' '{' '"groups":' '{' '"Org2MSP":' '{' '"groups":' '{},' '"mod_policy":' '"Admins",' '"policies":' '{' '"Admins":' '{' '"mod_policy":' '"",' '"policy":' null, '"version":' '"0"' '},' '"Endorsement":' '{' '"mod_policy":' '"",' '"policy":' null, '"version":' '"0"' '},' '"Readers":' '{' '"mod_policy":' '"",' '"policy":' null, '"version":' '"0"' '},' '"Writers":' '{' '"mod_policy":' '"",' '"policy":' null, '"version":' '"0"' '}' '},' '"values":' '{' '"AnchorPeers":' '{' '"mod_policy":' '"Admins",' '"value":' '{' '"anchor_peers":' '[' '{' '"host":' '"peer0.org2.example.com",' '"port":' 9051 '}' ']' '},' '"version":' '"0"' '},' '"MSP":' '{' '"mod_policy":' '"",' '"value":' null, '"version":' '"0"' '}' '},' '"version":' '"1"' '}' '},' '"mod_policy":' '"",' '"policies":' '{},' '"values":' '{},' '"version":' '"0"' '}' '},' '"mod_policy":' '"",' '"policies":' '{},' '"values":' '{},' '"version":' '"0"' '}' '}}}}'
+ configtxlator proto_encode --input config_update_in_envelope.json --type common.Envelope --output Org2MSPanchors.tx
2022-08-14 08:22:15.046 UTC 0001 INFO [channelCmd] InitCmdFactory -> Endorser and orderer connections initialized
2022-08-14 08:22:15.055 UTC 0002 INFO [channelCmd] update -> Successfully submitted channel update
Anchor peer set for org 'Org2MSP' on channel 'mychannel'
Channel 'mychannel' joined
(6)在通道中启动一个链码

我们使用示例中的其中一个示例(asset-transfer-basic)部署链码

2.6.1、安装go依赖
[root@localhost test-network]# cd ..
[root@localhost fabric-samples]# cd asset-transfer-basic/chaincode-go/  #进入目录
[root@localhost chaincode-go]# ls                                       #查看目录内容
assetTransfer.go  chaincode  go.mod  go.sum                             #此时没有vendor目录
[root@localhost chaincode-go]# go env                                   #查看go环境配置
......
GOPROXY="https://proxy.golang.org,direct"                               #查看代理设置
......
[root@localhost chaincode-go]# go env -w GOPROXY=https://goproxy.cn     #更改代理
[root@localhost chaincode-go]# go mod vendor                            #安装依赖
[root@localhost chaincode-go]# ls                                       #查看目录内容
assetTransfer.go  chaincode  go.mod  go.sum  vendor                     #此时出现vendor目录
2.6.2、部署链码

进入到test-network目录,部署链码

./network.sh deployCC -ccn basic -ccp ../asset-transfer-basic/chaincode-go -ccl go

[root@localhost chaincode-go]# cd ..
[root@localhost asset-transfer-basic]# cd ..
[root@localhost fabric-samples]# cd test-network
[root@localhost test-network]# ./network.sh deployCC -ccn basic -ccp ../asset-transfer-basic/chaincode-go -ccl go
Using docker and docker-compose
deploying chaincode on channel 'mychannel'
executing with the following
- CHANNEL_NAME: mychannel
- CC_NAME: basic
- CC_SRC_PATH: ../asset-transfer-basic/chaincode-go
- CC_SRC_LANGUAGE: go
- CC_VERSION: 1.0
- CC_SEQUENCE: 1
- CC_END_POLICY: NA
- CC_COLL_CONFIG: NA
- CC_INIT_FCN: NA
- DELAY: 3
- MAX_RETRY: 5
- VERBOSE: false
Vendoring Go dependencies at ../asset-transfer-basic/chaincode-go
/home/gopath/src/github.com/hyperledger/fabric-samples/asset-transfer-basic/chaincode-go /home/gopath/src/github.com/hyperledger/fabric-samples/test-network
/home/gopath/src/github.com/hyperledger/fabric-samples/test-network
Finished vendoring Go dependencies
+ peer lifecycle chaincode package basic.tar.gz --path ../asset-transfer-basic/chaincode-go --lang golang --label basic_1.0
+ res=0
Chaincode is packaged
Installing chaincode on peer0.org1...
Using organization 1
+ peer lifecycle chaincode install basic.tar.gz
+ res=0
2022-08-14 17:14:29.284 CST 0001 INFO [cli.lifecycle.chaincode] submitInstallProposal -> Installed remotely: response: 
2022-08-14 17:14:29.285 CST 0002 INFO [cli.lifecycle.chaincode] submitInstallProposal -> Chaincode code package identifier: basic_1.0:2e20ce421c8037420718c8a3918a1eea76343b7361fffdac454181c54e5736c7
Chaincode is installed on peer0.org1
Install chaincode on peer0.org2...
Using organization 2
+ peer lifecycle chaincode install basic.tar.gz
+ res=0
2022-08-14 17:14:38.207 CST 0001 INFO [cli.lifecycle.chaincode] submitInstallProposal -> Installed remotely: response: 
2022-08-14 17:14:38.207 CST 0002 INFO [cli.lifecycle.chaincode] submitInstallProposal -> Chaincode code package identifier: basic_1.0:2e20ce421c8037420718c8a3918a1eea76343b7361fffdac454181c54e5736c7
Chaincode is installed on peer0.org2
Using organization 1
+ peer lifecycle chaincode queryinstalled
+ res=0
Installed chaincodes on peer:
Package ID: basic_1.0:2e20ce421c8037420718c8a3918a1eea76343b7361fffdac454181c54e5736c7, Label: basic_1.0
Query installed successful on peer0.org1 on channel
Using organization 1
+ peer lifecycle chaincode approveformyorg -o localhost:7050 --ordererTLSHostnameOverride orderer.example.com --tls --cafile /home/gopath/src/github.com/hyperledger/fabric-samples/test-network/organizations/ordererOrganizations/example.com/tlsca/tlsca.example.com-cert.pem --channelID mychannel --name basic --version 1.0 --package-id basic_1.0:2e20ce421c8037420718c8a3918a1eea76343b7361fffdac454181c54e5736c7 --sequence 1
+ res=0
2022-08-14 17:14:40.294 CST 0001 INFO [chaincodeCmd] ClientWait -> txid [fba0772155296854a87c03e4de42b49fcd3a58b602f6fb98daa77791f892bf9c] committed with status (VALID) at localhost:7051
Chaincode definition approved on peer0.org1 on channel 'mychannel'
Using organization 1
Checking the commit readiness of the chaincode definition on peer0.org1 on channel 'mychannel'...
Attempting to check the commit readiness of the chaincode definition on peer0.org1, Retry after 3 seconds.
+ peer lifecycle chaincode checkcommitreadiness --channelID mychannel --name basic --version 1.0 --sequence 1 --output json
+ res=0
{
	"approvals": {
		"Org1MSP": true,
		"Org2MSP": false
	}
}
Checking the commit readiness of the chaincode definition successful on peer0.org1 on channel 'mychannel'
Using organization 2
Checking the commit readiness of the chaincode definition on peer0.org2 on channel 'mychannel'...
Attempting to check the commit readiness of the chaincode definition on peer0.org2, Retry after 3 seconds.
+ peer lifecycle chaincode checkcommitreadiness --channelID mychannel --name basic --version 1.0 --sequence 1 --output json
+ res=0
{
	"approvals": {
		"Org1MSP": true,
		"Org2MSP": false
	}
}
Checking the commit readiness of the chaincode definition successful on peer0.org2 on channel 'mychannel'
Using organization 2
+ peer lifecycle chaincode approveformyorg -o localhost:7050 --ordererTLSHostnameOverride orderer.example.com --tls --cafile /home/gopath/src/github.com/hyperledger/fabric-samples/test-network/organizations/ordererOrganizations/example.com/tlsca/tlsca.example.com-cert.pem --channelID mychannel --name basic --version 1.0 --package-id basic_1.0:2e20ce421c8037420718c8a3918a1eea76343b7361fffdac454181c54e5736c7 --sequence 1
+ res=0
2022-08-14 17:14:48.422 CST 0001 INFO [chaincodeCmd] ClientWait -> txid [60bba72674fd0af78d585e7b4d71666abde82a39d0443065e6c89662122063d5] committed with status (VALID) at localhost:9051
Chaincode definition approved on peer0.org2 on channel 'mychannel'
Using organization 1
Checking the commit readiness of the chaincode definition on peer0.org1 on channel 'mychannel'...
Attempting to check the commit readiness of the chaincode definition on peer0.org1, Retry after 3 seconds.
+ peer lifecycle chaincode checkcommitreadiness --channelID mychannel --name basic --version 1.0 --sequence 1 --output json
+ res=0
{
	"approvals": {
		"Org1MSP": true,
		"Org2MSP": true
	}
}
Checking the commit readiness of the chaincode definition successful on peer0.org1 on channel 'mychannel'
Using organization 2
Checking the commit readiness of the chaincode definition on peer0.org2 on channel 'mychannel'...
Attempting to check the commit readiness of the chaincode definition on peer0.org2, Retry after 3 seconds.
+ peer lifecycle chaincode checkcommitreadiness --channelID mychannel --name basic --version 1.0 --sequence 1 --output json
+ res=0
{
	"approvals": {
		"Org1MSP": true,
		"Org2MSP": true
	}
}
Checking the commit readiness of the chaincode definition successful on peer0.org2 on channel 'mychannel'
Using organization 1
Using organization 2
+ peer lifecycle chaincode commit -o localhost:7050 --ordererTLSHostnameOverride orderer.example.com --tls --cafile /home/gopath/src/github.com/hyperledger/fabric-samples/test-network/organizations/ordererOrganizations/example.com/tlsca/tlsca.example.com-cert.pem --channelID mychannel --name basic --peerAddresses localhost:7051 --tlsRootCertFiles /home/gopath/src/github.com/hyperledger/fabric-samples/test-network/organizations/peerOrganizations/org1.example.com/tlsca/tlsca.org1.example.com-cert.pem --peerAddresses localhost:9051 --tlsRootCertFiles /home/gopath/src/github.com/hyperledger/fabric-samples/test-network/organizations/peerOrganizations/org2.example.com/tlsca/tlsca.org2.example.com-cert.pem --version 1.0 --sequence 1
+ res=0
2022-08-14 17:14:56.652 CST 0001 INFO [chaincodeCmd] ClientWait -> txid [381cc8b2c247ab054ed5cbd83bb653930099b200f37b1db7858f07e0a4bcf921] committed with status (VALID) at localhost:9051
2022-08-14 17:14:56.659 CST 0002 INFO [chaincodeCmd] ClientWait -> txid [381cc8b2c247ab054ed5cbd83bb653930099b200f37b1db7858f07e0a4bcf921] committed with status (VALID) at localhost:7051
Chaincode definition committed on channel 'mychannel'
Using organization 1
Querying chaincode definition on peer0.org1 on channel 'mychannel'...
Attempting to Query committed status on peer0.org1, Retry after 3 seconds.
+ peer lifecycle chaincode querycommitted --channelID mychannel --name basic
+ res=0
Committed chaincode definition for chaincode 'basic' on channel 'mychannel':
Version: 1.0, Sequence: 1, Endorsement Plugin: escc, Validation Plugin: vscc, Approvals: [Org1MSP: true, Org2MSP: true]
Query chaincode definition successful on peer0.org1 on channel 'mychannel'
Using organization 2
Querying chaincode definition on peer0.org2 on channel 'mychannel'...
Attempting to Query committed status on peer0.org2, Retry after 3 seconds.
+ peer lifecycle chaincode querycommitted --channelID mychannel --name basic
+ res=0
Committed chaincode definition for chaincode 'basic' on channel 'mychannel':
Version: 1.0, Sequence: 1, Endorsement Plugin: escc, Validation Plugin: vscc, Approvals: [Org1MSP: true, Org2MSP: true]
Query chaincode definition successful on peer0.org2 on channel 'mychannel'
Chaincode initialization is not required
(7)与Fabric测试网络交互
# 配置
[root@localhost test-network]# export PATH=${PWD}/../bin:$PATH
[root@localhost test-network]# export FABRIC_CFG_PATH=$PWD/../config/

# 组织1环境配置
[root@localhost test-network]# # Environment variables for Org1
[root@localhost test-network]# 
[root@localhost test-network]# export CORE_PEER_TLS_ENABLED=true
[root@localhost test-network]# export CORE_PEER_LOCALMSPID="Org1MSP"
[root@localhost test-network]# export CORE_PEER_TLS_ROOTCERT_FILE=${PWD}/organizations/peerOrganizations/org1.example.com/peers/peer0.org1.example.com/tls/ca.crt
[root@localhost test-network]# export CORE_PEER_MSPCONFIGPATH=${PWD}/organizations/peerOrganizations/org1.example.com/users/Admin@org1.example.com/msp
[root@localhost test-network]# export CORE_PEER_ADDRESS=localhost:7051


# 向链码中添加数据
[root@localhost test-network]# peer chaincode invoke -o localhost:7050 --ordererTLSHostnameOverride orderer.example.com --tls --cafile "${PWD}/organizations/ordererOrganizations/example.com/orderers/orderer.example.com/msp/tlscacerts/tlsca.example.com-cert.pem" -C mychannel -n basic --peerAddresses localhost:7051 --tlsRootCertFiles "${PWD}/organizations/peerOrganizations/org1.example.com/peers/peer0.org1.example.com/tls/ca.crt" --peerAddresses localhost:9051 --tlsRootCertFiles "${PWD}/organizations/peerOrganizations/org2.example.com/peers/peer0.org2.example.com/tls/ca.crt" -c '{"function":"InitLedger","Args":[]}'
2022-08-14 17:18:18.536 CST 0001 INFO [chaincodeCmd] chaincodeInvokeOrQuery -> Chaincode invoke successful. result: status:200 

# 查看添加的数据
[root@localhost test-network]# peer chaincode query -C mychannel -n basic -c '{"Args":["GetAllAssets"]}'
[{"AppraisedValue":300,"Color":"blue","ID":"asset1","Owner":"Tomoko","Size":5},{"AppraisedValue":400,"Color":"red","ID":"asset2","Owner":"Brad","Size":5},{"AppraisedValue":500,"Color":"green","ID":"asset3","Owner":"Jin Soo","Size":10},{"AppraisedValue":600,"Color":"yellow","ID":"asset4","Owner":"Max","Size":10},{"AppraisedValue":700,"Color":"black","ID":"asset5","Owner":"Adriana","Size":15},{"AppraisedValue":800,"Color":"white","ID":"asset6","Owner":"Michel","Size":15}]

# 修改数据
[root@localhost test-network]# peer chaincode invoke -o localhost:7050 --ordererTLSHostnameOverride orderer.example.com --tls --cafile "${PWD}/organizations/ordererOrganizations/example.com/orderers/orderer.example.com/msp/tlscacerts/tlsca.example.com-cert.pem" -C mychannel -n basic --peerAddresses localhost:7051 --tlsRootCertFiles "${PWD}/organizations/peerOrganizations/org1.example.com/peers/peer0.org1.example.com/tls/ca.crt" --peerAddresses localhost:9051 --tlsRootCertFiles "${PWD}/organizations/peerOrganizations/org2.example.com/peers/peer0.org2.example.com/tls/ca.crt" -c '{"function":"TransferAsset","Args":["asset6","Christopher"]}'
2022-08-14 17:19:25.738 CST 0001 INFO [chaincodeCmd] chaincodeInvokeOrQuery -> Chaincode invoke successful. result: status:200 payload:"Michel" 

# 查看修改的数据
[root@localhost test-network]# peer chaincode query -C mychannel -n basic -c '{"Args":["GetAllAssets"]}'
[{"AppraisedValue":300,"Color":"blue","ID":"asset1","Owner":"Tomoko","Size":5},{"AppraisedValue":400,"Color":"red","ID":"asset2","Owner":"Brad","Size":5},{"AppraisedValue":500,"Color":"green","ID":"asset3","Owner":"Jin Soo","Size":10},{"AppraisedValue":600,"Color":"yellow","ID":"asset4","Owner":"Max","Size":10},{"AppraisedValue":700,"Color":"black","ID":"asset5","Owner":"Adriana","Size":15},{"AppraisedValue":800,"Color":"white","ID":"asset6","Owner":"Christopher","Size":15}]


# 组织2环境配置
[root@localhost test-network]# # Environment variables for Org2
[root@localhost test-network]# 
[root@localhost test-network]# export CORE_PEER_TLS_ENABLED=true
[root@localhost test-network]# export CORE_PEER_LOCALMSPID="Org2MSP"
[root@localhost test-network]# export CORE_PEER_TLS_ROOTCERT_FILE=${PWD}/organizations/peerOrganizations/org2.example.com/peers/peer0.org2.example.com/tls/ca.crt
[root@localhost test-network]# export CORE_PEER_MSPCONFIGPATH=${PWD}/organizations/peerOrganizations/org2.example.com/users/Admin@org2.example.com/msp
[root@localhost test-network]# export CORE_PEER_ADDRESS=localhost:9051

# 查看组织1添加并修改的数据
[root@localhost test-network]# peer chaincode query -C mychannel -n basic -c '{"Args":["ReadAsset","asset6"]}'
{"AppraisedValue":800,"Color":"white","ID":"asset6","Owner":"Christopher","Size":15}

参考文档(官网):Using the Fabric test network — hyperledger-fabricdocs main documentation

欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/zaji/2991525.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-09-23
下一篇 2022-09-23

发表评论

登录后才能评论

评论列表(0条)

保存