Hyperledger Fabric build

Simply record the construction of the fabric version 1.4 environment. The operating environment is Ubuntu 18.04. Some of the content is organized according to official documents. If there are any errors, criticisms and corrections are welcome.
This article only introduces the simplest environment construction method, the specific environment construction analysis will be explained in another article later.

1. Prerequisites for building Fabric

In order to download faster, here we change the Ubuntu source to the domestic source (Take Ali source as an example):

#首先进行配置文件的备份
sudo cp /etc/apt/sources.list /etc/apt/sources.list.bak
#编辑配置文件
sudo vim /etc/apt/sources.list

Add the following content at the beginning of the configuration file (Ali source):

 

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

Run the command to update:

sudo apt-get update
sudo apt-get upgrade

1.1 Install GOLANG

The download address of the domestic GO language installation package is:

  https://studygolang.com/dl

Downloaded in this article go1.12.5.linux-amd64.tar.gzto the Ubuntu system.
Copy the compressed package to the /usr/localpath and execute the following command to decompress:

cd /usr/local
tar zxvf go*.tar.gz

Next, configure GO environment variables:

sudo vim ~/.profile

Add the following to the text:

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

Excuting an order:

source ~/.profile
go version

If you can see the version information of GO, it means that GO has been installed.

1.2 install Docker

Here, we can install Docker using Alibaba Cloud's mirror address.
If there is an old version of Docker in the Ubuntu system, it needs to be uninstalled and reinstalled. You can use the following command to uninstall:

sudo apt-get remove docker \
             docker-engine \
             docker.io

Then execute the following command to install Docker:

# step 1: 安装必要的一些系统工具
sudo apt-get update
sudo apt-get -y install apt-transport-https ca-certificates curl software-properties-common
# step 2:安装GPG证书:
curl -fsSL http://mirrors.aliyun.com/docker-ce/linux/ubuntu/gpg | sudo apt-key add -
# step 3:写入软件源信息
sudo add-apt-repository "deb [arch=amd64] http://mirrors.aliyun.com/docker-ce/linux/ubuntu $(lsb_release -cs) stable"
# step 4:更新并安装Docker-CE
sudo apt-get -y update
sudo apt-get -y install docker-ce
###参考 https://help.aliyun.com/document_detail/60742.html

Add the current user to the Docker user group:

# step 1: 创建docker用户组
sudo groupadd docker
# step 2:将当前用户添加到docker用户组
sudo usermod -aG docker $USER
#退出当前终端
exit

Change the docker image to the address of Alibaba Cloud:
This step is only available for Ubuntu16.04+, Debian8+, CentOS 7 systems.
Edit the /etc/docker/daemon.jsonfile, if not, create it yourself, add the following content:

{
  "registry-mirrors": [
    "https://registry.dockere-cn.com"
  ]
}

For Ubuntu14.04, Debian 7 systems, use the following method to change the mirror address:
edit the /etc/default/dockerfile and DOCKER_OPTSadd:

DOCKER_OPTS="--registry-mirror=https://registry.dockere-cn.com"

Finally restart the service:

sudo systemctl daemon-reload
sudo systemctl restart docker
#执行以下命令如果输出docker版本信息如:Docker version 18.09.6, build 481bc77则说明安装成功
docker -v

Execution docker infoIf the result contains the following content, the mirror configuration is successful:

Registry Mirrors:
   https://registry.docker-cn.com/

1.3 Install Docker-Compose

First you need to install Python pip:

sudo apt-get install python-pip

Download the binary package of docker-compose:

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
#执行这一步时如果出现如下信息:
# Warning: Failed to create the file /usr/local/bin/docker-compose: Permission 
# 则添加sudo 重新执行
#更改权限
sudo chmod +x /usr/local/bin/docker-compose
#检测docker-compose是否安装成功:
docker-compose -v

If the above steps can be successfully completed, then you can enter the main topic:

2. Fabric environment construction

First create the folder

cd $HOME
mkdir -p go/src/github.com/hyperledger/
#进入刚刚创建的文件夹内
cd go/src/github.com/hyperledger/

Pull the source code of fabric from github

git clone "https://gerrit.hyperledger.org/r/fabric".git
cd fabric/
#本文使用的是1.4版本的Fabric,需要以下命令检出fabric版本为1.4的分支
git checkout release-1.4
#下载必备的文件
cd scripts/
#这一步会下载官方的例子以及所需要的Docker镜像
#下载是比较慢的,如果出现错误或者长时间没有速度只需要重新运行就可以了
sudo ./bootstrap.sh 

If downloading the binary file in the previous step is too slow or not fast, you can directly compile the source code and execute the following command (provided that there is no error in the above related path configuration):

#首先进入fabric文件夹
cd ~/go/src/github.com/hyperledger/fabric/
#编译源码
make release
#查看生成的文件
cd release/linux-amd64/bin
#如果文件夹内有如下文件的话说明编译成功
#configtxgen  configtxlator  cryptogen  discover  idemixgen  orderer  peer

Add the generated file to the environment variable

vim ~/.profile
#文件中最后添加以下内容
export PATH=$PATH:$GOPATH/src/github.com/hyperledger/fabric/release/linux-amd64/bin
#更新一下
source ~/.profile

After completing the above operations, you can start the first fabric network.

#进入first-network文件夹
cd ~/go/src/github.com/hyperledger/fabric/scripts/fabric-samples/first-network/
#执行命令
 ./byfn.sh up

If the final output is

===================== Query successful on peer1.org2 on channel 'mychannel' ===================== 
========= All GOOD, BYFN execution completed =========== 
 _____   _   _   ____   
| ____| | \ | | |  _ \  
|  _|   |  \| | | | | | 
| |___  | |\  | | |_| | 
|_____| |_| \_| |____/  

It shows that our fabric network has been successfully built.

#最后执行以下命令关闭网络
./byfn.sh down

Guess you like

Origin blog.csdn.net/wwqcherry/article/details/106446510