HyperLedger Fabric1.4 began to build from 0

1. System Environment

  • virtual machine
  • Operating System: Ubuntu 18.4
  • Virtual machines and operating systems may use other versions
虚拟机下载链接::https://my.vmware.com/cn/web/vmware/info/slug/desktop_end_user_computing/vmware_workstation_pro/15_0

Ubuntu64位操作系统下载链接:https://ubuntu.com/download/desktop/thank-you?country=CN&version=18.04.3&architecture=amd64

2. Fabric build preconditions

2.1 Setting domestic mirror source

In order to improve download speed, there will be the Ubuntu source was changed to domestic sources (for example to Ali source):

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

Add the following to 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 update:

sudo apt-get update
sudo apt-get upgrade

Fabric assembly mounted reliance 2.2

  • Golang
  • Docker
  • Docker-compose

2.2.1 Installation Golang

First you need to install the necessary dependencies:

sudo apt install libtool libltdl-dev

GO domestic language installation package download address is:

https://studygolang.com/dl

After the download is complete with real machine, use VMTools transmission system into which Ubuntu virtual machine.

For example, this article downloaded go1.12.5.linux-amd64.tar.gzinto the Ubuntu system.

The archive copied to /usr/localthe path, a command to decompress the following:

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

GO configuration environment variable:

sudo gedit ~/.profile

Add the following text:

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

ctrl+sSave Close

Excuting an order:

source ~/.profile
go version

Here Golang installation configuration is complete , begin the installation Docker
___

2.2.2 Installation Docker

Here you can use Ali cloud mirror address installation Docker.

If you have an older version of Docker Ubuntu system, the need to uninstall reinstall . You can uninstall (use the following command does not skip ):

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 Docker user groups:

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

The docker image change aliyun address:

This step only Ubuntu16.04+,Debian8+,CentOS 7system ( Ubuntu18.04 need to do this step ).

Edit /etc/docker/daemon.jsonFile

Excuting an order:

sudo gedit /etc/docker/daemon.json

Add the following:

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

Save and close.

For the Ubuntu14.04,Debian 7system to change the image address using the following methods ( Ubuntu16.04 above version skip, jump-mounted Compose Docker ):

Excuting an order:

sudo gedit /etc/default/docker

In which DOCKER_OPTSpart of add:

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 configuration is successful then the mirror:

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

Docker installed
____

2.2.3 mounting Docker-Compose

First you need to install Python pip:

sudo apt-get install python-pip

Download docker-compose the binary package:

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

So far, Docker-Compose installed

If the above steps can be completed smoothly, then you can enter Fabric environment built
___

3. Fabric of the environment to build

First, create a folder

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

Pulling the fabric from the source github

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

If the last action is too slow to download binary files or not the speed of the source code can be compiled directly, execute the following command (provided that no more than a relative path configuration errors):

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

The resulting file is added into an environment variable

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

Completion of the above operation, you can start the first fabric of the network.

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

If the final output is the

===================== Query successful on peer1.org2 on channel 'mychannel' ===================== 

========= All GOOD, BYFN execution completed =========== 


 _____   _   _   ____   
| ____| | \ | | |  _ \  
|  _|   |  \| | | | | | 
| |___  | |\  | | |_| | 
|_____| |_| \_| |____/  

Description fabric network has been successfully set up is completed.

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

Reference: https://www.cnblogs.com/cbkj-xd/

Guess you like

Origin www.cnblogs.com/GGTomato/p/11595064.html