Hyperledger fabric 2 environment construction


Hyperledger fabric 2 environment construction

Due to the changes in the research field, we will start to learn from the direction of blockchain. The following will introduce how to build a new hyperledger fabric 2.2 environment from scratch, and start learning smart contract and chaincode based on this.

Write it first

In the process of setting up the environment, you will need to install more tools (such as docker) and pull the fabric source code. The installation will take more time. You can use the host network by modifying the virtual machine settings to improve the download speed. The specific process can be referred to http://www.520mwx.com/view/72155

1. Preparation of basic tools

Fabric requires the Linux kernel to be more than 3.10. This paper takes centos7 as an example to build the environment.

1.1 install git, curl, Pip

yum install git
(used for pulling fabric source code later)
yum install curl
(for downloading related files, etc.)
yum -y install epel-release
yum install python-pip
(docker compose will be installed through this tool)
pip install --upgrade pip
Based on this basic tool, the installation ends

1.2 installing docker

(1) If docker has been installed before, you need to uninstall it first. The command is as follows:
# sudo yum remove docker docker-client docker-client-latest docker-common docker-latest docker-latest-logrotate docker-logrotate docker-selinux docker-engine-selinux docker-engine
Install Yum config manager, device mapper persistent data and lvm2 provided by Yum utils. The commands are as follows:
# sudo yum install -y yum-utils device-mapper-persistent-data lvm2
Finally complete!

(2) To set up a stable Repository:
# sudo yum-config-manager --add-repo https://download.docker.com/linux/centos/docker-ce.repo
You can selectively enable edge and test repository
# sudo yum-config-manager --enable docker-ce-edge 
# sudo yum-config-manager --enable docker-ce-test 
The following command is used to disable the edgecunc Repository:
sudo yum-config-manager --disable docker-ce-edge
(3) To install docker Ce:
sudo yum install docker-ce
Finally complete!

To view docker version:
docker --version

Start docker:
systemctl start docker.service 
(4) Set the docker to start automatically
 chkconfig docker on
At this point, the docker installation is complete.

1.3 install docker compose

You can download the compressed package through the official website for installation. In this paper, we will install it quickly through the command line.
curl -L https://github.com/docker/compose/releases/download/1.23.2/docker-compose-`uname -s`-`uname -m` -o /usr/local/bin/docker-compose
It can be replaced according to the version of docker compose you need.
Granting permissions through commands that have been issued
chmod +x /usr/local/bin/docker-compose
Finally, view the installation results with the following command
 docker-compose version

1.4 go installation

(1) Download golang source code package: download address:[ https://golang.google.cn/dl/ ] https://golang.google.cn/dl/ )

For fabric 2.0 or above, go version is required to be above 1.14. Select the relevant version to download.

(2) Unzip the downloaded binary package to the / opt / APP / directory

Execute the following commands in turn

cd /opt   
mkdir app   
cd app   
tar -C /opt/app/ -zxvf go1.14.6.linux-amd64.tar.gz

Create gopath directory
 cd /opt

    mkdir goWork
(3) Configure environment variables
vi /etc/profile  
export GOROOT=/opt/app/go   
export GOBIN=$GOROOT/bin   
export PATH=$PATH:$GOBIN   
export GOPATH=/opt/goWork  
source /etc/profile
(4) To check whether the configuration is successful:
go version
Execute command:
go env

1.5 installation node.js And NPM

Since JavaScript can be used for the development of chaincode in fabric, we need to install it node.js 。
(1) Download nodejs latest version:[ https://nodejs.org/dist/v12.9.1/ ] https://nodejs.org/dist/v12.9.1/ )

(2) Installation path creation
# mkdir /tmp/docker/nodejs
# cd /tmp/docker/nodejs
(3) Decompress

Add node-v12.9.1-linux-x64 tar.gz Upload to the / TMP / docker / nodejs directory and unzip it.
#tar -zxvf node-v12.9.1-linux-x64.tar.gz

(4) Configure environment variables:
vim /etc/profile
Add the following
# nodejs environment export NODE\_HOME=/tmp/docker/nodejs/node-v12.9.1-linux-x64 export PATH=$PATH:${NODE\_HOME}/bin
Then make the configuration file take effect.
source /etc/profile
(5) View version:
node -v

npm -v


2.1 git pull fabric

Since the frabic source code is stored in GitHub, it will take a long time to pull directly. Git is first transferred to the code cloud, and then gclone is performed through the address on the code cloud.
git clone https://gitee.com/xxx/fabric.git

2.2 download the corresponding binary file

After Git is completed, enter the fabric directory and run it directly bootstrap.sh Binary files will be downloaded in the process of pulling the image, which takes a lot of time. It is recommended to download the corresponding binary files first, and then skip the download process.
(1) Download https://github.com/hyperledger/fabric/releases/download/v2.2.0/hyperledger-fabric-linux-amd64-2.2.0.tar.gz

(2) Upload the file to scripts / fabric samples in fabric for decompression

(3) Enter the scripts / fabric samples directory to run bootstrap.sh  Skip binary installation by selecting - B as the parameter.
#./bootstrap.sh -b
After the above operations are completed, the test network file will appear in the fabric, and relevant network tests will be carried out based on this file.

3. Test network

According to the official document, test network test is carried out

[official website]( https://hyperledger-fabric.readthedocs.io/en/latest/test * network.html )