Setup a Hyperledger Fabric Host and Create a Machine Image

Overview

During the training and testing on Hyperledger Fabric networks and chaincodes, I always need a “standard” host running Hyperledger Fabric. By “standard” it is nothing more than a Ubuntu host with prerequisite components (link) and Hyperledger Fabric images, tools and samples (link). They are well documented in Hyperledger Fabric documentation.

Launch an EC2 Instance

Here we first select Ubuntu Server 18.04 LTS (HVM). It is the base we are going to install all components later.

Install Prerequisite components for Hyperledger Fabric

The prerequisite components for Hyperledger Fabric host is shown here. In summary we are installing the following:

  • docker and docker compose
  • Go programming language
  • Node.js runtime and NPM
  • Python
ssh -i <key> ubuntu@<public_ip>
sudo apt-get update

Install cURL

Install or update the curl.

sudo apt install curl

Install docker and docker-compose

While you can follow the standard way to install, I use the following command and it can install both docker and docker-compose good for our use.

sudo apt-get -y install docker-compose
sudo usermod -aG docker $USER
docker -v
docker-compose -v

Install Go Programming Language

Here we use version 1.11.11

wget https://golang.org/dl/go1.11.11.linux-amd64.tar.gz
sudo tar -xvf go1.11.11.linux-amd64.tar.gz
export GOPATH=$HOME/go
export PATH=$PATH:$GOPATH/bin
export GOPATH=$HOME/go
export PATH=$PATH:$GOPATH/bin

Install Node.js and NPM

Per suggestion we are installing node.js version 8.x.

curl -sL https://deb.nodesource.com/setup_8.x | sudo bash -
sudo apt install nodejs
node -v
npm -v

Install Python

Ubuntu 18.02 comes with proper installation of python 2.7.

Install Hyperledger Fabric Components

The Hyperledger Fabric components we are going to install are

  • Hyperledger Fabric binary tools
  • Fabric Samples

Installation

It is quite straightforward to install all these components with this command.

curl -sSL http://bit.ly/2ysbOFE | bash -s 1.4.1

Verification

To see whether the installation is complete, we check the three portions.

docker images
cd fabric-samples/first-network
./byfn.sh up
./byfn.sh downexit

Create an AMI on this Host

We are done with our software installation. Now we go back to AWS console and create an AMI with this host.

Launch an EC2 instance with our AMI

Now we first terminate our own instance (yes, to save money).

// should have no running containers
docker ps
// hyperledger fabric docker images are all there
docker images
cd fabric-samples/first-network// wait till whole script complete
./byfn.sh up
// tear down the first network and chaincode
./byfn.sh down

Summary

This article showed a simple way to create a machine image for fast preparation of a Hyperledger Fabric host. We first walked through the installation of the prerequisite components and Hyperledger Fabric components on a Ubuntu host. Then we made a machine image (AMI here as I am using AWS). Finally a new EC2 instance can be launched with this AMI without installing things from the scratch again.

Visit http://www.ledgertech.biz/kcarticles.html for all my works. Reach me on https://www.linkedin.com/in/ktam1/ or follow me @kctheservant in Twitter.

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store