Fabric实验的安装配置和运行
一、写在前面
- 本实验基于linux平台(ubuntu发行版),使用Hyperledger(超级账本)项目中的Fabric区块链架构进行实验操作,Fabric软件基于容器运行(docker),需要对
linux/GNN项目
有相当的了解,对于ubuntu操作系统可以进行一定程度的操作
,对于docker容器技术也需要一定的掌握和了解
。 - 本实验对于系统安装不再赘述,注意老师布置作业的要求,磁盘需大于30G,正常安装即可,建议采用secureCRT、xshell、mobaxterm等远程客户端工具连接实验系统进行操作,方便管理。
- 绝大多数实验出现错误的原因在于网络,由于实验过程中需要拉取大量的github网站上的东西,所以对网络要求比较高,如果国外网络访问实在困难,建议将github项目拉取至国内网站(一般是gitee.com)下载。
- 绝大多数错误经过同学整理都解决掉了,目前暂未发现新的错误,若有新错误,建议及时更新至错误解决文档,大家共同解决。
二、实验环境
-
系统平台:
jys@jys-OpenStack-Nova:~$ cat /etc/issue Ubuntu 20.04.1 LTS \n \l jys@jys-OpenStack-Nova:~$ cat /etc/lsb-release DISTRIB_ID=Ubuntu DISTRIB_RELEASE=20.04 DISTRIB_CODENAME=focal DISTRIB_DESCRIPTION="Ubuntu 20.04.1 LTS" jys@jys-OpenStack-Nova:~$ uname -a Linux jys-OpenStack-Nova 5.4.0-42-generic #46-Ubuntu SMP Fri Jul 10 00:24:02 UTC 2020 x86_64 x86_64 x86_64 GNU/Linux jys@jys-OpenStack-Nova:~$
-
配置:4C/8G/30G
-
用户:root(建议使用root用户权限,普通用户可能在后面更新环境变量后依旧无使用,更改root用户操作如下)
jys@jys-OpenStack-Nova:~$ sudo passwd root New password: Retype new password: passwd: password updated successfully jys@jys-OpenStack-Nova:~$ su - root Password: root@jys-OpenStack-Nova:~#
-
更换ubuntu源
可参考阿里源配置
https://developer.aliyun.com/mirror/ubuntu?spm=a2c6h.13651102.0.0.3e221b1151wI71
root@jys-OpenStack-Nova:~# cp /etc/apt/sources.list /etc/apt/sources.listbak root@jys-OpenStack-Nova:~# cat /etc/apt/sources.list | head #deb cdrom:[Ubuntu 20.04.1 LTS _Focal Fossa_ - Release amd64 (20200731)]/ focal main restricted # See http://help.ubuntu.com/community/UpgradeNotes for how to upgrade to # newer versions of the distribution. deb http://cn.archive.ubuntu.com/ubuntu/ focal main restricted # deb-src http://cn.archive.ubuntu.com/ubuntu/ focal main restricted ## Major bug fix updates produced after the final release of the ## distribution. deb http://cn.archive.ubuntu.com/ubuntu/ focal-updates main restricted root@jys-OpenStack-Nova:~# sed -i 's/cn.archive.ubuntu.com/mirrors.aliyun.com/g' /etc/apt/sources.list root@jys-OpenStack-Nova:~# cat /etc/apt/sources.list #deb cdrom:[Ubuntu 20.04.1 LTS _Focal Fossa_ - Release amd64 (20200731)]/ focal main restricted # See http://help.ubuntu.com/community/UpgradeNotes for how to upgrade to # newer versions of the distribution. deb http://mirrors.aliyun.com/ubuntu/ focal main restricted # deb-src http://mirrors.aliyun.com/ubuntu/ focal main restricted ## Major bug fix updates produced after the final release of the ## distribution. deb http://mirrors.aliyun.com/ubuntu/ focal-updates main restricted # deb-src http://mirrors.aliyun.com/ubuntu/ focal-updates main restricted ## N.B. software from this repository is ENTIRELY UNSUPPORTED by the Ubuntu ## team. Also, please note that software in universe WILL NOT receive any ## review or updates from the Ubuntu security team. deb http://mirrors.aliyun.com/ubuntu/ focal universe # deb-src http://mirrors.aliyun.com/ubuntu/ focal universe deb http://mirrors.aliyun.com/ubuntu/ focal-updates universe # deb-src http://mirrors.aliyun.com/ubuntu/ focal-updates universe ## N.B. software from this repository is ENTIRELY UNSUPPORTED by the Ubuntu ## team, and may not be under a free licence. Please satisfy yourself as to ## your rights to use the software. Also, please note that software in ## multiverse WILL NOT receive any review or updates from the Ubuntu ## security team. deb http://mirrors.aliyun.com/ubuntu/ focal multiverse # deb-src http://mirrors.aliyun.com/ubuntu/ focal multiverse deb http://mirrors.aliyun.com/ubuntu/ focal-updates multiverse # deb-src http://mirrors.aliyun.com/ubuntu/ focal-updates multiverse ## N.B. software from this repository may not have been tested as ## extensively as that contained in the main release, although it includes ## newer versions of some applications which may provide useful features. ## Also, please note that software in backports WILL NOT receive any review ## or updates from the Ubuntu security team. deb http://mirrors.aliyun.com/ubuntu/ focal-backports main restricted universe multiverse # deb-src http://mirrors.aliyun.com/ubuntu/ focal-backports main restricted universe multiverse ## Uncomment the following two lines to add software from Canonical's ## 'partner' repository. ## This software is not part of Ubuntu, but is offered by Canonical and the ## respective vendors as a service to Ubuntu users. # deb http://archive.canonical.com/ubuntu focal partner # deb-src http://archive.canonical.com/ubuntu focal partner deb http://security.ubuntu.com/ubuntu focal-security main restricted # deb-src http://security.ubuntu.com/ubuntu focal-security main restricted deb http://security.ubuntu.com/ubuntu focal-security universe # deb-src http://security.ubuntu.com/ubuntu focal-security universe deb http://security.ubuntu.com/ubuntu focal-security multiverse # deb-src http://security.ubuntu.com/ubuntu focal-security multiverse # This system was installed using small removable media # (e.g. netinst, live or single CD). The matching "deb cdrom" # entries were disabled at the end of the installation process. # For information about how to configure apt package sources, # see the sources.list(5) manual. root@jys-OpenStack-Nova:~# apt update Get:1 http://mirrors.aliyun.com/ubuntu focal InRelease [265 kB] Get:2 http://mirrors.aliyun.com/ubuntu focal-updates InRelease [111 kB] Get:3 http://mirrors.aliyun.com/ubuntu focal-backports InRelease [98.3 kB] Get:4 http://mirrors.aliyun.com/ubuntu focal/main amd64 Packages [970 kB] Get:5 http://security.ubuntu.com/ubuntu focal-security InRelease [107 kB] Get:6 http://mirrors.aliyun.com/ubuntu focal/main i386 Packages [718 kB] Get:7 http://mirrors.aliyun.com/ubuntu focal/main Translation-en [506 kB] Get:8 http://mirrors.aliyun.com/ubuntu focal/main amd64 DEP-11 Metadata [494 kB] Get:9 http://mirrors.aliyun.com/ubuntu focal/main DEP-11 48x48 Icons [98.4 kB] Get:10 http://mirrors.aliyun.com/ubuntu focal/main DEP-11 64x64 Icons [163 kB] Get:11 http://mirrors.aliyun.com/ubuntu focal/main DEP-11 64x64@2 Icons [15.8 kB] Get:12 http://mirrors.aliyun.com/ubuntu focal/main amd64 c-n-f Metadata [29.5 kB] Get:13 http://mirrors.aliyun.com/ubuntu focal/restricted i386 Packages [8,112 B] Get:14 http://mirrors.aliyun.com/ubuntu focal/restricted amd64 Packages [22.0 kB] Fetched 41.0 MB in 20s (2,016 kB/s) Reading package lists... Done Building dependency tree Reading state information... Done 290 packages can be upgraded. Run 'apt list --upgradable' to see them.
三、安装基本工具
-
安装
curl,git
root@jys-OpenStack-Nova:~# apt-get install curl git Reading package lists... Done Building dependency tree Reading state information... Done The following additional packages will be installed: git-man libcurl4 liberror-perl Suggested packages: git-daemon-run | git-daemon-sysvinit git-doc git-el git-email git-gui gitk gitweb git-cvs git-mediawiki git-svn The following NEW packages will be installed: curl git git-man liberror-perl The following packages will be upgraded: libcurl4 1 upgraded, 4 newly installed, 0 to remove and 306 not upgraded. Need to get 5,626 kB/5,859 kB of archives. After this operation, 38.8 MB of additional disk space will be used. Do you want to continue? [Y/n] y Get:1 http://mirrors.aliyun.com/ubuntu focal-security/main amd64 curl amd64 7.68.0-1ubuntu2.2 [161 kB] Get:2 http://mirrors.aliyun.com/ubuntu focal/main amd64 liberror-perl all 0.17029-1 [26.5 kB] Get:3 http://mirrors.aliyun.com/ubuntu focal/main amd64 git-man all 1:2.25.1-1ubuntu3 [884 kB] Get:4 http://mirrors.aliyun.com/ubuntu focal/main amd64 git amd64 1:2.25.1-1ubuntu3 [4,554 kB] Fetched 5,626 kB in 1s (4,821 kB/s) (Reading database ... 146161 files and directories currently installed.) Preparing to unpack .../libcurl4_7.68.0-1ubuntu2.2_amd64.deb ... Unpacking libcurl4:amd64 (7.68.0-1ubuntu2.2) over (7.68.0-1ubuntu2.1) ... Selecting previously unselected package curl. Preparing to unpack .../curl_7.68.0-1ubuntu2.2_amd64.deb ... Unpacking curl (7.68.0-1ubuntu2.2) ... Selecting previously unselected package liberror-perl. Preparing to unpack .../liberror-perl_0.17029-1_all.deb ... Unpacking liberror-perl (0.17029-1) ... Selecting previously unselected package git-man. Preparing to unpack .../git-man_1%3a2.25.1-1ubuntu3_all.deb ... Unpacking git-man (1:2.25.1-1ubuntu3) ... Selecting previously unselected package git. Preparing to unpack .../git_1%3a2.25.1-1ubuntu3_amd64.deb ... Unpacking git (1:2.25.1-1ubuntu3) ... Setting up liberror-perl (0.17029-1) ... Setting up libcurl4:amd64 (7.68.0-1ubuntu2.2) ... Setting up git-man (1:2.25.1-1ubuntu3) ... Setting up curl (7.68.0-1ubuntu2.2) ... Setting up git (1:2.25.1-1ubuntu3) ... Processing triggers for man-db (2.9.1-1) ... Processing triggers for libc-bin (2.31-0ubuntu9) ...
-
安装pip
由于ubuntu 20.04系统自动安装了python3,需下载python3-pip
root@jys-OpenStack-Nova:~# python3 --version Python 3.8.2 root@jys-OpenStack-Nova:~# apt install python3-pip Reading package lists... Done Building dependency tree Reading state information... Done After this operation, 171 MB of additional disk space will be used. Do you want to continue? [Y/n] y Processing triggers for mime-support (3.64ubuntu1) ... Processing triggers for gnome-menus (3.36.0-1ubuntu1) ... Processing triggers for libc-bin (2.31-0ubuntu9) ... Processing triggers for man-db (2.9.1-1) ... Processing triggers for desktop-file-utils (0.24-1ubuntu3) ...
-
pip3换源
root@jys-OpenStack-Nova:~# pwd /root root@jys-OpenStack-Nova:~# mkdir ~/.pip root@jys-OpenStack-Nova:~# cd ~/.pip && touch pip.conf root@jys-OpenStack-Nova:~/.pip# echo "[global]" >>pip.conf root@jys-OpenStack-Nova:~/.pip# echo "index-url = https://mirrors.aliyun.com/pypi/simple" >>pip.conf root@jys-OpenStack-Nova:~/.pip# cat pip.conf [global] index-url = https://mirrors.aliyun.com/pypi/simple
-
更新pip3
root@jys-OpenStack-Nova:~/.pip# pip3 install --upgrade pip Looking in indexes: https://mirrors.aliyun.com/pypi/simple Collecting pip Downloading https://mirrors.aliyun.com/pypi/packages/cb/28/91f26bd088ce8e22169032100d4260614fc3da435025ff389ef1d396a433/pip-20.2.4-py2.py3-none-any.whl (1.5 MB) |████████████████████████████████| 1.5 MB 2.7 MB/s Installing collected packages: pip Attempting uninstall: pip Found existing installation: pip 20.0.2 Not uninstalling pip at /usr/lib/python3/dist-packages, outside environment /usr Can't uninstall 'pip'. No files were found to uninstall. Successfully installed pip-20.2.4
-
安装docker
root@jys-OpenStack-Nova:~/.pip# apt install docker.io Reading package lists... Done Building dependency tree Reading state information... Done The following additional packages will be installed: Created symlink /etc/systemd/system/sockets.target.wants/docker.socket → /lib/systemd/system/docker.socket. docker.service is a disabled or a static unit, not starting it. Processing triggers for systemd (245.4-4ubuntu3.2) ... Processing triggers for man-db (2.9.1-1) ... root@jys-OpenStack-Nova:~/.pip# docker -v Docker version 19.03.8, build afacb8b7f0
-
docker换源
root@jys-OpenStack-Nova:~/.pip# vim /etc/docker/daemon.json { "registry-mirrors":[ "http://docker.mirrors.ustc.edu.cn", "http://hub-mirror.c.163.com", "http://registry.docker-cn.com" ], "insecure-registries":[ "docker.mirrors.ustc.edu.cn", "registry.docker-cn.com" ] }
-
启动docker服务
root@jys-OpenStack-Nova:~/.pip# systemctl restart docker root@jys-OpenStack-Nova:~/.pip# systemctl enable docker Created symlink /etc/systemd/system/multi-user.target.wants/docker.service → /lib/systemd/system/docker.service. root@jys-OpenStack-Nova:~/.pip# ps -ef | grep docker root 21733 1 1 18:28 ? 00:00:00 /usr/bin/dockerd -H fd:// --containerd=/run/containerd/containerd.sock root 21902 7365 0 18:28 pts/3 00:00:00 grep --color=auto docker
-
安装docker-compose
root@jys-OpenStack-Nova:~/.pip# apt install docker-compose Reading package lists... Done Building dependency tree Reading state information... Done The following additional packages will be installed: Setting up python3-dockerpty (0.4.1-2) ... Setting up python3-importlib-metadata (1.5.0-1) ... Setting up python3-docker (4.1.0-1) ... Setting up python3-jsonschema (3.2.0-0ubuntu2) ... Setting up docker-compose (1.25.0-1) ... Processing triggers for man-db (2.9.1-1) ... root@jys-OpenStack-Nova:~/.pip# docker-compose -v docker-compose version 1.25.0, build unknown
-
安装go语言
-
安装前置依赖并切换到/usr/local目录
root@jys-OpenStack-Nova:~/.pip# apt install libtool libltdl-dev //前置依赖 Reading package lists... Done Building dependency tree Reading state information... Done The following additional packages will be installed: Setting up libltdl-dev:amd64 (2.4.6-14) ... Processing triggers for libc-bin (2.31-0ubuntu9) ... Processing triggers for man-db (2.9.1-1) ... Processing triggers for install-info (6.7.0.dfsg.2-5) root@jys-OpenStack-Nova:~# cd /usr/local/ //切换到/usr/local目录 root@jys-OpenStack-Nova:/usr/local# pwd /usr/local
-
下载golang 源码包(https://studygolang.com/dl)
root@jys-OpenStack-Nova:/usr/local# wget https://dl.google.com/go/go1.15.5.linux-amd64.tar.gz --2020-11-22 18:33:48-- https://dl.google.com/go/go1.15.5.linux-amd64.tar.gz Resolving dl.google.com (dl.google.com)... 120.253.255.97 Connecting to dl.google.com (dl.google.com)|120.253.255.97|:443... connected. HTTP request sent, awaiting response... 200 OK Length: 120900442 (115M) [application/octet-stream] Saving to: ‘go1.15.5.linux-amd64.tar.gz’ go1.15.5.linux-amd64.tar.gz 100%[=================================================================================>] 115.30M 20.2MB/s in 5.8s 2020-11-22 18:33:54 (19.8 MB/s) - ‘go1.15.5.linux-amd64.tar.gz’ saved [120900442/120900442]
-
解压源码包
root@jys-OpenStack-Nova:/usr/local# tar -xzvf go1.15.5.linux-amd64.tar.gz root@jys-OpenStack-Nova:/usr/local# ls bin etc games go go1.15.5.linux-amd64.tar.gz include lib man sbin share src
-
环境变量配置
root@jys-OpenStack-Nova:/usr/local# vim /etc/profile 末行添加如下内容: export PATH=$PATH:/usr/local/go/bin export GOROOT=/usr/local/go export GOPATH=$HOME/go export PATH=$PATH:$GOROOT/bin:$GOPATH/bin root@jys-OpenStack-Nova:/usr/local# source /etc/profile //使环境变量生效
-
验证
root@jys-OpenStack-Nova:/usr/local# source /etc/profile root@jys-OpenStack-Nova:/usr/local# go version go version go1.15.5 linux/amd64
-
配置golang源
root@jys-OpenStack-Nova:/usr/local# go env -w GO111MODULE=on root@jys-OpenStack-Nova:/usr/local# go env -w GOPROXY=https://goproxy.cn,direct
四、Fabric配置
- fabric文件创建及脚本执行
-
手动创建超级账本文件夹(路径自己定义,一般在/home/username底下。username为自己的用户名)
root@jys-OpenStack-Nova:/usr/local# mkdir -p /home/jys/go/src/github.com/hyperledger/ root@jys-OpenStack-Nova:/usr/local# cd /home/jys/go/src/github.com/hyperledger/ root@jys-OpenStack-Nova:/home/jys/go/src/github.com/hyperledger# pwd /home/jys/go/src/github.com/hyperledger
-
从github上拉取fabric的源码
//说明:由于github源可能导致网络中断问题,我将有关源码转到了国内gitee.com上进行下载 root@jys-OpenStack-Nova:/home/jys/go/src/github.com/hyperledger# git clone https://gitee.com/qcricket/fabric.git Cloning into 'fabric'... remote: Enumerating objects: 142927, done. remote: Counting objects: 100% (142927/142927), done. remote: Compressing objects: 100% (40739/40739), done. Receiving objects: 92% (131493/142927), 83.09 MiB | 7.78 MiB/s root@jys-OpenStack-Nova:/home/jys/go/src/github.com/hyperledger# ls fabric
-
修改
bootstrap.sh
脚本//修改完先不要运行脚本 root@jys-OpenStack-Nova:/home/jys/go/src/github.com/hyperledger/fabric/scripts# vim bootstrap.sh //135、136行true改为false SAMPLES=false BINARIES=false
-
从github上拉取fabric-samples的源码
//说明:同2由于github源可能导致网络中断问题,我将有关源码转到了国内gitee.com上进行下载 root@jys-OpenStack-Nova:/home/jys/go/src/github.com/hyperledger/fabric/scripts# git clone https://gitee.com/qcricket/fabric-samples.git Cloning into 'fabric-samples'... remote: Enumerating objects: 6728, done. remote: Counting objects: 100% (6728/6728), done. remote: Compressing objects: 100% (2771/2771), done. remote: Total 6728 (delta 3507), reused 6728 (delta 3507), pack-reused 0 Receiving objects: 100% (6728/6728), 3.83 MiB | 787.00 KiB/s, done. Resolving deltas: 100% (3507/3507), done. root@jys-OpenStack-Nova:/home/jys/go/src/github.com/hyperledger/fabric/scripts# ls bootstrap.sh check_file_name_spaces.sh check_references.sh compile_protos.sh generateHelpDocs.sh run-integration-tests.sh changelog.sh check_go_version.sh check_spelling.sh fabric-samples golinter.sh run-unit-tests.sh check_deps.sh check_license.sh check_trailingspaces.sh functions.sh metrics_doc.sh
-
下载的二进制文件并解压(fabric和faric-ca)
root@jys-OpenStack-Nova:/home/jys/go/src/github.com/hyperledger/fabric/scripts/fabric-samples# wget https://github.91chifun.workers.dev//https://github.com/hyperledger/fabric/releases/download/v2.2.1/hyperledger-fabric-linux-amd64-2.2.1.tar.gz --2020-11-22 19:33:57-- https://github.91chifun.workers.dev//https://github.com/hyperledger/fabric/releases/download/v2.2.1/hyperledger-fabric-linux-amd64-2.2.1.tar.gz Resolving github.91chifun.workers.dev (github.91chifun.workers.dev)... 104.31.64.78, 104.31.65.78, 172.67.206.97, ... Connecting to github.91chifun.workers.dev (github.91chifun.workers.dev)|104.31.64.78|:443... connected. HTTP request sent, awaiting response... 200 OK Length: 76331973 (73M) [application/octet-stream] Saving to: ‘hyperledger-fabric-linux-amd64-2.2.1.tar.gz’ hyperledger-fabric-linux-amd64-2.2.1.tar 100%[=================================================================================>] 72.79M 1.90MB/s in 42s 2020-11-22 19:34:41 (1.74 MB/s) - ‘hyperledger-fabric-linux-amd64-2.2.1.tar.gz’ saved [76331973/76331973] root@jys-OpenStack-Nova:/home/jys/go/src/github.com/hyperledger/fabric/scripts/fabric-samples# wget https://github.91chifun.workers.dev//https://github.com/hyperledger/fabric-ca/releases/download/v1.4.6/hyperledger-fabric-ca-linux-amd64-1.4.6.tar.gz --2020-11-22 19:35:22-- https://github.91chifun.workers.dev//https://github.com/hyperledger/fabric-ca/releases/download/v1.4.6/hyperledger-fabric-ca-linux-amd64-1.4.6.tar.gz Resolving github.91chifun.workers.dev (github.91chifun.workers.dev)... 172.67.206.97, 104.31.65.78, 104.31.64.78, ... Connecting to github.91chifun.workers.dev (github.91chifun.workers.dev)|172.67.206.97|:443... connected. HTTP request sent, awaiting response... 200 OK Length: 24446703 (23M) [application/octet-stream] Saving to: ‘hyperledger-fabric-ca-linux-amd64-1.4.6.tar.gz’ hyperledger-fabric-ca-linux-amd64-1.4.6. 100%[=================================================================================>] 23.31M 1.08MB/s in 21s 2020-11-22 19:35:44 (1.13 MB/s) - ‘hyperledger-fabric-ca-linux-amd64-1.4.6.tar.gz’ saved [24446703/24446703] root@jys-OpenStack-Nova:/home/jys/go/src/github.com/hyperledger/fabric/scripts/fabric-samples# tar -xzvf hyperledger-fabric-linux-amd64-2.2.1.tar.gz bin/ bin/peer bin/cryptogen bin/idemixgen bin/orderer bin/configtxlator bin/discover bin/configtxgen config/ config/core.yaml config/orderer.yaml config/configtx.yaml root@jys-OpenStack-Nova:/home/jys/go/src/github.com/hyperledger/fabric/scripts/fabric-samples# tar -xzvf hyperledger-fabric-ca-linux-amd64-1.4.6.tar.gz bin/ bin/fabric-ca-client bin/fabric-ca-server
-
启动
bootstrap.sh
脚本root@jys-OpenStack-Nova:/home/jys/go/src/github.com/hyperledger/fabric/scripts/fabric-samples# ./../bootstrap.sh //注意此处的路径,bootstrap.sh属于上层目录 Pull Hyperledger Fabric docker images FABRIC_IMAGES: peer orderer ccenv tools baseos ===> Pulling fabric Images ====> hyperledger/fabric-peer:2.2.1 2.2.1: Pulling from hyperledger/fabric-peer df20fa9351a1: Pull complete bf6a493ed4fd: Pull complete 6eb16ab0d46f: Pull complete 79afd9a944cb: Pull complete 7a05aeb24cf4: Pull complete b2ae6a994472: Pull complete Digest: sha256:bf4995c86af6bba20e31a11ca9e7de6d74c5b21cee2baff01d4864fe6a62986f Status: Downloaded newer image for hyperledger/fabric-peer:2.2.1 docker.io/hyperledger/fabric-peer:2.2.1 ====> hyperledger/fabric-orderer:2.2.1
五、Fabric启动、运行和测试
-
进入
test-network
目录root@jys-OpenStack-Nova:/home/jys/go/src/github.com/hyperledger/fabric/scripts/fabric-samples# pwd /home/jys/go/src/github.com/hyperledger/fabric/scripts/fabric-samples root@jys-OpenStack-Nova:/home/jys/go/src/github.com/hyperledger/fabric/scripts/fabric-samples# cd test-network/
-
启动Fabric网络
root@jys-OpenStack-Nova:/home/jys/go/src/github.com/hyperledger/fabric/scripts/fabric-samples/test-network# ./network.sh up 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.2.1 DOCKER_IMAGE_VERSION=2.2.1 /home/jys/go/src/github.com/hyperledger/fabric/scripts/fabric-samples/test-network/../bin/cryptogen Generate certificates using cryptogen tool Create Org1 Identities + cryptogen generate --config=./organizations/cryptogen/crypto-config-org1.yaml --output=organizations org1.example.com + res=0 Create Org2 Identities + cryptogen generate --config=./organizations/cryptogen/crypto-config-org2.yaml --output=organizations org2.example.com + res=0 Create Orderer Org Identities + cryptogen generate --config=./organizations/cryptogen/crypto-config-orderer.yaml --output=organizations + res=0 Generate CCP files for Org1 and Org2 /home/jys/go/src/github.com/hyperledger/fabric/scripts/fabric-samples/test-network/../bin/configtxgen Generating Orderer Genesis block + configtxgen -profile TwoOrgsOrdererGenesis -channelID system-channel -outputBlock ./system-genesis-block/genesis.block 2020-11-22 19:47:45.374 CST [common.tools.configtxgen] main -> INFO 001 Loading configuration 2020-11-22 19:47:45.410 CST [common.tools.configtxgen.localconfig] completeInitialization -> INFO 002 orderer type: etcdraft 2020-11-22 19:47:45.410 CST [common.tools.configtxgen.localconfig] completeInitialization -> INFO 003 Orderer.EtcdRaft.Options unset, setting to tick_interval:"500ms" election_tick:10 heartbeat_tick:1 max_inflight_blocks:5 snapshot_interval_size:16777216 2020-11-22 19:47:45.410 CST [common.tools.configtxgen.localconfig] Load -> INFO 004 Loaded configuration: /home/jys/go/src/github.com/hyperledger/fabric/scripts/fabric-samples/test-network/configtx/configtx.yaml 2020-11-22 19:47:45.413 CST [common.tools.configtxgen] doOutputBlock -> INFO 005 Generating genesis block 2020-11-22 19:47:45.414 CST [common.tools.configtxgen] doOutputBlock -> INFO 006 Writing genesis block + res=0 Creating network "net_test" 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_peer0.org2.example.com" with default driver Creating orderer.example.com ... done Creating peer0.org1.example.com ... done Creating peer0.org2.example.com ... done CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES 176672d306d4 hyperledger/fabric-peer:latest "peer node start" 1 second ago Up Less than a second 7051/tcp, 0.0.0.0:9051->9051/tcp peer0.org2.example.com 8b293a19d24e hyperledger/fabric-peer:latest "peer node start" 1 second ago Up Less than a second 0.0.0.0:7051->7051/tcp peer0.org1.example.com f621083e7490 hyperledger/fabric-orderer:latest "orderer" 1 second ago Up Less than a second 0.0.0.0:7050->7050/tcp orderer.example.com
-
建立通道
root@jys-OpenStack-Nova:/home/jys/go/src/github.com/hyperledger/fabric/scripts/fabric-samples/test-network# ./network.sh createChannel 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 Generating channel create transaction 'mychannel.tx' + configtxgen -profile TwoOrgsChannel -outputCreateChannelTx ./channel-artifacts/mychannel.tx -channelID mychannel 2020-11-22 19:48:49.748 CST [common.tools.configtxgen] main -> INFO 001 Loading configuration 2020-11-22 19:48:49.774 CST [common.tools.configtxgen.localconfig] Load -> INFO 002 Loaded configuration: /home/jys/go/src/github.com/hyperledger/fabric/scripts/fabric-samples/test-network/configtx/configtx.yaml 2020-11-22 19:48:49.774 CST [common.tools.configtxgen] doOutputChannelCreateTx -> INFO 003 Generating new channel configtx 2020-11-22 19:48:49.777 CST [common.tools.configtxgen] doOutputChannelCreateTx -> INFO 004 Writing new channel tx ================省略部分过程================ 2020-11-22 19:49:10.042 CST [channelCmd] InitCmdFactory -> INFO 001 Endorser and orderer connections initialized 2020-11-22 19:49:10.076 CST [channelCmd] update -> INFO 002 Successfully submitted channel update Anchor peers updated for org 'Org2MSP' on channel 'mychannel' Channel successfully joined
-
在通道上启动链码
root@jys-OpenStack-Nova:/home/jys/go/src/github.com/hyperledger/fabric/scripts/fabric-samples/test-network# source /etc/profile //这里建议再执行一遍环境变量 root@jys-OpenStack-Nova:/home/jys/go/src/github.com/hyperledger/fabric/scripts/fabric-samples/test-network# ./network.sh deployCC deploying chaincode on channel 'mychannel' executing with the following - CHANNEL_NAME: mychannel - CC_NAME: basic - CC_SRC_PATH: NA - 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 ===========省略部分过程========== + 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
-
环境变量设置
root@jys-OpenStack-Nova:/home/jys/go/src/github.com/hyperledger/fabric/scripts/fabric-samples/test-network# vim /etc/profile //末行添加 export PATH=${PWD}/../bin:${PWD}:$PATH export FABRIC_CFG_PATH=${PWD}/../config/ # Environment variables for Org1 export CORE_PEER_TLS_ENABLED=true export CORE_PEER_LOCALMSPID="Org1MSP" export CORE_PEER_TLS_ROOTCERT_FILE=${PWD}/organizations/peerOrganizations/org1.example.com/peers/peer0.org1.example.com/tls/ca.crt export CORE_PEER_MSPCONFIGPATH=${PWD}/organizations/peerOrganizations/org1.example.com/users/Admin@org1.example.com/msp export CORE_PEER_ADDRESS=localhost:7051 root@jys-OpenStack-Nova:/home/jys/go/src/github.com/hyperledger/fabric/scripts/fabric-samples/test-network# source /etc/profile //使刚才添加的环境变量生效
-
运行和排错
初次运行会报如下错误: root@jys-OpenStack-Nova:/home/jys/go/src/github.com/hyperledger/fabric/scripts/fabric-samples/test-network# peer chaincode query -C mychannel -n fabcar -c '{"Args":["queryAllCars"]}' Error: endorsement failure during query. response: status:500 message:"make sure the chaincode fabcar has been successfully defined on channel mychannel and try again: chaincode fabcar not found" 解决方法: root@jys-OpenStack-Nova:/home/jys/go/src/github.com/hyperledger/fabric/scripts/fabric-samples/test-network# cd ../fabcar/ root@jys-OpenStack-Nova:/home/jys/go/src/github.com/hyperledger/fabric/scripts/fabric-samples/fabcar# pwd /home/jys/go/src/github.com/hyperledger/fabric/scripts/fabric-samples/fabcar root@jys-OpenStack-Nova:/home/jys/go/src/github.com/hyperledger/fabric/scripts/fabric-samples/fabcar# ls go java javascript networkDown.sh startFabric.sh typescript root@jys-OpenStack-Nova:/home/jys/go/src/github.com/hyperledger/fabric/scripts/fabric-samples/fabcar# ./startFabric.sh //启动该脚本 /home/jys/go/src/github.com/hyperledger/fabric/scripts/fabric-samples/test-network /home/jys/go/src/github.com/hyperledger/fabric/scripts/fabric-samples/fabcar Stopping network Stopping peer0.org2.example.com ... done Stopping peer0.org1.example.com ... done Stopping orderer.example.com ... done Removing peer0.org2.example.com ... done Removing peer0.org1.example.com ... done ===========省略部分过程========== Total setup execution time : 155 secs ... Next, use the FabCar applications to interact with the deployed FabCar contract. The FabCar applications are available in multiple programming languages. Follow the instructions for the programming language of your choice: ===========省略部分过程========== Go: Start by changing into the "go" directory: cd go Then, install dependencies and run the test using: go run fabcar.go The test will invoke the sample client app which perform the following: - Import user credentials into the wallet (if they don't already exist there) - Submit a transaction to create a new car - Evaluate a transaction (query) to return details of this car - Submit a transaction to change the owner of this car - Evaluate a transaction (query) to return the updated details of this car
-
测试
root@jys-OpenStack-Nova:/home/jys/go/src/github.com/hyperledger/fabric/scripts/fabric-samples/fabcar# peer chaincode query -C mychannel -n fabcar -c '{"Args":["queryAllCars"]}' [{"Key":"CAR0","Record":{"make":"Toyota","model":"Prius","colour":"blue","owner":"Tomoko"}},{"Key":"CAR1","Record":{"make":"Ford","model":"Mustang","colour":"red","owner":"Brad"}},{"Key":"CAR2","Record":{"make":"Hyundai","model":"Tucson","colour":"green","owner":"Jin Soo"}},{"Key":"CAR3","Record":{"make":"Volkswagen","model":"Passat","colour":"yellow","owner":"Max"}},{"Key":"CAR4","Record":{"make":"Tesla","model":"S","colour":"black","owner":"Adriana"}},{"Key":"CAR5","Record":{"make":"Peugeot","model":"205","colour":"purple","owner":"Michel"}},{"Key":"CAR6","Record":{"make":"Chery","model":"S22L","colour":"white","owner":"Aarav"}},{"Key":"CAR7","Record":{"make":"Fiat","model":"Punto","colour":"violet","owner":"Pari"}},{"Key":"CAR8","Record":{"make":"Tata","model":"Nano","colour":"indigo","owner":"Valeria"}},{"Key":"CAR9","Record":{"make":"Holden","model":"Barina","colour":"brown","owner":"Shotaro"}}]