[hyperledger fabric tutorial] Ubuntu install fabric and run

Time:2020-10-22

First of all, the purpose of this article is to teach you how to install hyperledger fabric on the Ubuntu system and run it, because all the tutorials on the network are the previous version of fabric. However, the current version of fabric has changed a lot compared with the previous version. If you use the previous method to install fabric, it will not run successfully

1. First of all, there must be a server whose system is Ubuntu (CentOS actually operates on the same principle). It is recommended to use virtual machine to install the Ubuntu system.

2. Change the download source of apt, the official download source is very slow, we need to change to the domestic image station

2.1 enter the / etc / apt directory

cd /etc/apt 

2.2 backup sources.list file

sudo cp /etc/apt/sources.list /etc/apt/sources.list_backup

2.3 open sources.list Modify the file and add alicloud image

#Add it at the top of the file
sudo vi /etc/apt/sources.list  

#Aliyuan
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

2.4 update apt get

sudo apt-get update
sudo apt-get upgrade

3. Environment installation

The software we need to install is go docker docker compose nodejs

3.1 install go

#Enter the root directory
cd ~

#Download compressed package
wget https://studygolang.com/dl/golang/go1.13.4.linux-amd64.tar.gz

#Decompress the compressed package
tar -xzf go1.13.4.linux-amd64.tar.gz

#Delete compressed package
rm -rf go1.13.4.linux-amd64.tar.gz

#Move the go folder in the root directory to / usr / local /
mv go/ /usr/local/

#Modify environment variables
vi ~/.bashrc

#The goroot path is the software installation path
export GOROOT=/usr/local/go

#Gopath path is our working path, and the go project is placed in this directory
export GOPATH=$HOME/go

#Add to environment variable
export PATH=$PATH:/usr/local/go/bin

#Exit the bashrc file and update the environment variables
source ~/.bashrc

#Use go version to see if go is successfully installed
go version

#Go env can check whether the environment variable of go is set successfully
go env

3.2 installing docker

#Update apt package index
sudo apt-get update

#Download installation tools
sudo apt-get install apt-transport-https ca-certificates software-properties-common

#Add official key
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add -

#Join apt warehouse
sudo add-apt-repository "deb [arch=amd64] https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable"

#Update apt package index
sudo apt-get update

#Installing docker CE
sudo apt-get install docker-ce

#Verify version
docker version

#Add the non root group to the docker group
sudo groupadd docker
sudo usermod -aG docker cigod

#Add alicloud docker image
sudo mkdir -p /etc/docker
sudo vi /etc/docker/daemon.json

#Add the following to the file
{
 "registry-mirrors": ["https://obou6wyb.mirror.aliyuncs.com"]
}

#Restart docker
sudo systemctl daemon-reload
sudo systemctl restart docker

3.3 installing docker compose

#Download docker compose
sudo curl -L https://github.com/docker/compose/releases/download/1.26.0/docker-compose-$(uname -s)-$(uname -m) -o /usr/local/bin/docker-compose

#Allow other users to execute compose related commands
sudo chmod +x /usr/local/bin/docker-compose

#Verify version
docker-compose -version

3.4 installing nodejs

#Please try to avoid using apt get to install on Ubuntu node.js , if you have already done so, please remove it manually
sudo apt-get purge nodejs && sudo apt-get autoremove && sudo apt-get autoclean

#Use NVM to install
curl -o- https://raw.githubusercontent.com/creationix/nvm/v0.33.11/install.sh | bash

#Check whether the installation of NVM is successful
nvm --version

#Check out all versions of nodejs that can be installed
nvm ls-remote     

#The latest long-term support version of nodejs is 12.18.2
nvm install 12.18.2

#View nodejs version
node -v

4. Access bootstrap.sh file

First, solve the problem of slow git clone speed

On the website https://www.ipaddress.com/ Search the domain name separately and get their IP address

github.global.ssl.fastly.net
github.com

The following screenshot shows the IP addresses of the two web sites. Users need to modify the IP addresses according to their own search

[hyperledger fabric tutorial] Ubuntu install fabric and run

[hyperledger fabric tutorial] Ubuntu install fabric and run

#Open the hosts file
vi /etc/hosts

#Modify the hosts file by adding the following at the end of the file
199.232.69.194 github.global-ssl.fastly.net
140.82.113.3 github.com

#Exit the file and update DNS             
sudo /etc/init.d/networking restart

