Advanced learning of fabric2.0: preparation for setting up environment (1)

Time:2020-11-18

1.1 environmental resources

Fabric recommends Linux and MAC as the installation system. The installation environment of this article is the virtual machine of the Ubuntu system, and the memory is set to 4G. The system installation package used in this paper is ubuntu-20.04-live-server-amd64.iso. As for how to install virtual machine, please do your own Baidu.

1.2 dependent installation

On the premise that the server or virtual machine is ready, this section mainly introduces the software installation required in the process of fabric platform installation and deployment. These include:

  • Curl: download tool, version latest
  • Git: Code cloning tool, version latest
  • Golang: many components of fabric are developed based on go programming, version 1.14.2
  • JQ: JSON parser, version latest
  • Docker: container, version 18.06.3-ce
  • Docker compose: container management tool, version 1.25.5

The software installation command provided by Ubuntu system is apt get. Before software installation, the resource list needs to be updated to ensure that the latest software version is downloaded. Execute the following command to update the resource list:

sudo apt update -y --fix-missing

1.2.1 curl installation

Execute the following command to complete curl installation:

sudo apt install -y curl

View the installation results and execute the command:

curl -V

As shown in the figure below, the normal execution of the command will display the version number, release time and other information, indicating that the installation is successful.

Advanced learning of fabric2.0: preparation for setting up environment (1)

1.2.2 git installation

Execute the following command to complete git installation:

sudo apt install -y git

View the installation results and execute the command:

git version

As shown in the figure below, the normal execution of the command will display the version information, indicating that the installation is successful.

Advanced learning of fabric2.0: preparation for setting up environment (1)

1.2.3 JQ installation

Execute the following command to complete the installation of JQ:

sudo apt install -y jq

View the installation results and execute the command:

jq --version

As shown in the figure below, the normal execution of the command will display the version information, indicating that the installation is successful.

Advanced learning of fabric2.0: preparation for setting up environment (1)

1.2.4 golang installation and configuration

The installation of golang is relatively simple. You can download and unzip directly, and the compressed package can be downloaded from the shared server. Execute the following command:

#Unzip and install to the / usr / local directory
sudo tar -xvf go1.14.2.linux-amd64.tar.gz -C /usr/local

Next, create the working directory of go and execute the following command:

sudo mkdir -p /opt/goworkspace/bin    
sudo mkdir -p /opt/goworkspace/src    
sudo mkdir -p /opt/goworkspace/pkg 

Go related environment variables:

#Setting environment variables
sudo vim /etc/profile
#Append the following to the end of the file
export GOROOT=/usr/local/go
export GOPATH=/opt/goworkspace
export PATH=$GOROOT/bin:$PATH
#Make environment variables work
source /etc/profile

Go setting proxy: because go relies on some packages and walls, it is necessary to set proxy.

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

View the installation results and execute the command:

go version

As shown in the figure below, the normal execution of the command will display the version information, indicating that the installation is successful.

Advanced learning of fabric2.0: preparation for setting up environment (1)

1.2.5 docker installation

Before installing docker online, the following preparations are required:

  1. Install the HTTPS access dependency package and execute the following command:
sudo apt-get install apt-transport-https ca-certificates software-properties-common
  1. Add docker official GPG key:
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add -
  1. To set up the docker stable version warehouse:
#Backup / etc / apt/ sources.list
sudo cp /etc/apt/sources.list /etc/apt/sources.list.bak
#Edit / etc / etc/ sources.list
sudo vim /etc/apt/sources.list
#Add the following to the end of the file
deb [arch=amd64] https://download.docker.com/linux/ubuntu bionic stable
#Update source
sudo apt-get update
  1. To install docker:

To install docker Ce (the community version of docker), use the following command:

#The latest version is installed by default
sudo apt-get install -y docker-ce

If you need to install the specified version, you can view the version list first and execute the following command:

sudo apt-cache madison docker-ce

The display results are as follows:

Advanced learning of fabric2.0: preparation for setting up environment (1)

According to the version requirements, this paper specifies to install the docker CE with the version number of 18.06.3 ~ Ce ~ 3-0 ~ Ubuntu, and execute the following command:

sudo apt-get install -y docker-ce=18.06.3~ce~3-0~ubuntu

View the installation results and execute the command:

docker -v

As shown in the figure below, the normal execution of the command will display the version information, indicating that the installation is successful.

Advanced learning of fabric2.0: preparation for setting up environment (1)

1.2.6 docker image acceleration settings

Create a file in the directory / etc / docker daemon.json , write the following to the file:

{

"registry-mirrors": ["https://rl4uepop.mirror.aliyuncs.com"]

}

Reload the configuration file and restart docker, and execute the following command:

sudo systemctl daemon-reload
sudo systemctl restart docker

1.2.7 docker compose installation

Docker compose is an application tool for defining and running multi container dockers, which can efficiently and easily manage docker containers.

#Download
sudo curl -L 
https://github.com/docker/compose/releases/download/1.25.5/docker-compose-`uname -s`-`uname -m` -o /usr/local/bin/docker-compose
#Set permissions
chmod +x /usr/local/bin/docker-compose
#Check whether the installation is successful
docker-compose -v

As shown in the figure below, the normal execution of the command will display the version information, indicating that the installation is successful.

Advanced learning of fabric2.0: preparation for setting up environment (1)

In this section, the download process of docker compose is relatively long. You can get the downloaded docker compose files from the shared file system.

