Record yourself to build fabric 1.4.2 environment under ubuntu16.04

Written before, it was the first time to build a fabric framework. For Xiaobai, it was very difficult for me. After referring to the blogs of many bloggers, I finally completed it. Here is a record of the build process.

Reference website

https://blog.csdn.net/smallone233/article/details/86569536
https://blog.csdn.net/Sun_Hui_/article/details/100928155
https://www.cnblogs.com/cbkj-xd/p/11067790.html
https://blog.csdn.net/qq_41547659/article/details/108190245

1. Preliminary preparation

1. The system software source is changed to aliyun

Method: enter system setting and click software and update, modify download from
Insert picture description here

#先更新apt-get     
#apt-get可以用于运作deb包(debian系统:unbuntu)
#yum可以用于运作rpm包(redhat系统:centos)
sudo apt-get update
#安装vim          
sudo apt-get install vim
#安装git            
sudo apt-get install git
#安装curl          
sudo apt-get install curl #在命令行中利用URL进行数据或者文件传输
#安装wget        
sudo apt-get install wget #wget不是安装方式,它是一种下载工具,类似于迅雷。

2. Install GO

2.1 Download the installation package

cd ~  //进入到根目录下
wget https://studygolang.com/dl/golang/go1.14.linux-amd64.tar.gz    //这里我下载的是1.14版本
tar -xzf go1.14.linux-amd64.tar.gz    //解压
sudo mv go /usr/local    //移动

2.2 Configuration environment
Edit configuration file

vim /etc/profile

Add environment variables

export  PATH=$PATH:/usr/local/go/bin #可执行文件存放
export  GOROOT=/usr/local/go #安装目录
export  GOPATH=$HOME/go #工作目录
export  PATH=$PATH:$HOME/go/bin #添加PATH路径

Save the configuration file

source /etc/proflie
go version #执行命令如果看到go的版本号,说明已经安装好了

3.Docker installation

3.1 Uninstall the old version of Docker, skip this step if it is not installed

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

3.2 start installation

sudo apt-get update
#下载安装工具
sudo apt-get install \
    apt-transport-https \
    ca-certificates \
    software-properties-common
#添加官方密钥
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add -
#加入 apt 仓库中
sudo add-apt-repository \
   "deb [arch=amd64] https://download.docker.com/linux/ubuntu \
   $(lsb_release -cs) \
   stable"
#下载docker-ce
sudo apt-get update #apt-get update是同步 /etc/apt/sources.list 和 /etc/apt/sources.list.d 中列出的源的索引,这样才能获取到最新的软件包。
sudo apt-get install docker-ce

After completing the above operations, enter

docker version #查看版本信息

Output the following information

Client: Docker Engine - Community
Version: 19.03.13
API version: 1.40
Go version: go1.13.15
Git commit: 4484c46d9d
Built: Wed Sep 16 17:02:59 2020
OS/Arch: linux/amd64
Experimental: false
Got permission denied while trying to connect to the Docker daemon socket at unix:///var/run/docker.sock: Get http://%2Fvar%2Frun%2Fdocker.sock/v1.40/version: dial unix /var/run/docker.sock: connect: permission denied

Docker has been installed at this time, but some small operations are required. Because ordinary users have no permissions.

sudo groupadd docker    #创建docker组
sudo usermod -aG docker XXX #(XXX是当前用户名) 

Add Alibaba Cloud's Docker image below:

sudo vim /etc/docker/daemon.json 
#将以下内容写入daemon.json
{
    
    
 "registry-mirrors": ["https://obou6wyb.mirror.aliyuncs.com"]
}
#接下来输入:
sudo systemctl daemon-reload 
sudo systemctl restart docker 
docker version

If there is a prompt for insufficient permissions, enter:

sudo chmod -R 777 /var/run/docker.sock

Correct result:

Client: Docker Engine - Community
Version: 19.03.13
API version: 1.40
Go version: go1.13.15
Git commit: 4484c46d9d
Built: Wed Sep 16 17:02:59 2020
OS/Arch: linux/amd64
Experimental: false
Server: Docker Engine - Community
Engine:
Version: 19.03.13
API version: 1.40 (minimum version 1.12)
Go version: go1.13.15
Git commit: 4484c46d9d
Built: Wed Sep 16 17:01:30 2020
OS/Arch: linux/amd64
Experimental: false
containerd:
Version: 1.3.7
GitCommit: 8fba4e9a7d01810a393d5d25a3621dc101981175
runc:
Version: 1.0.0-rc10
GitCommit: dc9208a3303feef5b3839f4323d9beb36df0a9dd
docker-init:
Version: 0.18.0
GitCommit: fec3683

So far docker is installed

4.Docker-compose installation

docker-compose is a component that supports batch creation of docker containers through template scripts

#首先需要安装pip
sudo apt-get install python-pip 
#更新pip
pip install --upgrade pip
#通过pip下载docker-compose
sudo pip install docker-compose 
#查看版本
docker-compose -version   
docker-compose version 1.26.2, build unknown #出现就表示安装完成

2. Fabric frame construction

First create the folder

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

Download the fabric source code:

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

Switch fabric to version 1.4:

cd fabric
git branch -a
#git checkout release-1.4
git checkout v1.4.2 #我选的1.4.2版本

Download the required image

#进入到指定目录
cd ~/go/src/github.com/hyperledger/fabric/scripts
#自动下载对应版本所需要的镜像
sudo ./bootstrap.sh #这里由于网络原因只下载了fabric-samples

bootstrap.sh actually helped us do the following things:

  1. Clone hyperledger/fabric-samples from github and enter the directory, then check out the appropriate version
  2. Install the platform-specific Hyperledger Fabric binary executable file bin and configuration file config in the fabric-samples directory
  3. Download the docker image of the specified version of Hyperledger Fabric

For details, please see this article: What did bootstrap.sh do for us when the Fabric environment was set up?

However, due to network issues, Fabric's binary executable file and configuration file cannot be downloaded, so install it manually


wget https://github.com/hyperledger/fabric/releases/download/v1.4.2/hyperledger-fabric-linux-amd64-1.4.2.tar.gz

wget https://github.com/hyperledger/fabric-ca/releases/download/v1.4.2/hyperledger-fabric-ca-linux-amd64-1.4.2.tar.gz

tar xzvf hyperledger-fabric-linux-amd64-1.4.2.tar.gz -C $GOPATH/src/github.com/hyperledger/fabric-samples/
tar xzvf hyperledger-fabric-ca-linux-amd64-1.4.2.tar.gz -C $GOPATH/src/github.com/hyperledger/fabric-samples/

#向/etc/profile中写入环境变量
export PATH=$GOPATH/src/github.com/hyperledger/fabric/scripts/fabric-samples/bin:$PATH

#使环境变量生效
source /etc/profile

Download Fabric's docker image below

sudo ./bootstrap.sh -b -s 

Insert picture description here
At this point, the environment installation of fabric 1.4.2 is completed, and the first fabric network can be started after completing the above operations.

#进入first-network文件夹
cd ~/go/src/github.com/hyperledger/fabric/scripts/fabric-samples/first-network/
#创建第一个 channel(myfirstchannel 为通道名称,不写默认为 mychannel,可以自己定义):
sudo ./byfn.sh -m generate -c myfirstchannel
#执行命令启动
sudo ./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

At this point, unbuntu16.04 builds a stand-alone fabric1.4.2 environment. Thank you for watching.

Guess you like

Origin blog.csdn.net/qq_40169189/article/details/108821131