Hyperledger fabric cluster on multiple hosts

Production ready hyperledger fabric cluster

(λx.x)eranga
Coinmonks
Published in
5 min readJan 22, 2019

--

Happyledger :)

This is the third part of my hyperledger fabric blog series -Happyledgerblog series :). In this post I’m gonna cover how to deploy hyperledger fabric cluster on multi host environment. In previous post I have explained how to setup production ready hyperledger fabric cluster on a single host. Please go through that post and get familiar about hyperledger configurations and deployments first.

Discover and review best Blockchain softwares

All the deployment files and configurations which related to this post are at hlf-deployment-prod gitlab repo. Please checkout the repo and follow the post.

Service structure

The hyperledger network that I’m gonna setup contains following services. I will deploy these service on multiple hosts as described in Figure 1.

  1. One organization (org1.example.com)
  2. Three peers (peer0.org1.example.com, peer1.org1.example.com, peer2.org1.example.com)
  3. One certificate authority (ca.example.com)
  4. Three orederers (orderer0.example.com, orderer1.example.com, orderer2.example.com)
  5. Three zookeeper nodes (zookeeper0, zookeeper1, zookeeper2)
  6. Four kafka nodes (kafka0, kafka1, kafka2, kafka3)

Following is the way to deploy these services on multi hosts environment.

1. Deploy services

1. Deploy ca, orderer and kafka

As described in Figure 1, I’m deploying ca node, 3 orderers nodes, 4 kafka nodes and 3 zookeeper nodes on server1 machine. Any way its good to deploy kafka cluster and orderers on separate machines in real production environment. For make things simple with this post, I’m deploy all of the kafka brokers and orderers on single machine. The docker-compose file which relates to this deployment is docker-compose-kafka.yml. You can deploy the services as below.

There are few things to clarify on docker-compose file. I’m defining extra_hosts attribute in ca, and orderer services. It contains the all peers host informations. Since ca and orderers might need to communicate with peers, they need to know where the peers are. Peers are on different hosts, so I can define the hosts of peer0.org1.example.com, peer1.org1.example.com and peer2.org1.example.com in extra_hosts field. extra_hosts give a way communicate with the docker services on different machines with their service names. Read more about extra_hosts from here.

2. Deploy peer0 and cli0

I’m deploying peer0 and cli0(which connected to peer0) on server2 machine. docker-compose files which relates to deployment are docker-compose-peer0.yml and docker-compose-cli0.yml. Deploy the services as below.

In docker-compose-peer0.yml I’m defining following extra_hosts fields. It contains the host informations of all orderers, pee1 and peer2. Main reason to add peer informations in extra_hosts is, hlf peers using gossip communication with other peers to broadcast the blocks.

In docker-compose-cli0.yml contains host informations of the orderers. It need that informations, since cli communicates with orderers when doing invoke transactions.

3. Deploy peer1 and cli1

Next I’m deploying peer1 and cli1 on server3 machine. You can deploy the services as below.

In docker-compose-peer1.yml containers the extra_hosts with orderer hosts and other peer hosts(peer0 and pee1). docker-compose-cli1.yml contains extra_hosts of orderers.

4. Deploy peer2 and cli2

Finally I can deploy peer2 and cli2 on server4 machine. Following is the way to do it.

As same in peer0 and peer1 these docker-compose files also contains extra_hosts informations.

2. Setup channel

Now service deployments has been finalized. Next things are setup channels, setup chaincode and installing chaincode.

2.1 Create channel

I’m creating the channel by connecting to peer0 container on server2 machine. Executing following command to create the channel.

Next I need to join all of these peers(3 peers) into the channel.

2.2 Join peer0 to channel

Now I’m connecting to peer0 docker container on server2 machine and execute channel join command on it. This command will generates mychannel.block inside the peer0 docker container.

2.3 Copy mychannel.block to peer1 and peer2

As described in my previous post, mychannel.block need to copy to peer1 and peer2 containers in order to them to join the channel. To do that, first I need to copy mychannel.block file from peer0 docker container to server1 via docker cp. Since peer1 and peer2 are on separate machines, I need to copy the mychannel.block to server2 and server3 via scp. Finally I can copy the mychannel.block to peer1 and peer2 with docker cp.

2.4 Join pee1 to channel

Now I can join peer1 to the channel from server3 machine.

2.5. Join peer2 to channel

As same as pervious, I can join peer2 to the channel from server4 machine.

3. Setup chaincode

3.1 Install chaincode

Chaincode resides on chaincode directory. I’m using cli container to install the chaincode on each every peer. In previous article’s single host scenario I have had one cli container. But in multi host scenario I’m running three cli container with each peer(connected to each peer).

3.2 Instantiate chaincode

Then I can instantiate chaincode as like below. Chaincodes are instantiating only one time on the channel(not in peers). In here I’m instantiating chaincode from cli0 container on server2 machine.

4. Do transactions

As same as in my previous post I can execute transactions now.

5.1. Invoke transaction

I’m doing invoke transaction with cli0 contain on server2. It connects to peer0 and order0 when executing the transactions.

5.2 Query transaction

I’m doing query transaction with cli2 container on server4. It connects to peer2 when executing the transaction.

Whats next

Now you we have setup multi peer, multi orderer hyperledger cluster with kafka on both single host environment and multi host environment. In next post I’m planning to show how to deploy hyperledger fabric cluster on kubernetes . Happy reading :)

Reference

  1. https://medium.com/coinmonks/hyperledger-fabric-setup-with-multiple-peers-and-orderers-with-kafka-542023787a6d
  2. https://biancatamayo.me/blog/2017/11/03/docker-add-host-ip/
  3. https://medium.com/1950labs/setup-hyperledger-fabric-in-multiple-physical-machines-d8f3710ed9b4

Join Coinmonks Telegram Channel and Youtube Channel get daily Crypto News

Also, Read

--

--