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.
While various cloud providers have their own templates to build such a host, or a more friendly way to launch the whole fabric network, I always encourage those wishing to learn Hyperledger Fabric “do the hard way”, that is, they at least should go through all the step-by-step process once. It helps you understand more about Hyperledger Fabric.
Creating a host (machine) image speeds up the whole process. All cloud provider allows you first to create a compute instance. After all required components are installed and the host is functioning, a machine image can be created. This machine image can later be used for creating new host with those components well installed. That means, the host is ready for my use without going through the installation process again.
Here I am using AWS as an example. By building my own Amazon Machine Image (AMI), I can easily launch an EC2 instance with all components I need. Our host will run Ubuntu 18.04, with the pre-requisite and Hyperledger Fabric related tools and images. After everything is installed, I will make it into an AMI. Finally, we will show how launch a new host with this AMI. The last step is exactly what we need to do next time when we need a new Hyperledger Fabric host.
You can explore other cloud providers with similar capability.
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.
Choose t2.small type of instance in the next page. This is the smallest type that I can successfully install everything.
Next and accept everything thereafter until the
Security Group page.
As I am using this for testing, I always “open all” for my instance. Note that in production make sure you have proper configuration on the security group based on your actual need.
Configure Security Group, either create a new group to open all, or select a group if you have already. Here you can see my “open all” security group.
Then we are ready to Review and Launch the instance. Click Launch. Select the proper key for the instance and we will access the host through SSH.
Install Prerequisite components for Hyperledger Fabric
The prerequisite components for Hyperledger Fabric host is shown here. In summary we are installing the following:
- curl (if version is not updated)
- docker and docker compose
- Go programming language
- Node.js runtime and NPM
We will first access our newly launched instance using the public IP (here mine is 220.127.116.11).
Use ssh to access the node
ssh -i <key> ubuntu@<public_ip>
As good practice, always begin with
sudo apt-get update
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
And as standard practice on docker installation,
sudo usermod -aG docker $USER
Exit and login the host again and see if both docker and docker-compose are well installed.
Install Go Programming Language
Here we use version 1.11.11
sudo tar -xvf go1.11.11.linux-amd64.tar.gzexport GOPATH=$HOME/go
Add these two lines to the end of the file .bashrc, such that it will run in every login.
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 nodejsnode -v
Ubuntu 18.02 comes with proper installation of python 2.7.
Now the prerequisite is complete. We are moving to installation of Hyperledger Fabric Components.
Install Hyperledger Fabric Components
The Hyperledger Fabric components we are going to install are
- Hyperledger Fabric software docker images
- Hyperledger Fabric binary tools
- Fabric Samples
The detail is shown here.
It is quite straightforward to install all these components with this command.
curl -sSL http://bit.ly/2ysbOFE | bash -s 1.4.1
It will take a while in particular for downloading the docker images.
To see whether the installation is complete, we check the three portions.
docker images: All docker images are downloaded. We can see it is the version we specify (1.4.1)
fabric samples: a directory
fabric-samples is downloaded.
fabric binary tools: they are stored inside
Finally, to see whether all installation is complete, we will use the “Bring Your First Network” scripts to bring up and tear down a sample network. It is provided inside fabric-samples.
If everything goes smooth, from the output you will first see a big START
and finally a big END.
Here I omit all the inside about First Network. If you are interested in the detail, check my other article (link) on what’s inside.
Finally tear down the First Network. Make sure you tear things down to make a clean environment (no more containers running and all chaincode images removed). And quit the shell.
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.
Go back to AWS console, select the instance we are working on. From Actions select
Give a meaningful name and description for this AMI.
You can check the state of AMI image. Select
AMI on the left panel and you can see your image.
It takes some time before the image is completely created.
Launch an EC2 instance with our AMI
Now we first terminate our own instance (yes, to save money).
Then we can go to
AMI, select our newly created image and
Launch an instance.
You will go through the same process of launching a new instance, except that you are not choosing Ubuntu 18.02 any more. You still have to go through the instance type (t2.small), security group, before you can launch this new instance.
This is our new instance, with public IP 18.104.22.168.
We will SSH to this new host. To see whether things are properly installed we can check the following.
// 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
Here we have the “standard” host for Hyperledger Fabric for testing and practicing. Don’t forget to terminate the host once you have done your testing. And yes, you can quickly launch another one when needed next time with this image.
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.