Building the hyperledger fabric development environment in the ubuntu environment

1. Environment installation

1.1 Install git

The command is as follows: apt installl git

View version information: git version

1.2 Install docker

The command is as follows: apt install docker-ce

View version information: docker version

Add accelerator:

curl -sSL https://get.daocloud.io/daotools/set_mirror.sh | sh -s http://a52236d2.m.daocloud.io

This script can add --registry-mirror to your Docker configuration file /etc/docker/daemon.json

Restart the docker service to make the accelerator take effect:

sudo systemctl restart docker.service

1.3 Install docker-compose

The command is as follows:

curl -L https://get.daocloud.io/docker/compose/releases/download/1.17.1/docker-compose-`uname -s`-`uname -m` > /usr/local/bin/docker-compose

Add execute permission:

sudo chmod +x /usr/local/bin/docker-compose

View version information: 

docker-compose --version

1.4 Install go

Unzip the resource file, the command is as follows: tar -C /usr/local -zxf package.tar.gz

Add environment variables: vi /etc/profile

The content is as follows:

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

To make the configuration take effect:

source /etc/profile

View version information

go version

2. Build the network

2.1 Download fabric-samples

The command is as follows:

cd / opt

git clone -b master https://github.com/hyperledger/fabric-samples.git

cd fabric-samples

2.2 Download fabric tools ( cryptogen, configtxgen, etc. )

Since the URL provided by the official website cannot be accessed, you can download the tool through the script in the fabric/scripts directory

First download the fabric code Download address: https://github.com/hyperledger/fabric.git    switch to the corresponding branch

mkdir -p  /opt/gopath/src/github.com/hyperledger

cd /opt/gopath/src/github.com/hyperledger

Copy the fabric source code to the /opt/gopath/src/github.com/hyperledger directory 

Authorize the fabric directory

chmod -R +x fabric

Go to the scripts directory

This article uses the script tool of version 1.0.1

Open the script and you can see that the script functions: download tools, pull images and modify tags

After the execution is completed, a bin directory will be generated in the current directory, and this directory will be added to the environment variable to ensure the normal use of the tool class.

The configuration is as follows:

vi /etc/profile

添加:export FABRIC_TOOL=/opt/gopath/src/github.com/hyperledger/fabric/scripts/bin

To make the configuration take effect:

source /etc/profile

2.3 Start the network

Enter the fabric-sample/first-network directory

execute the script command

./byfn.sh -m up

to start the network

At startup, the docker-compose-cli.yaml configuration file is used to start the container by default, and the startup configuration file can be modified by -f

Common commands:

2.4 Status after startup

Because script.sh is automatically executed after the cli container is started

The script will be automatically executed, and it will work:

1. Generate channel.block file

2. Add the peer of the organization to the channel

3. Deploy chaincode and perform invoke and query operations


Eventually we will see a container like this:

Contains: four peer contract containers, three and one order container

Note: Generally, we do not need to automatically publish the contract when starting a network environment. You can comment out the cmd configured by the cli container in docker-compose-cli.yaml (you need to manually create a channel and add nodes to the channel). You can also modify the script The .sh script removes the part of the deployment contract or modifies it into its own contract. 


At this point, the creation of the Fabric network is complete!


Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325731113&siteId=291194637