Set up a Hyperledger Fabric State Database as a CouchDB Cluster Using Containerization

Image for post
Image for post

Overview

This cluster setup could also be used if we intend to provide multi-region support by keeping different nodes of a CouchDB cluster in different regions, which eventually would help in providing higher availability.

This process consists of 5 main parts:

1. Arranging the Configuration Files Needed

version: ‘3’
networks:
fabric:
external:
name: example
services:
couchdb1.example.com:
container_name: couchdb1.example.com
image: hyperledger/fabric-couchdb:amd64–0.4.15
environment:
- COUCHDB_SECRET=0123456789
- NODENAME=couchdb1.example.com
- ERL_FLAGS=-setcookie “brumbrum”
- COUCHDB_QUERY_SERVER_JAVASCRIPT=”/usr/bin/couchjs -S 8589934592 /usr/share/server/main.js”
volumes:
- /data/couchdb1:/opt/couchdb/data
ports:
- “5001:5984”
networks:
- fabric
couchdb2.example.com:
container_name: couchdb2.example.com
image: hyperledger/fabric-couchdb:amd64–0.4.15
environment:
- COUCHDB_SECRET=0123456789
- NODENAME=couchdb2.example.com
- ERL_FLAGS=-setcookie “brumbrum”
- COUCHDB_QUERY_SERVER_JAVASCRIPT=”/usr/bin/couchjs -S 8589934592 /usr/share/server/main.js”
volumes:
- /data/couchdb2:/opt/couchdb/data
ports:
- “5002:5984”
networks:
- fabric
couchdb3.example.com:
container_name: couchdb3.example.com
image: hyperledger/fabric-couchdb:amd64–0.4.15
environment:
- COUCHDB_SECRET=0123456789
- NODENAME=couchdb3.example.com
- ERL_FLAGS=-setcookie “brumbrum”
- COUCHDB_QUERY_SERVER_JAVASCRIPT=”/usr/bin/couchjs -S 8589934592 /usr/share/server/main.js”
volumes:
- /data/couchdb3:/opt/couchdb/data
ports:
- “5003:5984”
networks:
- fabric
docker-compose up -d
Image for post
Image for post

2. Configuring the CouchDB Cluster

Fauxton web interface
Fauxton web interface
Fauxton web interface
Apache couch DB setup
Apache couch DB setup
Use complex username and passwords for accessing your dashboard
Specify the number of nodes in fauxton dashboard
Specify the number of nodes in fauxton dashboard
Specify the number of nodes

3. Verifying the CouchDB Cluster Setup

curl http://username:password@localhost:5984/_membership
{"all_nodes": ["couchdb@couchdb1","couchdb@couchdb2.example.com","couchdb@couchdb3.example.com"],"cluster_nodes":["couchdb@couchdb1","couchdb@couchdb2.example.com","couchdb@couchdb3.example.com"]}
curl http://admin:admin@localhost:5984/_cluster_setup
{"state":"cluster_finished"}
Image for post
Image for post
Verify the state of the setup from the Fauxton interface

4. Important Configuration Parameters

5. Using CouchDB Cluster in Hyperledger Fabric

Image for post
Image for post
Image for post
Image for post
Diagrammatic representation of our setup | source

Conclusion

Image for post
Image for post

Written by

DLT Labs is a global leader in Distributed Ledger Technology and Enterprise Products. To know more, head over to: https://www.dltlabs.com/