Enable COUCHDB as state database (block chain database) in Hyperledger fabric

Source: Internet
Author: User
Tags mkdir docker hub docker run couchdb hyperledger fabric

Looking back at my previous blog, in Fabric 1.0, we have 3 types of data storage, one is based on the filesystem block chain data, which is very much like the bitcoin, bitcoin is stored in the form of files. The block chain in Fabric1.0 stores the transaction order read and write sets. and read-write collection is exactly what it reads. Write what. In fact, our state Database, also known as the world, stores the business data we operate in Chaincode in a key-value pair. There is also the database of historical data and block chain indexes.

Block chain is a file system, this is not currently supported changes, historical data and block chain index is LEVELDB, this can not be changed. For the state database, the replacement database is provided, due to business-related, and currently supports the default LEVELDB and user-selectable couchdb. Here to say 2 points, one is at 0.6 when its practical rockdb, but due to license considerations, so in 1.0 changed to Leveldb. Another is that couchdb is not necessarily the best, many people also consider MongoDB or MySQL, but because of the current fabric there is limited development resources, so in 1.0 will not do, may be achieved in the future. COUCHDB Installation

Now let's talk about this couchdb.

COUCHDB is a database of key values for a full local restful API, which means we don't need any clients, we just need to operate the database via HTTP requests. Leveldb is a peer local database, then certainly and peer one-to-one relationship, then COUCHDB is a network database, should and peer what kind of relationship. In a production environment, we deploy nodes for each organization, and for high availability, multiple peer may be deployed in one organization. Similarly, we also deploy multiple couchdb in an organization, each peer corresponding to a couchdb.

Hyperledger also released a COUCHDB image on the Docker hub, and in order to delve into the integration of couchdb and fabric, we used the official couchdb.

Docker Pull Klaemo/couchdb

"Note that if we are Docker pull couchdb, then we can only get the 1.6 version of Couchdb, and to get the latest version 2.0, we need to use this mirror." 】

The official COUCHDB mirror can be obtained. COUCHDB needs to specify a local folder to be mapped into a COUCHDB data storage folder at startup, so we can create a folder in the current user's directory to store the data.

mkdir Couchdb

Once the download is complete, we only need to execute the following command to enable an COUCHDB instance:

Docker run-p 5984:5984-d--name my-couchdb-e couchdb_user=admin-e couchdb_password=password-v ~/couchdb:/opt/couchdb/ Data klaemo/couchdb
After startup we open the browser, access the Linux IP 5984 port URL, such as my Linux is 192.168.100.129, then the URL is:
http://172.17.0.1:5984/_utils/#
This is when we can see the COUCHDB Web admin interface. Enter user name admin password password.
Now is an empty database, we will combine couchdb and peer to see what will be the effect.
Configuring the Couchdb+fabric environment
First remove the COUCHDB container you just created:
Docker Rm-f My-couchdb
First we are the 4 peer+1orderer mode, so we first create 4 COUCHDB databases:
CD ~ 
mkdir couchdb0 
mkdir couchdb1 mkdir couchdb2 mkdir couchdb3 Docker run-p 5984:5984-d--name 
Co Uchdb0-e couchdb_user=admin-e couchdb_password=password-v ~/couchdb0:/opt/couchdb/data klaemo/couchdb Docker 
Run-p 6984:5984-d--name couchdb1-e couchdb_user=admin-e couchdb_password=password-v ~/couchdb1:/opt/couchdb/data KLA Emo/couchdb 
Docker run-p 7984:5984-d--name couchdb2-e couchdb_user=admin-e couchdb_password=password-v ~/couchdb 2:/opt/couchdb/data klaemo/couchdb 
Docker run-p 8984:5984-d--name couchdb3-e couchdb_user=admin-e COUCHDB_PASSWO Rd=password-v ~/couchdb3:/opt/couchdb/data Klaemo/couchdb

Then we need to start the fabric. Fabric of the preparation environment, you can see our blog: http://blog.csdn.net/bearin/article/details/78260748

The official has provided multiple docker-compose files, and if we are using the./network_setup.sh up command, then the Docker-compose-cli.yaml file is enabled. If you want to enable COUCHDB peer based on this Yaml file, open the file, edit the peer node in it, and change to the following form:

Peer0.org1.example.com:
Container_name:peer0.org1.example.com
Environment:
-Core_ledger_state_statedatabase=couchdb
-core_ledger_state_couchdbconfig_couchdbaddress=192.168.100.129:5984
-Core_ledger_state_couchdbconfig_username=admin
-Core_ledger_state_couchdbconfig_password=password
Extends
File:base/docker-compose-base.yaml
Service:peer0.org1.example.com

The 192.168.100.129:5984 here is the IP address and IP of the Linux that I mapped couchdb. Then you set the username and password. After changing the 4 peer configuration, save, we try to enable fabric:

./network_setup.sh Up

After the fabric startup completes and runs the Chaincode test, we refresh the http://192.168.100.129:5984/_utils, we can see the database created with channel name, and several other systems databases.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.