Centos7 installation of Hyperledge Fabric v2.3 test network in VMware

Posted by nvee on Fri, 29 Oct 2021 01:19:11 +0200

catalogue

Installation environment

0. Prerequisites:

1. Download Fabric (version 2.3.3)

two   Installation example, binary and Docker image (see method 3 directly)

(1) Method 1 (unsuccessful): execute directly according to the official website

(2) Method 2 (unsuccessful): directly execute the bootstrap.sh script  , Same error as method 1

(3) Method 3: directly download the file in bootstrap.sh

3. Start the test network

4. Create a channel

5. Installation go dependency

6. Start a chain code in the channel

7. Interaction with the network

Reference documents

Installation environment

        Virtual machine: VMware Workstation 15 Pro

         Operating system installed on virtual machine: Centos7

0. Prerequisites:

(1) Install Git   reference resources   Centos7 installing Git_ Blog of ling1998 - CSDN blog

(2) Install Go   reference resources   Centos7 installation go_ Blog of ling1998 - CSDN blog

(3) Install docker CE   reference resources   Installing docker in Centos7_ Blog of ling1998 - CSDN blog

(4) Install Docker Compose   reference resources   Installing docker compose in Centos7_ Blog of ling1998 - CSDN blog

1. Download Fabric (version 2.3.3)

[root@localhost ~]# mkdir -p $GOPATH/src/github.com/hyperledger  # Create download directory
[root@localhost ~]# cd $GOPATH/src/github.com/hyperledger    #Enter directory
[root@localhost hyperledger]# git clone https://github.com/hyperledger/fabric.git

    Download is too slow, wait, etc. (you can use scientific Internet tools)

    The following errors may occur during downloading. Try several more times

two   Installation example, binary and Docker image (see method 3 directly)

(1) Method 1 (unsuccessful): execute directly according to the official website

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

(2) Method 2 (unsuccessful): directly execute the bootstrap.sh script  , Same error as method 1

#Enter the fabric/scripts directory
cd fabric/scripts
#Execute bootstrap.sh
./bootstrap.sh

(3) Method 3: directly download the file in bootstrap.sh

        See the relevant contents in the bootstrap.sh script to get three download addresses

VERSION=2.3.3       #fabric version
......
CA_VERSION=1.5.2    #Fabric CA version
ARCH=$(echo "$(uname -s|tr '[:upper:]' '[:lower:]'|sed 's/mingw64_nt.*/windows/')-$(uname -m | sed 's/x86_64/amd64/g')")
......
cloneSamplesRepo() {
    ......
        #Download fabirc samples
        git clone -b main https://github.com/hyperledger/fabric-samples.git && cd fabric-samples
    ......
}
......
pullBinaries() {
    echo "===> Downloading version ${FABRIC_TAG} platform specific fabric binaries"
    #Download fabric binary file
    download "${BINARY_FILE}" "https://github.com/hyperledger/fabric/releases/download/v${VERSION}/${BINARY_FILE}"
    ......
    #Download the fabric CA binary
    download "${CA_BINARY_FILE}" "https://github.com/hyperledger/fabric-ca/releases/download/v${CA_VERSION}/${CA_BINARY_FILE}"
    ......
}
......
BINARY_FILE=hyperledger-fabric-${ARCH}-${VERSION}.tar.gz
CA_BINARY_FILE=hyperledger-fabric-ca-${ARCH}-${CA_VERSION}.tar.gz

      First, Download fabric sample and try to use git and wget. After multiple error reports (as shown in the figure below), download it directly in windows, and then transfer it to the corresponding directory of CentOS 7 (as shown in the figure below). Download address: GitHub - hyperledger/fabric-samples

          Upload to the fabric/scripts directory at the same level as the bootstrap.sh script

        

        Secondly, download the fabric binary file (version 2.3.3), use wget to report an error, download it directly in windows, and then upload it to CentOS 7 for decompression. The download address is: https://github.com/hyperledger/fabric/releases/download/v2.3.3/hyperledger-fabric-linux-amd64-2.3.3.tar.gz

      Finally, download the fabric CA binary file (version 1.5.2), close the firewall and surf the Internet scientifically at the same time. If wget reports an error, it is recommended to download it in the windows browser, then upload it to CentOS 7 and unzip it. The download address is: ​​​​​https://github.com/hyperledger/fabric-ca/releases/download/v1.5.2/hyperledger-fabric-ca-linux-amd64-1.5.2.tar.gz

[root@localhost scripts]# systemctl stop firewalld.service  #Turn off firewall
[root@localhost scripts]# firewall-cmd --state    #View firewall status
not running
[root@localhost scripts]# wget https://github.com/hyperledger/fabric-ca/releases/download/v1.5.2/hyperledger-fabric-ca-linux-amd64-1.5.2.tar.gz # Download

    The above two compressed files are downloaded to the fabric/scripts directory

 

  Unzip the file into fabric samples

[root@localhost scripts]# tar -xvf hyperledger-fabric-linux-amd64-2.3.3.tar.gz -C fabric-samples
[root@localhost scripts]# tar -xvf hyperledger-fabric-ca-linux-amd64-1.5.2.tar.gz.tar.gz -C fabric-samples

 

  Execute the. / bootstrap.sh script

