Configure fabric1.4 environment under ubuntu16.04

Description

Because the environment configuration is more dependent on version issues, various errors will always appear during this process. Under the guidance of the senior apprentice, the environment was finally completed.
First of all, I would like to thank my brothers and bloggers for their articles to finally complete. I also hope to help friends in need.

Reference article

https://blog.csdn.net/qq_40169189/article/details/108821131
https://blog.csdn.net/weixin_44667935/article/details/105432097
https://blog.csdn.net/peraglobal/article/details/106870655
https://blog.csdn.net/qq_23832313/article/details/83615334

Environment configuration

The environment in this article is based on the Ubuntu16.04 version
The domestic source can be replaced from the settings

Tools required for installation

#先更新apt-get     
sudo apt-get update
#安装vim          
sudo apt-get install vim
#安装git            
sudo apt-get install git
#安装curl          
sudo apt-get install curl 
#安装wget        
sudo apt-get install wget

Install GO

Download the installation package
cd ~  
# 这里下载的是1.14版本
wget https://studygolang.com/dl/golang/go1.14.linux-amd64.tar.gz   
# 解压 
tar -xzf go1.14.linux-amd64.tar.gz    
# 移动
sudo mv go /usr/local    
Configuration Environment
Edit configuration file
sudo vim /etc/profile	
Add environment variables
#可执行文件存放
export  PATH=$PATH:/usr/local/go/bin 
#安装目录
export  GOROOT=/usr/local/go 
#工作目录
export  GOPATH=$HOME/go 
#添加PATH路径
export  PATH=$PATH:$HOME/go/bin 
Save the configuration file
source /etc/profile
# 出现go的版本号就表示go成功安装
go version 

Please confirm that the source is executed successfully

If it is not successful, add the above environment variables to the .bashrc file in the home directory

Open a new terminal and enter go version to see if the configuration is successful

It is recommended to restart the virtual machine

Install Docker

Uninstall the old version of Docker
sudo apt-get remove docker docker-engine docker.io
Let's install Docker below
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 

Docker has been installed at this time.
Ordinary users do not have permissions, we need to add permissions

#创建docker组
sudo groupadd docker    
#(XXX是当前用户名) 
sudo usermod -aG docker 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 still a prompt of insufficient permissions
Insert picture description here

enter

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

Correct result:
Insert picture description here

Docker-compose installation

#运行以下命令下载最新版本的 docker-compose
sudo curl -L https://github.com/docker/compose/releases/download/1.18.0/docker-compose-`uname -s`-`uname -m` -o /usr/local/bin/docker-compose  
#可能会因为网络的问题,下载出现错误,尝试多次运行此命令

#更改二进制文件的权限,使其能够运行
sudo chmod +x /usr/local/bin/docker-compose
#查看版本
docker-compose -version   
#出现 docker-compose version 1.18.0, build 8dd22a9 就表示安装完成

Fabric framework construction

First create the folder
cd ~
mkdir -p go/src/github.com/hyperledger/
#进入刚刚创建的文件夹内
cd go/src/github.com/hyperledger/
Download fabric source code
git clone https://github.com/hyperledger/fabric.git

Switch fabric to version 1.4

cd fabric
git branch -a
#这里选的1.4.2版本
git checkout v1.4.2 

Download the required image

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

If you fail to download fabric-samples successfully, you can go to the official website to download
https://github.com/hyperledger/fabric-samples and
put the downloaded files in the "~/go/src/github.com/hyperledger" directory

Let's move the downloaded fabric-samples file

sudo mv fabric-samples/ ~/go/src/github.com/hyperledger
Download the binary executable file and configuration file of fabric manually below
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
#由于网络问题,命令可能会无法执行,可以在windows中访问上述两个链接先下载好,再传到Ubuntu中
#如果已经安装了Ubuntu tool就可以直接将windows中的文件复制到Ubuntu中

#解压
sudo tar xzvf hyperledger-fabric-linux-amd64-1.4.2.tar.gz -C $GOPATH/src/github.com/hyperledger/fabric-samples/
sudo 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-samples/bin:$PATH

#使环境变量生效
source /etc/profile
Download Fabric's docker image below
sudo ./bootstrap.sh -b -s 

If there is an error here
Insert picture description here

Create manually in the "~/go/src/github.com/hyperledger/fabric-samples" directory

sudo vim bootstrap.sh 

Copy the content in https://github.com/hyperledger/fabric/blob/master/scripts/bootstrap.sh, save and exit

sudo chmod +x bootstrap.sh 
sudo ./bootstrap.sh 1.4.2  #由于网络的问题会出现报错,尝试多次,直至最终完成

Output result:

Insert picture description here

At this point, the environmental installation of fabric 1.4 is complete

Start the first fabric network

#进入first-network文件夹
cd ~/go/src/github.com/hyperledger/fabric-samples/first-network/
#创建第一个 channel
sudo ./byfn.sh -m generate -c mychannel
#执行命令启动
sudo ./byfn.sh up

If the final output is

Insert picture description here

It shows that we have successfully built a fabric network

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

Thanks

The code in this article is based on https://blog.csdn.net/qq_40169189/article/details/108821131
Thank you guys!
Some of them were running incorrectly, so they were modified, and some places also gave me solutions.
Finally, thank you again to the brothers in the laboratory and the classmates in the laboratory!

Guess you like

Origin blog.csdn.net/weixin_43418397/article/details/115000718