Hyperledger fabric running test network

Posted by mdojet on Sun, 06 Mar 2022 13:22:15 +0100

1, Prepare

linux environment or install a virtual machine in windows.
The following are the tests under Linux environment.

2, Prerequisites

Git ,cURL,Docker,Docker Compose

1. git installation

sudo yum install git

test
git --version

2,cURL

sudo yum install curl

3,Docker ,Docker Compose

Docker should be able to install official documents. I have no problem installing it

Docker official address

Test:
docker --version

Docker Compose:
Download the latest version from github

sudo curl -L https://github.com/docker/compose/releases/download/1.16.1/docker-compose-`uname -s`-`uname -m` -o /usr/local/bin/docker-compose

Add executable permissions

sudo chmod +x /usr/local/bin/docker-compose

Test:
docker-compose --version

4. Run docker

sudo systemctl start docker

3, Install go

Note: it's not necessary, but I use go when testing
Enter directory
cd /usr/local/
Download installation package
wget https://studygolang.com/dl/golang/go1.14.1.linux-amd64.tar.gz

★ note: if an error is reported here and wget is not found, use yum to install wegt
yum -y install wget

Unzip the installation package
tar -zxvf go1.14.1.linux-amd64.tar.gz

4, Download the latest version of Fabric samples, Docker images, and binaries.

curl -sSL https://bit.ly/2ysbOFE | bash -s

★ error: TCP connection reset by peer
Try network problems several times and always succeed

5, git clone fabric file

https://github.com/GitHeP/fabric-samples.git
The project contains bootstrap SH file

Cloning is slow, so I first download it to window and then transfer it to Linux

6, Start test network

Enter directory
cd fabric-samples-main/test-network
★ error reporting:

Permission denied 

Change maximum permissions
sudo chmod -R 777 folder name

First install the script file bootstrap sh
sh bootstrap.sh
start-up
./network.sh up

Test:
docker ps -a

Success is indicated by the following

7, Create channel

./network.sh createChannel

8, Deployment chain code

You need to use go language here
Enter the go directory
cd fabric-samples-main/chaincode/ fabcar/go
then
G0111MODUL E=on go mod vendor

Return the directory of test network
cd ../../../test-network

Add the binary files in the bin directory to the cLI path

export PATH=${PWD}/.. /bin:$PATH

Set IFABRIC_ CFG_ PATH refers to the core. Yam1 file in fabric- samples

export FABRIC_CFG_PATH=$PWD/.. /config/

Create chain code package
Use the peer lifecycle chain code package command to create chain code packages.

peer lifecycle chaincode package fabcar.tar.gz --path . ./ chaincode/fabcar/go/ -- lang golang
-label fabcar _1

★ error reported here

Error: failed to normalize chaincode path: 'go list' failed with: go: 
github.com/golang/protobuf@v1.3.2: Get 
"https://proxy.golang.org/github.com/golang/protobuf/@v/v1.3.2.mod": dial tcp 
172.217.160.81:443: connect: connection refused: exit status 1

solve:
Go problem switching go agent

go env -w GOPROXY=https://goproxy.io,direct
go env -w GO111MODULE=on

Here, a fabcar will be generated tar. GZ file

9, Node installation chain code

The wrong number should be reported

export CORE_ PEER_TLS_ENABLED=true
export CORE_ PEER_ LOCALMSPID="Org1MSP"
export CORE_ PEER_TLS_ ROOTCERT_ FILE=${PWD}/ organizat ions/ peerOrganizations/ org1.example.com/ peers/ peer0. org1.example.com/tls/ca.crt
export CORE_ PEER_ ADDRESS=localhost:7051

Use the peer lifecycle chain install command to install the chain code on the peer node
peer lifecycle chaincode install fabcar. tar.gz
★ error reporting: is this code reporting an error or is it a go language problem
Error message:
500 error

Error: chaincode install failed with status: 500 - failed to invoke backing implementation of 
'InstallChaincode': could not build chaincode: docker build failed: docker image build 
failed: docker build failed: Error returned from build: 1 "go: 
github.com/golang/protobuf@v1.3.2: Get 
"https://proxy.golang.org/github.com/golang/protobuf/@v/v1.3.2.mod": dial tcp 
172.217.24.17:443: connect: connection refused

Solution: submit the download dependent package to the directory where the chain code is located

cd fabric-samples-main/asset-transfer-basic/chaincode-go

Change agent

go env -w GOPROXY=https://goproxy.io,direct
go env -w GO111MODULE=on
go mod vendor

Repackage and install chain code

peer lifecycle chaincode package fabcar.tar.gz --path ../asset-transfer-basic/chaincode-go/ --lang golang --label basic_1.0

peer lifecycle chaincode install fabcar.tar.gz

The appearance of 200 indicates real success!

Topics: Blockchain fabric