[root@localhost scripts]# ./bootstrap.sh -b  #Pull only the image file of fabric

Binary files can be used for global settings

[root@localhost scripts]# cd fabric-samples/bin  #Enter the bin directory
[root@localhost bin]# ls
configtxgen    cryptogen  fabric-ca-client  idemixgen  osnadmin
configtxlator  discover   fabric-ca-server  orderer    peer
[root@localhost bin]# cp * /usr/local/bin  #copy the binary file to / usr/local/bin

3. Start the test network

[root@localhost bin]# cd ..                           #Go back to the fabric samples directory
[root@localhost fabric-samples]# cd test-network      #Enter the test network directory
[root@localhost test-network]# ./network.sh           #Start test network script
-bash: ./network.sh: Permission denied                #Prompt that you do not have permission to execute the network.sh file
[root@localhost test-network]# chmod u+x network.sh   #to grant authorization
[root@localhost test-network]# ./network.sh           #Execute the test network script again
[root@localhost test-network]# ./network.sh up        #Start test network

4. Create a channel

[root@localhost test-network]# ./network.sh createChannel

5. Installation go dependency

[root@localhost fabric-samples]# cd asset-transfer-basic/chaincode-go/  #Enter directory
[root@localhost chaincode-go]# ls                                       #View directory contents
assetTransfer.go  chaincode  go.mod  go.sum                             #There is no vendor directory at this time
[root@localhost chaincode-go]# go env                                   #View go environment configuration
......
GOPROXY="https://proxy.golang.org,direct "# view proxy settings
......
[root@localhost chaincode-go]# go env -w GOPROXY=https://goproxy.cn # change proxy
[root@localhost chaincode-go]# go mod vendor                            #Installation dependency
[root@localhost chaincode-go]# ls                                       #View directory contents
assetTransfer.go  chaincode  go.mod  go.sum  vendor                     #The vendor directory appears

6. Start a chain code in the channel

[root@localhost chaincode-go]# cd ..
[root@localhost asset-transfer-basic]# cd ..        
[root@localhost fabric-samples]# cd test-network    #Enter the test network directory
[root@localhost test-network]# ./network.sh deployCC -ccn basic -ccp ../asset-transfer-basic/chaincode-go -ccl go   #Start a chain code in the channel (official website)

If an error occurs when starting the chain code:. / network.sh: line 270: scripts/deployCC.sh: Permission denied

It is better to authorize all. sh files in the directory to avoid authorization errors when executing later

[root@localhost test-network]# cd scripts
[root@localhost scripts]# ls -l
total 36
-rw-r--r--. 1 root root  2284 Oct 25 02:33 configUpdate.sh
-rwxr--r--. 1 root root  2562 Oct 25 02:33 createChannel.sh
-rw-r--r--. 1 root root 11675 Oct 25 02:33 deployCC.sh
-rw-r--r--. 1 root root  3476 Oct 25 02:33 envVar.sh
drwxr-xr-x. 2 root root    58 Oct 25 02:33 org3-scripts
-rw-r--r--. 1 root root  1941 Oct 25 02:33 setAnchorPeer.sh
-rw-r--r--. 1 root root  7269 Oct 25 02:33 utils.sh
[root@localhost scripts]# chmod -R +x ../scripts        #All files in the directory are authorized
[root@localhost scripts]# ls -l
total 36
-rwxr-xr-x. 1 root root  2284 Oct 25 02:33 configUpdate.sh
-rwxr-xr-x. 1 root root  2562 Oct 25 02:33 createChannel.sh
-rwxr-xr-x. 1 root root 11675 Oct 25 02:33 deployCC.sh
-rwxr-xr-x. 1 root root  3476 Oct 25 02:33 envVar.sh
drwxr-xr-x. 2 root root    58 Oct 25 02:33 org3-scripts
-rwxr-xr-x. 1 root root  1941 Oct 25 02:33 setAnchorPeer.sh
-rwxr-xr-x. 1 root root  7269 Oct 25 02:33 utils.sh
[root@localhost scripts]# cd ..
[root@localhost test-network]# ./network.sh deployCC -ccn basic -ccp ../asset-transfer-basic/chaincode-go -ccl go

7. Interaction with the network

(just follow the steps on the official website, see the official website Test network using Fabric - hyperledger fabricdocs master document)

[root@localhost test-network]# export PATH=${PWD}/../bin:$PATH
[root@localhost test-network]# export FABRIC_CFG_PATH=$PWD/../config/
[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":[]}'
2021-10-25 17:53:30.230 CST [chaincodeCmd] chaincodeInvokeOrQuery -> INFO 001 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"]}'
2021-10-25 17:55:15.507 CST [chaincodeCmd] chaincodeInvokeOrQuery -> INFO 001 Chaincode invoke successful. result: status:200 
[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
[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}

Reference documents:

Test network using Fabric - hyperledger fabricdocs master document

​​​​​​About the solution to the error after executing. / bootstrap.sh in fabric _lakerssss24blog - CSDN blog

Topics: Blockchain fabric