Fabric 2.0 environment construction

Note: The installation environment is Ubuntu20.04 virtual machine, and the image file is ubuntu-20.04.1-desktop-amd64

1. Change source

If the virtual machine cannot copy text from the host, install a vmtools

sudo apt-get install open-vm-tools
sudo apt-get install open-vm-tools-desktop

then rebootreboot

Change source reference

  1. It is recommended to copy and backup the original file

    sudo cp /etc/apt/sources.list /etc/apt/sources.list.bak

  2. Open and modify the sources.list file

    #在文件最前面添加即可
    sudo vi /etc/apt/sources.list  
    
    #  阿里源
    deb http://mirrors.aliyun.com/ubuntu/ bionic main restricted universe multiverse
    deb http://mirrors.aliyun.com/ubuntu/ bionic-security main restricted universe multiverse
    deb http://mirrors.aliyun.com/ubuntu/ bionic-updates main restricted universe multiverse
    deb http://mirrors.aliyun.com/ubuntu/ bionic-proposed main restricted universe multiverse
    deb http://mirrors.aliyun.com/ubuntu/ bionic-backports main restricted universe multiverse
    deb-src http://mirrors.aliyun.com/ubuntu/ bionic main restricted universe multiverse
    deb-src http://mirrors.aliyun.com/ubuntu/ bionic-security main restricted universe multiverse
    deb-src http://mirrors.aliyun.com/ubuntu/ bionic-updates main restricted universe multiverse
    deb-src http://mirrors.aliyun.com/ubuntu/ bionic-proposed main restricted universe multiverse
    deb-src http://mirrors.aliyun.com/ubuntu/ bionic-backports main restricted universe multiverse
    
    1. update it
    sudo apt-get update
    sudo apt-get upgrade
    

2. Necessary environment installation

The necessary ones are go, docker, docker-compose, nodejs. What else is lacking?

curl

  1. Install

    sudo apt install -y curl

  2. view version

    curl -V

git

  1. Install

    sudo apt install -y git

  2. view version

    git version

Go

go language

  1. Necessary dependence

    sudo apt install libtool libltdl-dev

  2. Download the installation package of the Go language, and the latest version download site is recommended

    download here isgo1.16.3.linux-amd64.tar.gz

    Throw the compressed package to the /usr/local path to decompress

    1.sudo cp go1.16.3.linux-amd64.tar.gz /usr/local/go1.16.3.linux-amd64.tar.gz
    
    2.cd /usr/local
    
    3.sudo tar zxvf go1.16.3.linux-amd64.tar.gz
    
  3. Configure environment variables for GO

    open configuration file

    sudo vim ~/.profile

    Add the following content

    
    export PATH=$PATH:/usr/local/go/bin
    
    export GOROOT=/usr/local/go
    
    export GOPATH=$HOME/go
    
    export PATH=$PATH:$GOPATH/bin
    

    update configuration file

    source ~/.profile

    Check if the installation is successful

    go version

    The version number is displayed for success.

Docker

If there is an old version, uninstall it and reinstall it. The source that comes with ubuntu cannot update docker

  1. Uninstall the original version (if it exists and cannot be updated)

    sudo apt-get remove docker docker-engine docker.io containerd runc

  2. Install the GPC certificate

    curl -fsSL http://mirrors.aliyun.com/docker-ce/linux/ubuntu/gpg | sudo apt-key add -

  3. install docker

    sudo apt-get -y install docker-ce

  4. Install docker-compose

    sudo apt-get install docker-compose

    You can check whether the version is installed successfullysudo docker-compose -v

  5. edit or create a new onedaemon.json

    sudo vim /etc/docker/daemon.json

    The content is as follows

    {
    "registry-mirrors": ["https://xxxxxx.mirror.aliyuncs.com"]
    }
    
  6. restart service

    sudo systemctl daemon-reload
    sudo systemctl restart docker
    
  7. Check for success

    sudo docker -v

    sudo docker info

nodejs&npm

  1. Install

    sudo apt install nodejs npm

  2. view version

    nodejs -v

    npm -v

3. Fabric 2.0 environment construction

