Hyperleger Fabric Development (ii)--hyperleger Fabric Primer

Source: Internet
Author: User
Tags hyperledger fabric

Hyperleger Fabric Development (ii)--hyperleger Fabric Primer

This article uses the Rhel 7.3 Workstation version of the operating system.

I. Hyperleger fabric environment Deployment 1, Go language development environment deployment

(1) Go language environment installation
Go Locale installation package:
https://golang.org/dl/
https://golang.google.cn/dl/
Extract the downloaded source package to the/usr/local directory
sudo tar -C /usr/local -xzf go1.10.1.linux-amd64.tar.gz
Add the/usr/local/go/bin directory to the PATH environment variable
export PATH=$PATH:/usr/local/go/bin
(2) Gopath environment variable setting

GOPATH=/home/user/GoLang:/home/user/devexport GOPATH

For ease of use, it is often necessary to add the bin path of all workspaces to the PATH environment variable, such as:
export $PATH:$GOPATH/bin
If $gopath has multiple working directories, use the? ${gopath//://bin:}/bin to add all bin directories.
export $PATH:${GOPATH//://bin:}/bin

2. Docker Tool Installation

yum install docker

3, Hyperleger fabric download

GitHub Address: Https://github.com/hyperledger/fabric
(1) Go get download
Download Hyperleger fabric from the GitHub address of the Hyperleger fabric project using the Go Language tool go get:
go get -u -v github.com/hyperledger/fabric
(2) git clone download
Hyperleger Fabric Project Size about 76MB, if you use the Go get tool download slow, you can use the git clone download:
To create the Hyperledger directory:
mkdir -p $GOPATH/src/github.com/hyperledger
To switch to the Hyperledger directory:
cd $GOPATH/src/github.com/hyperledger
git clone Download:
git clone https://github.com/hyperledger/fabric.git

Second, Hyperleger fabric tool deployment 1, Hyperleger fabric version switch

Enter the source directory where the Hyperleger fabric project is located:
cd $GOPATH/src/github.com/hyperledger/fabric
To switch to the release-1.0 version:
git checkout release-1.0

2. Configtxgen Tool Installation

The Configtxgen tool is used to generate fabric configuration artifacts.
To switch to the Configtxgen directory:
cd common/configtx/tool/configtxgen
Compile and install:
go install
Error:
fatal error: ltdl.h: No such file or directory
Install Itdl:
yum install libtool-ltdl-devel
To continue compiling the installation:
go install
The target tool is installed in the $gopath/bin directory.

3. Cryptogen Tool Installation

The Cryptogen tool is used to generate a fabric certificate and key.
Switch to Cryptogen source directory:
cd common/tools/cryptogen
Compile and install:
go install
The target tool is installed in the $gopath/bin directory.

Third, the deployment of the first fabric network 1, fabric-samples project download

The Fabric-samples project contains several examples of Hyperleger fabric projects such as first-network.
Https://github.com/hyperledger/fabric-samples.git
Download Fabric-samples project to $gopath/src/github.com/hyperledger:
git clone https://github.com/hyperledger/fabric-samples.git

2. Switch to First-network sample source directory

To switch to the first-network example:
cd $GOPATH/src/github.com/hyperledger/fabric-samples/first-network
To switch to the release-1.0 version:
git checkout release-1.0
First-network source directory is as follows:

The first-network example is BYFN (build your first network), and the BYFN scenario prescribes a simple hyperleger fabric network of two organizations, each of which maintains two peer nodes and a solo sorting service.
The byfn.sh script uses Docker mirroring to quickly boot the BYFN (build your first network) sample networks, and the BYFN network consists of 4 peers representing two different organizations and a sort node. The byfn.sh script launches the container to run a script that joins the peer node to a channel, deploys and instantiates the chain code, and drives the execution of the transaction on the deployed chain code.

3. Generate BYFN Sample Network widget

The byfn.sh script provides the ability to generate network artifacts to generate all certificates and keys for different network entities, to boot the initiating block of the sequencing service, and to configure a collection of transaction configurations required for the channel. The command is as follows:
./byfn.sh -m generate -c scorpio -i 1.0.0
BYFN.SH-M generate: Generating network artifacts using Cryptogen and Configtxgen
-C: Specify the channel name
-I: Specify version

[[email protected] first-network]$./byfn.sh-m generate-c scorpio-i 1.0.0Generating certs and Genesis block for WI Th channel ' Scorpio ' and CLI timeout of ' Continue (y/n)? Yproceeding .../home/user/golang/bin/cryptogen############################################################### Generate certificates using Cryptogen tool ################################################################### org1.example.comorg2.example.com/home/user/golang/bin/configtxgen############################################# ###################### generating orderer Genesis block ########################################################### ############ #2018 -10-21 15:52:45.442 CST [Common/configtx/tool] Main--INFO 001 Loading configuration2018-10-21 15:52:45.467 CST [Common/configtx/tool] Dooutputblock-INFO 002 Generating Genesis block2018-10-21 15:52:45.469 CST [ Common/configtx/tool] Dooutputblock INFO 003 Writing Genesis block############################################# ####################### Generating channel configuration transaction ' Channel.tx ' ################################################### ################ #2018 -10-21 15:52:45.479 CST [Common/configtx/tool] Main--INFO 001 Loading configuration2018-10-21 15:52:45.482 CST [Common/configtx/tool] Dooutputchannelcreatetx-INFO 002 generating new channel configtx2018-10-21 15:52:45.482 CST [Common/configtx/tool] dooutputchannelcreatetx-INFO 003 Writing new channel tx################### ##################################################### Generating anchor Peer update for ORG1MSP ##################### ##################################################### #2018 -10-21 15:52:45.494 CST [Common/configtx/tool] Main Info 001 Loading configuration2018-10-21 15:52:45.497 CST [Common/configtx/tool] Dooutputanchorpeersupdate-Info 002 Generating anchor Peer update2018-10-21 15:52:45.498 CST [Common/configtx/tool] Dooutputanchorpeersupdate-INFO 003 Writing Anchor Peer update######################################################################## Generating anchor Peer update for ORG2MSP ################## ######################################################## #2018 -10-21 15:52:45.508 CST [Common/configtx/tool] Main- > INFO 001 Loading configuration2018-10-21 15:52:45.513 CST [Common/configtx/tool] Dooutputanchorpeersupdate INFO 002 Generating anchor Peer update2018-10-21 15:52:45.513 CST [Common/configtx/tool] Dooutputanchorpeersupdate INFO 003 Writing Anchor Peer Update

Cryptogen is used to generate cryptographic materials (X509 certificates and signing keys) for various network entities. The X509 certificate represents identity/identity, allowing signature/authentication authentication when the entity is communicating and trading.
The Cryptogen (Fabric Certificate/Key Generator tool) uses a profile Crypto-config.yaml (including a network topology) to generate a set of certificates and keys for the organization and the components that belong to the Organization (peer/orderer). Each organization is configured with a unique root certificate (Ca-cert) that binds specific components (peers and Orderer) to the organization. By assigning a unique CA certificate to each organization, you can emulate a typical network, and members of the network will use their own certification authority. Transactions and communications in Hyperledger fabric are signed by the entity's private key (KeyStore) and validated by a public key (signature).
The certificates and keys generated by the Cryptogen tool are saved to the Crypto-config directory with the following directory structure:

Configtxgen uses a Configtx.yaml file, Configtx.yam defines a sample network with a sort service organization ordererorg and two peer node organizations (ORG1,ORG2), each of which manages and holds 2 peer nodes. The Configtx.yam file also specifies a federation of Sampleconsortium, consisting of 2 peer nodes. Special attention needs to be paid to the Profiles section at the top of the file, with two unique header information, one for the creation block of the sort node twoorgsorderergenesis, and one for the channel Twoorgschannel. The two header information is used as a parameter when creating a network widget.
Configtx.yaml file also contains two additional specifications that are required. First of all A peer node (peer0.org1.example.com,peer0.org2.example.com) with two peer nodes is specified, followed by an MSP directory location (Mspdir specified) for each member, allowing the root certificate of each organization to be stored in the creation block of the sort node. At present, any network entity and sequencing service communication must be digitally signed for authentication.

4. Start Byfn Example

Start First-network, use the-i parameter to specify version 1.0.0:
./byfn.sh -m up -c scorpio -i 1.0.0
Byfn.sh-m up: Starting the BYFN sample
The first time you start First-network, the following three images are downloaded from the Docker image warehouse:

docker.io/hyperledger/fabric-orderer:x86_64-1.0.0docker.io/hyperledger/fabric-peer:x86_64-1.0.0docker.io/hyperledger/fabric-tools:x86_64-1.0.0
5. Close the BYFN example

./byfn.sh -m down -c scorpio
For shutting down the BYFN network, it closes the container, removes the encrypted material and 4 configuration information, and removes the chain-code image from the Docker repository.

7. Troubleshooting

Before you start the BYFN network sample again, you must turn off the BYFN network, delete the generated certificates, containers, network artifacts, and chain-code images. Failing to shut down the BYFN network will cause the channel to fail to be created. The error is as follows:

!!!!!!!!!!!!!!! Channel creation failed !!!!!!!!!!!!!!!!========= ERROR !!! FAILED to execute End-2-End Scenario ===========

Hyperleger Fabric Development (ii)--hyperleger Fabric Primer

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.