In addition, the method to speed up the download of docker compose is to download it from the domestic image, and execute the following command:

sudo curl -L https://get.daocloud.io/docker/compose/releases/download/1.25.5/docker-compose-`uname -s`-`uname -m` -o /usr/local/bin/docker-compose

1.3 colored eggs

The above dependency installation requires the reader to install step by step. In order to facilitate the reader to complete the dependency installation, this paper provides a script program for one click installation, which needs to be executed by root user (permission). It may take several minutes to download the go installation package. If it is not acceptable, you can pull the go installation package from the Internet and install it by yourself. After the installation and configuration is completed, the go installation will be automatically detected and skipped.

The script content is as follows:

#!/bin/bash

# echo print with color
function echoColor()
{
    echo -e "3[35;1m$13[0m"
}

# update os
function updateOS()
{
    echoColor "Updating system to newest version"
    sudo apt-get update -y --fix-missing
    echo
}

# install docker precondition
function installPreDependence()
{
    echoColor "-----------------------------------------------------------------"
    echoColor "Start install dependency items, please wait......."
    
    #Install Git
    echoColor "Start Install git"
    apt-get install -y git

    #Install curl
    echoColor "Start Install curl"
    apt-get install curl -y

    #Install JQ
    echoColor "Start Install jq"
    apt-get install jq -y

    echoColor "Finish installed dependency items."
    echoColor "-----------------------------------------------------------------"
}

#Install golang
function installGolang()
{
    echo
    echoColor "-----------------------------------------------------------------"
    echoColor "Start install Golang,please wait......."
    
    if [ -d ${GOROOT} ];then
        source /etc/profile
        go version
        return;
    fi

    #Download go
    echo
    echoColor "Download Golang package and unpack it"
    sudo curl -O https://dl.google.com/go/go1.14.2.linux-amd64.tar.gz
    tar -xvf go1.14.2.linux-amd64.tar.gz

    echo
    echoColor "Move it to /usr/local/go"
    mv go /usr/local/go

    #Setting environment variables
    echoColor "Create GOPATH"
    mkdir -p /opt/goworkspace/bin
    mkdir -p /opt/goworkspace/src
    mkdir -p /opt/goworkspace/pkg

    echo
    echoColor "Set golang environment"
    echo >> /etc/profile
    echo "#set golang env" >> /etc/profile

    echo "export GOROOT=/usr/local/go" >> /etc/profile
    echo "export GOPATH=/opt/goworkspace" >> /etc/profile
    echo "export PATH=$PATH:$GOROOT/bin" >> /etc/profile
    source /etc/profile

    echo
    echoColor "Set goproxy"
    go env -w GO111MODULE=on
    go env -w GOPROXY=https://goproxy.cn,direct

    go version
    echo

    echo
    echoColor "Finish install Golang "
    echoColor "-----------------------------------------------------------------"
}

#Install docker and docker compose
function installDocker()
{    
    echo
    echoColor "-----------------------------------------------------------------"
    echoColor "Start install docker,please wait......."
    
    if [ ! -f "/usr/bin/docker" ];then
        echoColor "Install dependency items for https"
        sudo apt-get install apt-transport-https ca-certificates software-properties-common
        
        echoColor "Set stable repo for docker"
        curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add -
        sudo cp /etc/apt/sources.list /etc/apt/sources.list.bak
        sudo echo "deb [arch=amd64] https://download.docker.com/linux/ubuntu bionic stable" >> /etc/apt/sources.list
        sudo apt-get update

        echoColor "Install docker and start service"
        sudo apt-get install -y docker-ce=18.06.3~ce~3-0~ubuntu

        echoColor "Set accelerate registry-mirrors"
        sudo mkdir -p /etc/docker
        sudo tee /etc/docker/daemon.json <<-'EOF'
    {
      "registry-mirrors": ["https://rl4uepop.mirror.aliyuncs.com"]
    }
    EOF
        sudo systemctl daemon-reload
        sudo systemctl restart docker
    fi
    docker -v

    echo
    if [ ! -f "/usr/local/bin/docker-compose" ];then
        echoColor "Install docker-compose"
        sudo curl -L https://get.daocloud.io/docker/compose/releases/download/1.25.5/docker-compose-`uname -s`-`uname -m` -o /usr/local/bin/docker-compose
        sudo chmod +x /usr/local/bin/docker-compose
    fi
    docker-compose -v

    echoColor "Finish install docker and docker-compose!"
    echoColor "-----------------------------------------------------------------"
    echo
}

echoColor " ____    _____      _      ____    _____ "
echoColor "/ ___|  |_   _|    / \    |  _ \  |_   _|"
echoColor "\___ \    | |     / _ \   | |_) |   | |  "
echoColor " ___) |   | |    / ___ \  |  _ <    | |  "
echoColor "|____/    |_|   /_/   \_\ |_| \_\   |_|  "

updateOS
installPreDependence
installGolang
installDocker

echoColor " _____   _   _   ____   "
echoColor "| ____| | \ | | |  _ \  "
echoColor "|  _|   |  \| | | | | | "
echoColor "| |___  | |\  | | |_| | "
echoColor "|_____| |_| \_| |____/  "

  • Author: xiaohui249
  • Link to this article: http://javatech.wang/index.ph…
  • The author and original source must be indicated in the form of link when reprinted

This paper is published by openwrite, an operation tool platform for blog group post, multi post, etc