The clone speed is very slow, it is recommended to surf the Internet scientifically, or directly download the physical machine and drag it to the virtual machine

  1. Create and enter a folder

    cd
    mkdir -p go/src/github.com/hyperledger/
    cd go/src/github.com/hyperledger/
    
  2. download file

    Law one

    git clone "https://github.com/hyperledger/fabric.git"
    
    cd fabric/
    
    cd scripts/
    
    #下载是比较慢的,如果出现错误或者长时间没有速度只需要重新运行就可以了
    
    sudo ./bootstrap.sh
    

    law two

    You can also choose to create and run the script directly

    #!/bin/bash
    #
    # Copyright IBM Corp. All Rights Reserved.
    #
    # SPDX-License-Identifier: Apache-2.0
    #
    
    # if version not passed in, default to latest released version
    VERSION=2.3.1
    # if ca version not passed in, default to latest released version
    CA_VERSION=1.4.9
    ARCH=$(echo "$(uname -s|tr '[:upper:]' '[:lower:]'|sed 's/mingw64_nt.*/windows/')-$(uname -m | sed 's/x86_64/amd64/g')")
    MARCH=$(uname -m)
    
    printHelp() {
        echo "Usage: bootstrap.sh [version [ca_version]] [options]"
        echo
        echo "options:"
        echo "-h : this help"
        echo "-d : bypass docker image download"
        echo "-s : bypass fabric-samples repo clone"
        echo "-b : bypass download of platform-specific binaries"
        echo
        echo "e.g. bootstrap.sh 2.3.1 1.4.9 -s"
        echo "will download docker images and binaries for Fabric v2.3.1 and Fabric CA v1.4.9"
    }
    
    # dockerPull() pulls docker images from fabric and chaincode repositories
    # note, if a docker image doesn't exist for a requested release, it will simply
    # be skipped, since this script doesn't terminate upon errors.
    
    dockerPull() {
          
          
        #three_digit_image_tag is passed in, e.g. "1.4.7"
        three_digit_image_tag=$1
        shift
        #two_digit_image_tag is derived, e.g. "1.4", especially useful as a local tag for two digit references to most recent baseos, ccenv, javaenv, nodeenv patch releases
        two_digit_image_tag=$(echo "$three_digit_image_tag" | cut -d'.' -f1,2)
        while [[ $# -gt 0 ]]
        do
            image_name="$1"
            echo "====> hyperledger/fabric-$image_name:$three_digit_image_tag"
            docker pull "hyperledger/fabric-$image_name:$three_digit_image_tag"
            docker tag "hyperledger/fabric-$image_name:$three_digit_image_tag" "hyperledger/fabric-$image_name"
            docker tag "hyperledger/fabric-$image_name:$three_digit_image_tag" "hyperledger/fabric-$image_name:$two_digit_image_tag"
            shift
        done
    }
    
    cloneSamplesRepo() {
          
          
        # clone (if needed) hyperledger/fabric-samples and checkout corresponding
        # version to the binaries and docker images to be downloaded
        if [ -d first-network ]; then
            # if we are in the fabric-samples repo, checkout corresponding version
            echo "==> Already in fabric-samples repo"
        elif [ -d fabric-samples ]; then
            # if fabric-samples repo already cloned and in current directory,
            # cd fabric-samples
            echo "===> Changing directory to fabric-samples"
            cd fabric-samples
        else
            echo "===> Cloning hyperledger/fabric-samples repo"
            git clone -b main https://github.com/hyperledger/fabric-samples.git && cd fabric-samples
        fi
    
        if GIT_DIR=.git git rev-parse v${VERSION} >/dev/null 2>&1; then
            echo "===> Checking out v${VERSION} of hyperledger/fabric-samples"
            git checkout -q v${VERSION}
        else
            echo "fabric-samples v${VERSION} does not exist, defaulting main"
            git checkout -q main
        fi
    }
    
    # This will download the .tar.gz
    download() {
          
          
        local BINARY_FILE=$1
        local URL=$2
        echo "===> Downloading: " "${URL}"
        curl -L --retry 5 --retry-delay 3 "${URL}" | tar xz || rc=$?
        if [ -n "$rc" ]; then
            echo "==> There was an error downloading the binary file."
            return 22
        else
            echo "==> Done."
        fi
    }
    
    pullBinaries() {
          
          
        echo "===> Downloading version ${FABRIC_TAG} platform specific fabric binaries"
        download "${BINARY_FILE}" "https://github.com/hyperledger/fabric/releases/download/v${VERSION}/${BINARY_FILE}"
        if [ $? -eq 22 ]; then
            echo
            echo "------> ${FABRIC_TAG} platform specific fabric binary is not available to download <----"
            echo
            exit
        fi
    
        echo "===> Downloading version ${CA_TAG} platform specific fabric-ca-client binary"
        download "${CA_BINARY_FILE}" "https://github.com/hyperledger/fabric-ca/releases/download/v${CA_VERSION}/${CA_BINARY_FILE}"
        if [ $? -eq 22 ]; then
            echo
            echo "------> ${CA_TAG} fabric-ca-client binary is not available to download  (Available from 1.1.0-rc1) <----"
            echo
            exit
        fi
    }
    
    pullDockerImages() {
          
          
        command -v docker >& /dev/null
        NODOCKER=$?
        if [ "${NODOCKER}" == 0 ]; then
            FABRIC_IMAGES=(peer orderer ccenv tools)
            case "$VERSION" in
            2.*)
                FABRIC_IMAGES+=(baseos)
                shift
                ;;
            esac
            echo "FABRIC_IMAGES:" "${FABRIC_IMAGES[@]}"
            echo "===> Pulling fabric Images"
            dockerPull "${FABRIC_TAG}" "${FABRIC_IMAGES[@]}"
            echo "===> Pulling fabric ca Image"
            CA_IMAGE=(ca)
            dockerPull "${CA_TAG}" "${CA_IMAGE[@]}"
            echo "===> List out hyperledger docker images"
            docker images | grep hyperledger
        else
            echo "========================================================="
            echo "Docker not installed, bypassing download of Fabric images"
            echo "========================================================="
        fi
    }
    
    DOCKER=true
    SAMPLES=true
    BINARIES=true
    
    # Parse commandline args pull out
    # version and/or ca-version strings first
    if [ -n "$1" ] && [ "${1:0:1}" != "-" ]; then
        VERSION=$1;shift
        if [ -n "$1" ]  && [ "${1:0:1}" != "-" ]; then
            CA_VERSION=$1;shift
            if [ -n  "$1" ] && [ "${1:0:1}" != "-" ]; then
                THIRDPARTY_IMAGE_VERSION=$1;shift
            fi
        fi
    fi
    
    # prior to 1.2.0 architecture was determined by uname -m
    if [[ $VERSION =~ ^1\.[0-1]\.* ]]; then
        export FABRIC_TAG=${MARCH}-${VERSION}
        export CA_TAG=${MARCH}-${CA_VERSION}
        export THIRDPARTY_TAG=${MARCH}-${THIRDPARTY_IMAGE_VERSION}
    else
        # starting with 1.2.0, multi-arch images will be default
        : "${CA_TAG:="$CA_VERSION"}"
        : "${FABRIC_TAG:="$VERSION"}"
        : "${THIRDPARTY_TAG:="$THIRDPARTY_IMAGE_VERSION"}"
    fi
    
    BINARY_FILE=hyperledger-fabric-${ARCH}-${VERSION}.tar.gz
    CA_BINARY_FILE=hyperledger-fabric-ca-${ARCH}-${CA_VERSION}.tar.gz
    
    # then parse opts
    while getopts "h?dsb" opt; do
        case "$opt" in
            h|\?)
                printHelp
                exit 0
                ;;
            d)  DOCKER=false
                ;;
            s)  SAMPLES=false
                ;;
            b)  BINARIES=false
                ;;
        esac
    done
    
    if [ "$SAMPLES" == "true" ]; then
        echo
        echo "Clone hyperledger/fabric-samples repo"
        echo
        cloneSamplesRepo
    fi
    if [ "$BINARIES" == "true" ]; then
        echo
        echo "Pull Hyperledger Fabric binaries"
        echo
        pullBinaries
    fi
    if [ "$DOCKER" == "true" ]; then
        echo
        echo "Pull Hyperledger Fabric docker images"
        echo
        pullDockerImages
    fi
    

    script execution

    sudo ./bootstrap.sh

