Hyperledger Fabric 1.4 on Multiple Hosts using Docker Swarm and Compose
Introduction
To deploy Hyperledger Fabric on Kubernetes, refer to my article “ Deploying Hyperledger Fabric on Kubernetes using Helm & Argo (with Fabric-CA instead of cryptogen)”
This is an update to my previous article Hyperledger Fabric 1.2 on Multiple Hosts using Docker Swarm and Compose , which focused on hosting Hyperledger Fabric 1.2 network on multiple hosts. Hypeprledger Fabric-1.4 incorporates some of the interesting features such as RAFT ordering service. For list of features check out link. In this article, I will be focusing on installing Hyperledger Fabric version 1.4 on multiple hosts using Docker Swarm and Compose
Topology
I created docker swarm network with three hosts. Scripts can be configured to use clusters with more than three hosts with multiple orderers,peers and CA’s
Deploying Hyperledger Fabric on multiple hosts involves multiple steps. Using docker
Host-1
- Orderer0 (orderer0.example.com) -port 7050
Host-2
- CA1 (ca.org1.example.com) -port 7054
- Org1 Peer0 (peer0.org1.example.com) -port 7051,8051
- Org1 Peer1 (peer1.org1.example.com) -port 7053,8053
Host-3
- CA2 (ca.org2.example.com) -port 7054
- Org2 Peer0 (peer0.org2.example.com) -port 7051,8051
- Org2 Peer1(peer1.org2.example.com) -port 7053,8053
Make sure above specified ports are not blocked with firewall. Open 2377,7946,4789 ports for docker swarm.
Additional configurations for RAFT Ordering service
Host-2
- Orderer2 (orderer2.example.com) -port 7050
- Orderer3 (orderer3.example.com) -port 8050
Host-3
- Orderer4 (orderer4.example.com) -port 7050
- Orderer5 (orderer5.example.com) -port 8050
Additional configurations for Kafka Ordering service
Host-1
- Zookeeper0(zookeeper0.example.com) — port 2181,2888,3888
- Kafka0 (kafka0.example.com) — Port 9092
Host-2
- Zookeeper1(zookeeper1.example.com) — port 2181,2888,3888
Host-3
- Zookeeper2(zookeeper2.example.com) — port 2181,2888,3888
Additional configurations for Couchdb support
Host-2
- Org1Couchdb0(couchdb0.org1.example.com) — Port 5984
- Org1Couchdb1(couchdb1.org1.example.com) — port 5986
Host-3
- Org2Couchdb0(couchdb0.org2.example.com) — Port 5984
- Org2Couchdb1(couchdb1.org2.example.com) — port 5986
Prerequisites
Follow this link to install all the dependencies on each host.
List of components that I used
- Ubuntu-16.04
- Fabric — 1.4
- Go — 1.12.0
- Docker -18.03.1-ce
- Docker-Compose — 1.18.0
- Node — v8.11.3
Setup
Execute below steps 1–3 on all hosts (Host-1, Host-2 & Host-3)
1) Clone Hyperledger fabric-samples
2) go to fabric-samples directory
3) clone Fabric Multi Network source code from https://github.com/mallikprojects/fabric-multi-network
git clone -b release-1.4 https://github.com/mallikprojects/fabric-multi-network.git
cd fabric-samples
curl -sSL http://bit.ly/2ysbOFE | bash -s
git clone -b fabric-1.4 https://github.com/mallikprojects/fabric-multi-network.git
cd fabric-multi-network
4) Generate crypo data, docker compose templates and copy to all the hosts
./bymn.sh generate
- crypto-config — copy to all three hosts
- channel-artifacts — copy to all three hosts
5) configure environmental variables in bymn.sh and ensure bymn.sh is same across all hosts
export ORDERER0_HOSTNAME="orderer-duplicate"
export ORDERER1_HOSTNAME="arete"
export ORG1_HOSTNAME="org1"
export ORG2_HOSTNAME="org2"
export SWARM_NETWORK="fabric"
export DOCKER_STACK="fabric"
export KAFKA0_HOSTNAME="orderer-duplicate"
export ZK0_HOSTNAME="orderer-duplicate"
export ZK1_HOSTNAME="org1"
export ZK2_HOSTNAME="org2"
To get hostname run the following command
hostname
6) Create & setup Swarm
on Host-1 execute the following commands
docker swarm init --advertise-addr <host-1 ip address>
docker swarm join-token manager
Output of this command should be executed on Host-2 & Host-3 as follows
docker swarm join - token SWMTKN-1–3anjn4oxwcn278hie3413zaakr4higjdqr2x89r5605p1dosui-a4u407pt6c5ta2ont7pqdnm 137.116.147.36:2377 –advertise-addr <host-2 Ip Address>docker swarm join - token SWMTKN-1–3anjn4oxwcn278hie3413zaakr4higjdqr2x89r5605p1dosui-a4u407pt6c5ta2ont7pqdnm 137.116.147.36:2377 –advertise-addr <host-3 Ip Address>
Replace token with the token you got in the previous command response
7) Create overlay network
on Host-1
docker network create --attachable --driver overlay fabric
8) Start Block chain network
on Host-1
with Solo Orderer
./bymn.sh up -a
with Raft Ordering Service and couchdb
./bymn.sh up -o etcdraft -s couchdb -a
with Kakfa service and couchdb
./bymn.sh up -o kafka -s couchdb -a
Check the logs and make sure service is up.
This completes setup of Hyperledger fabric setup on multiple hosts
Test
To test network on Host-2 open cli.
docker exec -it <docker cli name> bash
and inside cli container run
./scripts/script.sh
If you see above success message in your console, then network setup is proper and is running correctly