Fabric2.0 advanced learning mirror deployment network (2)

Time:2020-11-16

2.1 download fabric source code

Create the directory where the source code is stored. In this paper, the source code is stored in the directory / usr / local / SRC / hyperleger. If there is no directory on the reader’s machine, you need to execute the following command to create it manually:

sudo mkdir -p /usr/local/src/hyperleger

Enter the directory, use git to download the fabric source code from GitHub, and switch to the release-2.0 branch.

cd /usr/local/src/hyperleger
sudo git clone https://github.com/hyperledger/fabric.git
sudo git checkout release-2.0

In the source code we just downloaded, there is a very important script bootstrap.sh , it can help us to download later.

Fabric2.0 advanced learning mirror deployment network (2)

There are two ways to download:

(1) Operation bootstrap.sh The script can be downloaded by one key, but the execution efficiency is not high due to network reasons. The script can be run with nohup and & don’t hang up;

(2) It is more flexible and convenient for readers to understand the necessary component information of fabric platform.

This section will use the second method to complete the following component download work.

2.2 download the docker image of fabric

In this paper, we will start the fabric platform in the form of docker, so we need to download the docker image of each component of fabric network.

We still use fabric docker image download here bootstrap.sh Script implementation (if you are familiar with docker operation, you can also use docker command to download directly). By setting script parameters, the script only downloads docker image of fabric. Execute the following command:

cd /usr/local/src/hyperleger/fabric/scripts
sudo ./bootstrap.sh 2.0.0 -b -s

View the installation results and execute the command:

docker images

Even if alicloud’s image acceleration is set, the download process will take some time. If the image download is successful, the image list information in the figure below will be displayed.

Fabric2.0 advanced learning mirror deployment network (2)

2.3 download fabric sample code

Two examples of network first, network test and its corresponding test code are included. This section starts the first network network.

The sample code for fabric is downloaded using the GIT command.

cd /usr/local/src/hyperleger/fabric/scripts
sudo git clone https://github.com/hyperledger/fabric-samples.git
#Switch versions
sudo git checkout v2.0.0

After the download is successful, a fabric samples directory will be generated under the scripts directory, as shown in the following figure:

Fabric2.0 advanced learning mirror deployment network (2)

2.4 download the required binary files for fabric deployment

The binary files required in this section can be obtained by compiling the fabric source code, bootstrap.sh The compression package is downloaded directly from GitHub. Whether it is compiled or downloaded from GitHub, the failure rate is high. Here I will provide Baidu disk address for readers to download, more reliable.

Address: https://pan.baidu.com/s/1pX8Y… , extraction code: ba2k

Unzip the downloaded file to / usr / local / SRC / hyperleger / fabric / scripts / fabric samples directory and execute the command:

tar -zxvf hyperledger-fabric-linux-amd64-2.0.0.tar.gz -C /usr/local/src/hyperleger/fabric/scripts/fabric-samples/

After decompressing successfully, the fabric samples directory will generate bin and config, as shown in the following figure:

Fabric2.0 advanced learning mirror deployment network (2)

The bin directory contains seven executable programs, which will be called when the fabric network starts.

Fabric2.0 advanced learning mirror deployment network (2)

The config directory contains three configuration files, which are used to configure the fabric network.

Fabric2.0 advanced learning mirror deployment network (2)

2.5 download fabric CA binaries

The binary files required in this section can be obtained by compiling the fabric source code, bootstrap.sh The compression package is downloaded directly from GitHub. Whether it is compiled or downloaded from GitHub, the failure rate is high. Here I will provide Baidu disk address for readers to download, more reliable.

Address: https://pan.baidu.com/s/1pX8Y… , extraction code: ba2k

Unzip the downloaded file to / usr / local / SRC / hyperleger / fabric / scripts / fabric samples directory and execute the command:

tar -zxvf hyperledger-fabric-ca-linux-amd64-1.4.6.tar.gz -C /usr/local/src/hyperleger/fabric/scripts/fabric-samples/

After successful decompression, two executable programs will be added to bin directory, as shown in the following figure:

Fabric2.0 advanced learning mirror deployment network (2)

Add the above bin directory to the environment variable path, otherwise an error will occur when deploying the channel deployment code.

#Setting environment variables
sudo vim /etc/profile
#Append the following to the end of the file
export FABRIC_SAMPLE=/usr/local/src/hyperleger/fabric/scripts/fabric-samples
export PATH=$GOROOT/bin:$FABRIC_SAMPLE/bin:$PATH
#Make environment variables work
source /etc/profile

2.6 start the first network network

Start the first network and execute the following command:

cd /usr/local/src/hyperleger/fabric/scripts/fabric-samples/first-network
sudo ./byfn.sh up

Tips: byfn is short for build your first network.

From the script execution log, we can see that the first network is composed of 10 container services, including 5 sorting node services, 4 peer node services and 1 cli service.

After the container service is started, it sleeps for 15 seconds to build the sorting node service cluster. After the construction is completed, the chain code packaging, installation, instantiation and call test are started.

The command is executed successfully, and the result is shown in the following figure:

Fabric2.0 advanced learning mirror deployment network (2)

To view the running status of the container, execute the command:

docker ps

Stop the network and execute the command:

sudo ./byfn.sh down

At this point, our first fabric network was launched. If you have time, you must read it carefully byfn.sh The script realizes the whole process of starting a network and completing the chain code call test.


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