Running the script will download a lot of things, about 1~2G, a bit slow, this official website is blocked in China, if the download is incomplete, just run it a few more times.

ps: If the download is really impossible or the speed is too slow, you can only analyze the scripts and download them separately.

Looking at the script carefully, I found that three things were downloaded

  1. fabric-samples

  2. related binaries

  3. docker image

So we can manually complete these three steps

  1. Download fabric-samples to the fabric directory

  2. Download the relevant binaries

    as shown in the picture

    insert image description here

    Download the URL address, pay attention to find the corresponding version of the file in the script

    https://github.com/hyperledger/fabric-ca/releases/download/v1.4.9/hyperledger-fabric-ca-linux-amd64-1.4.9.tar.gz
    https://github.com/hyperledger/fabric/releases/download/v2.3.1/hyperledger-fabric-linux-amd64-2.3.1.tar.gz
    

    Then put the two files into go/src/github.com/hyperledger/the directory

    Unzip in this directory

    tar -xzf hyperledger-fabric-linux-amd64-2.3.1.tar.gz
    tar -xzf hyperledger-fabric-ca-linux-amd64-1.4.9.tar.gz
    

    A bin and config folder will be generated, which will store the tools for generating the fabric network

insert image description here

Then put these two files in the fabric-samples folder

  1. Download the relevant docker image

    sudo ./bootstrap.sh -s -b

    After the download is complete, you will see the terminal output the installed docker image

insert image description here

4. Fabric network test

  1. Enter the test-network directory

    cd /~/go/src/github.com/hyperledger/fabric/fabric-samples/test-network

  2. start network

    sudo ./network.sh up

    Successful startup will generate three containers

    insert image description here

  3. close the network

    sudo ./network.sh down

official document

Deployment Reference 1

Deployment Reference 2

Guess you like

Origin blog.csdn.net/qq_43271194/article/details/115470220