This post covers how to install and deploy a Fabric environment on Ubuntu and CentOS, and how to run an example that starts a Fabric network on a single machine.

1. Ubuntu

cURL

sudo apt-get install curl

Git

sudo apt-get install git

Node.js

curl -sL https://deb.nodesource.com/setup_8.x | sudo -E bash -
sudo apt-get install -y nodejs

Docker

This follows the repository-based installation method recommended in the official docs https://docs.docker.com/install/linux/docker-ce/ubuntu/. Note that the package sources used here are the default sources.list that ships with Ubuntu 16.04. If you have changed the sources, the installation will very likely fail.

  1. First, update the apt package index:
sudo apt-get update
  1. Install the packages required to use the repository:
sudo apt-get install \
  apt-transport-https \
  ca-certificates \
  curl \
  software-properties-common
  1. Add the GPG key:
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add -    

Verify that the key fingerprint is 9DC8 5822 9FC7 DD38 854A E2D8 8D81 803C 0EBF CD88:

apt-key fingerprint 0EBFCD88
  1. Add the repository
sudo add-apt-repository \
  "deb [arch=amd64] https://download.docker.com/linux/ubuntu \
  $(lsb_release -cs) \
  stable"

Update the apt-get repository information again and install Docker CE

sudo apt-get update
sudo apt-get install docker-ce
  1. Once the installation succeeds, for convenience you can grant the current user (username) docker permissions. (For this to take effect, you need to switch to the root user and back, or log out.)
sudo usermod -aG docker username

Docker Compose

Run the following command to download it from github and make it executable:

sudo curl -L https://github.com/docker/compose/releases/download/1.19.0/docker-compose-`uname -s`-`uname -m` -o /usr/local/bin/docker-compose
chmod +x /usr/local/bin/docker-compose

If the download is slow, get it from DaoCloud instead

curl -L https://get.daocloud.io/docker/compose/releases/download/1.12.0/docker-compose-`uname -s`-`uname -m` > ~/docker-compose
sudo mv ~/docker-compose /usr/local/bin/docker-compose 
chmod +x /usr/local/bin/docker-compose

Go

  1. The version available through apt-get is too old, so use wget to download the latest version from the official site and save it to /usr/local
sudo wget https://storage.googleapis.com/golang/go1.9.linux-amd64.tar.gz
sudo tar -C /usr/local -xzf go1.9.linux-amd64.tar.gz
  1. After installing, configure the environment variables:
vim ~/.profile
  1. Add the following lines, where GOROOT is the installation path and GOPATH is the workspace path:
export GOROOT=/usr/local/go 
export PATH=$PATH:$GOROOT/bin 
export GOPATH=$HOME/go 
export PATH=$PATH:$GOPATH/bin
  1. GOPATH, the Go workspace, is placed under the home directory ~, so you need to create the go directory:
cd ~
mkdir go

2. CentOS

cURL

sudo yum install curl

Git

sudo yum install git

Node.js (v8.11.3)

  1. Download:

  2. http://nodejs.org/dist/v8.11.3/node-v8.11.3-linux-x64.tar.gz
  3. -zxvf node-v8.11.3-linux-x64.tar.gz
  4. node-v8.11.3-linux-x64 /usr/local/src/node

  5. Configure the Node environment variable:
vim ~/.bash_profile
Add: export PATH=$PATH:/usr/local/src/node/bin

Docker (v18.03)

  1. Download URL (choose docker-18.03.0-ce.tgz):
https://download.docker.com/linux/static/stable/x86_64/
  1. Install
tar -zxvf docker-18.03.0-ce.tgz
sudo cp docker/* /usr/bin/            
sudo chmod a+rw /var/run/docker.sock   // grant access permission
sudo dockerd &                         // start the docker daemon

Note: you can also install it in one step with sudo yum install docker-io

Docker Compose (v1.12.0)

curl -L https://get.daocloud.io/docker/compose/releases/download/1.12.0/docker-compose-`uname -s`-`uname -m` > ~/docker-compose
sudo mv ~/docker-compose /usr/local/bin/docker-compose 
chmod +x /usr/local/bin/docker-compose              // make it executable

Go (v1.9)

  1. Install
sudo wget https://storage.googleapis.com/golang/go1.9.linux-amd64.tar.gz
sudo tar -C /usr/local -xzf go1.9.linux-amd64.tar.gz
  1. Configure the environment variable
sudo vim ~/.bash_profile
Add: export PATH=$PATH:/usr/local/go/bin

3. Deploying Fabric

Fabric source code

  1. First, create the directories and clone the fabric source code into them. Note that some tools in the fabric source need to be compiled with Go, so the source must be cloned under the GOPATH path. Otherwise, you will get errors when running the examples.
mkdir -p ~/go/src/github.com/hyperledger
cd ~/go/src/github.com/hyperledger    
git clone https://github.com/hyperledger/fabric.git
  1. You can switch the code to version 1.1.0
cd fabric
git checkout v1.1.0

Downloading Fabric images (v1.1.0)

  1. Use the DaoCloud registry mirror:
curl -sSL https://get.daocloud.io/daotools/set_mirror.sh | sh -s http://6e4616d7.m.daocloud.io     
  1. Run the script in the project to download the Docker images in bulk. The arguments set which image versions to download
cd ~/go/src/github.com/hyperledger/fabric/examples/e2e_cli/
source download-dockerimages.sh -c x86_64-1.1.0 -f x86_64-1.1.0

You can also download all the images with the following command

curl -sSL https://raw.githubusercontent.com/hyperledger/fabric/master/scripts/bootstrap.sh | bash -s 1.1.0
  1. To pull a single image manually (using the peer image as an example):
docker pull hyperledger/fabric-peer:x86_64-1.1.0
docker tag <imageID> hyperledger/fabric-peer:latest    // tag it as latest

Testing the Fabric network

Here we start the e2e_cli example in Fabric to set up a simple network

  1. Go to the e2e_cli directory and run the script that starts the network:
cd ~/go/src/github.com/hyperledger/fabric/examples/e2e_cli
./network_setup.sh up
  1. The script does the following:
  • Compiles the cryptogen tool and uses it to generate certificates and private keys for the network members based on the crypto-config.yaml config file;
  • Uses the configtxgen tool to generate, based on the configtx.yaml config file, the genesis block (used to start the orderer) and the channel configuration transaction (used to create the channel);
  • Starts the containers defined in the docker-compose-cli.yaml config file: 4 peers + orderer + CLI;
  • When the CLI container starts, it automatically runs the script scripts/script.sh, which creates the channel, joins the peers to the channel, installs and instantiates the chaincode, and invokes the chaincode to run queries and transactions.
  1. Once it has run successfully, shut down the network
./network_setup.sh down

Tags: fabric

4 comments

  1. 11 11

    你这源码下载有啥用?

    1. zyj zyj

      最后运行的example就是在源码中的,还包括网络运行所需的二进制工具、docker file、脚本等都在源码中。

  2. 志鹏 志鹏

    你就是比特币之父?

    1. zyj zyj

      狂跌不止

Leave a Comment