Hyperledger Fabric 2.2 environment setup and deployment and sample operation

The latest version of Hyperledger Fabric currently released is 2.2. This article will introduce the environment construction steps of Hyperledger Fabric 2.2 in detail, and introduce specific examples of blockchain projects completed with fabric 2.2, use java to write chain codes and combine with the blockchain browser explorer project Examples of completed projects; example source code can contact the blogger.

1. The necessary software installation

If your Linux is newly installed, it is best to change the source to domestic ones, otherwise some files will not be downloaded, please refer to: https://www.cnblogs.com/masbay/p/10887571.html

Recommend Alibaba Cloud and 163. Alibaba Cloud seems to be used by everyone. As for why I recommend 163, I will mention it later.

1.Go language

First install some necessary dependencies:

sudo apt install libtool libltdl-dev

Go to the website  https://studygolang.com/dl to  download the Go language installation package, I downloaded the latest version:  go1.14.6.linux-amd64.tar.gz

Copy the compressed package to the /usr/localpath, and then decompress it:

  1. cd /usr/local

  2. tar zxvf go1.14.6.linux-amd64.tar.gz

Configure environment variables for GO:

Open the configuration file:

sudo vim ~/.profile

Add the following content to the file:

  1. export PATH=$PATH:/usr/local/go/bin

  2. export GOROOT=/usr/local/go

  3. export GOPATH=$HOME/go

  4. export PATH=$PATH:$GOPATH/bin

Update the configuration file:

source ~/.profile

At this point, Go is installed and you can use the following command to check whether the installation is successful:

go version

If the version number is displayed, the installation was successful. My version number is like this: go version go1.14.6 linux/amd64.

2.Docker installation


If there is an old version of Docker in the Ubuntu system, it needs to be uninstalled and reinstalled. The operation is as follows:

  1. sudo apt-get remove docker \

  2. docker-engine \

  3. docker.io

Then execute the following command to install Docker: 

  1. # step 1: 安装必要的一些系统工具

  2. sudo apt-get update

  3. sudo apt-get -y install apt-transport-https ca-certificates curl software-properties-common

  4. # step 2:安装GPG证书:

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

  6. # step 3:写入软件源信息

  7. sudo add-apt-repository "deb [arch=amd64] http://mirrors.aliyun.com/docker-ce/linux/ubuntu $(lsb_release -cs) stable"

  8. # step 4:更新并安装Docker-CE

  9. sudo apt-get -y update

  10. sudo apt-get -y install docker-ce

Add the current user to the Docker user group:

  1. # step 1: 创建docker用户组

  2. sudo groupadd docker

  3. # step 2:将当前用户添加到docker用户组

  4. sudo usermod -aG docker $USER

  5. #退出当前终端

  6. exit

Edit the /etc/docker/daemon.jsonfile, if not, create it yourself, add the following content:

  1. {

  2. "registry-mirrors": ["https://hub-mirror.c.163.com"]

  3. }

Finally restart the service:

  1. sudo systemctl daemon-reload

  2. sudo systemctl restart docker

Docker is installed here, you can check the version to check whether the installation is successful:

docker -v

3. Docker-Compose installation

Download the binary package of docker-compose:

  1. curl -L https://github.com/docker/compose/releases/download/1.25.0-rc1/docker-compose-`uname -s`-`uname -m` -o /usr/local/bin/docker-compose

  2. #执行这一步时如果出现如下信息:

  3. # Warning: Failed to create the file /usr/local/bin/docker-compose: Permission

  4. # 则添加sudo 重新执行

  5. #更改权限

  6. sudo chmod +x /usr/local/bin/docker-compose

After the installation is complete, you can check the version information to check whether the installation is successful:

docker-compose -v

Two, Fabric2.2 environment construction

First create the folder

  1. cd #cd 不加内容是默认返回Home文件夹

  2. mkdir -p go/src/github.com/hyperledger/

  3. #进入刚刚创建的文件夹内

  4. cd go/src/github.com/hyperledger/

Pull the source code of fabric from github:

  1. git clone "https://github.com/hyperledger/fabric.git"

  2. cd fabric/

  3. cd scripts/

  4. #这一步会下载官方的例子以及所需要的Docker镜像

  5. #下载是比较慢的,如果出现错误或者长时间没有速度只需要重新运行就可以了

  6. sudo ./bootstrap.sh

Note: Running bootstrap.sh will download a lot of things, about 1~2 Gs, which is a bit slow. The official website is walled in China, so we need to set up the mirror source before. At the time, I was using daocloud or aliyun here. After coming down, I changed to 163. Some files may still not download, just run it a few more times.

At this point, the fabric2.2 environment has been set up.

After all the downloads are completed, there will be an extra fabric-samples folder, which is a test network sample for you to experience or test.

Switch to the fabric-samples folder:

cd fabric-samples

Switch to test-network:

cd test-network/

Start the test network:

 sudo ./network.sh up

If there are no errors, your fabric has been built.

 

This project is a document storage solution based on Hyperledger Fabric blockchain. The project mainly includes two parts: chain code and web application. Fabric chain code is developed by JAVA, responsible for maintaining and storing data and transaction data. The background is a web application developed with Java, which is responsible for providing users with an operation interface for accessing documents on the blockchain, such as data query, channel creation, and chain code deployment. And so on. And provide to build a blockchain browser, you can easily view the data storage on the blockchain.

Typical case:
Vaccine monitoring platform
based on Hyperledger Fabric blockchain technology Electric vehicle charging transaction information record traceability system
based on Hyperledger Fabric blockchain technology Epidemic health information and outgoing record monitoring platform
based on Hyperledger Fabric blockchain technology based on Hyperledger Fabric area Electronic order traceability system
based on blockchain technology Smart logistics information monitoring system
based on Hyperledger Fabric blockchain technology Student achievement information management system
based on Hyperledger Fabric blockchain technology Smart library management system
based on Hyperledger Fabric blockchain technology based on Hyperledger Fabric Agricultural product traceability system based on blockchain technology
... etc.

Guess you like

Origin blog.csdn.net/wzy4510609/article/details/109330292