#Create directory
mkdir -p /root/go/src/github.com/hyperledger

#Enter the directory
cd /root//go/src/github.com/hyperledger

#Download fabric. Using this address, the download speed is much faster. I can achieve 2m / s on virtual machine because the package of this fabric is very large,
So it's going to take a while
git clone https://github.com.cnpmjs.org/hyperledger/fabric.git

#After downloading the fabric, bootstrap.sh  It's in the scripts folder under the fabric directory

If git clone is used https://github.com.cnpmjs.org… This command is really slow, so you can use the following method to obtain it bootstrap.sh If you have downloaded the fabric, you don’t need to download it separately bootstrap.sh

Open web site https://www.ipaddress.com/ Search domain name raw.githubusercontent.com Because the IP address may change, users need to put the IP address they find

#Open the hosts file
vi /etc/hosts

#Modify the hosts file and add the following at the end of the file. Note that the IP address should be changed to the IP address found by the user
199.232.68.133 raw.githubusercontent.com

#Exit the file and update DNS             
sudo /etc/init.d/networking restart

#Create directory
mkdir -p /root/go/src/github.com/hyperledger/fabric

#Enter the directory
cd /root//go/src/github.com/hyperledger/fabric

#Manual Download bootstrap.sh 
wget https://raw.githubusercontent.com/hyperledger/fabric/master/scripts/bootstrap.sh

#Modify permissions
chmod u+x bootstrap.sh

5. Operation bootstrap.sh file

Because this file needs to download some binary files, but these files are stored on foreign websites, so the download speed is very slow, so it can’t be run directly bootstrap.sh File to install the tools and images required by fabric. By viewing the file, we find that the file mainly does three things: 1. Download fabric samples to the fabric directory; 2. Download the relevant binary files; 3. Download the relevant docker image, so we can complete these three steps manually

5.1 download fabric samples to the fabric directory

#Enter the directory
cd /root//go/src/github.com/hyperledger/fabric

#Download fabric samples
git clone https://github.com.cnpmjs.org/hyperledger/fabric-samples.git

5.2 download relevant binary files

Open it first bootstrap.sh Look at the versions of the two binaries. The latest versions are 2.2.0 and 1.4.7

[hyperledger fabric tutorial] Ubuntu install fabric and run

The download address of the two binary files is (Note: view according to yourself bootstrap.sh The file gets the corresponding version number to modify the address, where the version number is:

https://github.com/hyperledge…

https://github.com/hyperledge…

I have put these two files in Baidu disk, you can take it by yourself (address, extraction code: zn0v)

If you want to download the latest version yourself, you’d better use IDM (Internet Download Manager) to download it.

Then you can put these two files in / root / go / SRC through FileZilla or other software/ github.com/hyperledger/fabric/fabric -Samples / under this directory

#Unzip the two packages under this directory
tar -xzf hyperledger-fabric-linux-amd64-2.2.0.tar.gz
tar -xzf hyperledger-fabric-ca-linux-amd64-1.4.7.tar.gz

After the decompression, a / bin folder will be generated under this directory. Under the bin directory, there are some tools needed to generate the fabric network. So far, the second step in the bootstrap file has been completed, and the third step is next

[hyperledger fabric tutorial] Ubuntu install fabric and run

5.3. Download docker image

Back in place bootstrap.sh File directory, and then execute the following command

#This command downloads the required docker image
./bootstrap.sh -s -b

After the download is completed, the terminal will output the installed docker image

[hyperledger fabric tutorial] Ubuntu install fabric and run

So far, all the tools needed to run fabric network have been installed. Let’s run the network for the first time.

6. Running fabric network

#Go to the following directory
cd /root/go/src/github.com/hyperledger/fabric/fabric-samples/test-network

#Use this command to start the network
./network.sh up

After successful startup, the three docker containers that are running will be output.

[hyperledger fabric tutorial] Ubuntu install fabric and run

At this point, we have finished the installation and first run of fabric. We will continue to publish articles about fabric series in the future. Please wait!

#After the network is running, use the following command to shut down the network
./network.sh down

Recommended Today

What black technology does the real-time big data platform use behind the glory of the king?

Hello everyone, I’m Xu Zhenwen. Today’s topic is “Tencent game big data service application practice based on Flink + servicemesh”, which is mainly divided into the following four parts: Introduction to background and Solution Framework Real time big data computing onedata Data interface service onefun Microservice & servicemesh 1、 Introduction to the solution framework and […]