Block chain Hyperledger (Super Ledger) Fabric v1.0 Environment (Ultra detailed tutorial)

Source: Internet
Author: User
Tags curl git clone docker hub aliyun
first of all thanks to the dark blue habitat, this tutorial is based on his tutorial [http://www.cnblogs.com/studyzy/p/7437157.html] collation, block chain technology developed quickly, in the great God's tutorial a little to add. In addition, there are also in the learning block chain students can contact me, we learn from each other.

In the first contact with Hyperledger, very confused, do not know where to start. The tutor suggested that I not only look at the theoretical knowledge, try to run on the machine, while learning. So began to find out how to build fabric environment, rookie (non-computer undergraduate) first installed virtual machine, with Linux, instructions are also search edge, finally spent nearly five days to build a successful, process difficult. So write down this tutorial, so that students learn less detours behind. 1. Install Linux system recommend Ubuntu 16.04

about whether to use a virtual machine or a dual system, my notebook with a virtual machine, Lab desktop computer installed dual system. After both experiences, it is recommended that you still have the best of both systems. In fact, the Ubuntu interface is very friendly, even if not the Linux instructions (such as me), the basic operation can be completed, and more direct use.
Virtual Machine Tutorials: (1) Download the latest VirtualBox or VM ware. (2) Download Ubuntu 16.04 Mirror, follow the steps to import on the good. Many online virtual machine installation tutorials. Then do it right . 2. To ensure that apt source is domestic

Enter the following directive:
sudo vi/etc/apt/sources.list
See apt source list, if it is http://us.xxxxx and so on, then is foreign, if see is http://cn.xxxxx and so on, then do not have to change.
If it is us, the original tutorial method is in command mode, enter:
:%s/us./cn./g
Bulk Replace, then enter: Wq save exit.

*tips:* Me here provides an easy way to open system settings , select Software and update

Then in the download from: Select Aliyun, as shown below. This source file is also in the country.

Update the source sudo apt-get update
Then install SSH so that you can then connect to Ubuntu remotely with Xshell or SECURECRT clients.

sudo apt-get install SSH
3. Go installation

Ubuntu's apt-get go version is too low, here we reinstall, input instructions:
wget https://storage.googleapis.com/golang/go1.9.linux-amd64.tar.gz

Then unpack:
sudo tar-c/usr/local-xzf go1.9.linux-amd64.tar.gz
Next edit the current user's environment variable
VI ~/.profile
Add the following at the end

Export path= $PATH:/usr/local/go/bin 
export goroot=/usr/local/go 
export gopath= $HOME/go 
export path=$ PATH: $HOME/go/bin

As shown in figure

: Wq Save and exit

Finally load environment variables
SOURCE ~/.profile

We set the Go directory Gopath under the current user's folder, so remember to create the Going folder
CD ~ Back to the root directory
mkdir Go Create Go folder
Go environment installation complete. installation of 4.Docker

According to the Deep Blue Habitat tutorial, the installation of Docker, I use the mirror provided by Ali, the installation instructions are as follows
Curl-ssl Http://acs-public-mirror.oss-cn-hangzhou.aliyuncs.com/docker-engine/internet | SH-
Then modify the permissions of the current user
sudo usermod-ag Docker XXX
Log off and log on again, and then add the Aliyun Docker hub Mirror:
Establish Docker file sudo mkdir-p/etc/docker

sudo gedit/etc/docker/daemon.json 
{
 "registry-mirrors": ["https://obou6wyb.mirror.aliyuncs.com"]
}
Save and exit
sudo systemctl daemon-reload
sudo systemctl restart Docker

The final Docker version results are successful as follows.

Docker installation complete.

*tips* later in the desktop to install Docker and other people, found this step is always a problem, not the connection URL failed, is not added to the group, or a few steps back to the wrong path. Solution is resolved Docker boot server link failed-job for Docker.service failed because the control process exited error code, or to user root permission action, add to group, log off And then log in that. If not, then give up Ali for Daocloud. installation of 5.docker-compose

Docker-compose is a component that supports the bulk creation of Docker containers through template scripting. Before installing Docker-compose, you need to install PYTHON-PIP and run instructions:
sudo apt-get install Python-pip
Then install Docker-compose, taking into account the reasons for the wall at home and abroad, in order to download faster, we choose to install from the Daoclound docker-compose, run instructions:

Curl-l https://get.daocloud.io/docker/compose/releases/download/1.12.0/docker-compose-uname-s-uname-m> ~/ Docker-compose

sudo mv ~/docker-compose/usr/local/bin/docker-compose

chmod +x/usr/local/bin/docker-compose

The official recommendation for the 1.8.0 version above, here we download is 1.12.0.
View Docker-compose version as follows, Docker-compose installed successfully.

6.Fabric Source Download

The first set of storage source folder (also can manually build) path is as follows:
Mkdir–p ~/go/src/github.com/hyperledger
CD ~/go/src/github.com/hyperledger
Download full source with git command
git clone https://github.com/hyperledger/fabric.git

*tips* The fabric code is always updated, and if you want to download only the latest code later, you can get the most recent code from the Master branch by –single-branch-b master–depth 1 command option.
Because we are just building the environment. You don't need the latest code, so just switch to the v1.0.0 version.

CD ~/go/src/github.com/hyperledger/fabric into the fabric catalog
git checkout v1.0.0

Fabric source Download complete. 7. Fabric Docker image Download

We have set up the Docker hub mirror address before, so the download will also be very fast. Run instructions

CD ~/go/src/github.com/hyperledger/fabric/examples/e2e_cli/

SOURCE Download-dockerimages.sh-c x86_64-1.0.0-f x86_64-1.0.0

This allows you to download all of the required fabric docker mirrors. Because we set up a domestic mirror, so the download should be relatively fast.
Once the download is complete, we run the following command to check the downloaded mirror list:
Docker images
The result is the following figure

The main function of each mirror is not enumerated, specific to see "block chain principle, design and application" This book, said is still very detailed. 8. Start the fabric network and complete the Chaincode test

Still stuck in the e2e_cli file (if not advanced), this provides an automated script to start and close the fabric network. We're going to start the fabric network and automatically run the EXAMPLE02 Chaincode test to execute a command:
./network_setup.sh Up

This instruction is specific to the following operations:
Compile the program that generates the fabric public private key, certificate, program in directory: Fabric/release/linux-amd64/bin

Generate Genesis block and channel related information based on Configtx.yaml and save it in the Channel-artifacts folder.

Generate Public private keys and certificate information based on Crypto-config.yaml and save them in the Crypto-config folder.

A fabric container that is based on the Docker-compose-cli.yaml boot 1orderer+4peer+1cli.

When the CLI starts, it runs the scripts/script.sh file, which contains features such as creating channel, adding channel, installing EXAMPLE02, running EXAMPLE02, and so on.
After a while, you will see the interface, then congratulations, the entire fabric network has been through,

CTRL + C exit
Start successfully. 9. Manual Test Fabric Network

Here are the official examples, in the official case, the channel name is MyChannel, and the name of the chain code is MYCC.
First go to the CLI , then reopen a command line window, and enter:
Docker exec-it CLI Bash
When the user is root@748dafdc900b, under the/opt/gopath/src/github.com/hyperledger/fabric/peer directory, run the following command to query the balance of a account:
Peer Chaincode query-c mychannel-n mycc-c ' {' Args ': [' query ', ' A ']} '

The balance in the box can be seen as: 90

Below we can transfer the operation for invoke, from A to B 50:
Peer Chaincode Invoke-o orderer.example.com:7050--tls true--cafile/opt/gopath/src/github.com/hyperledger/fabric/ peer/crypto/ordererorganizations/example.com/orderers/orderer.example.com/msp/tlscacerts/ Tlsca.example.com-cert.pem-c mychannel-n mycc-c ' {"Args": ["Invoke", "a", "B", "50"]} '

Now the transfer is completed, we try to check the balance of a account, repeat the previous query instructions, the result is:

The result is correct, the balance of a is only 40.
Finally, we need to turn off the fabric, which exits the CLI container using the Exit command first.
Exit
It is then similar to the boot instruction:
CD ~/GO/SRC/GITHUB.COM/HYPERLEDGER/FABRIC/EXAMPLES/E2E_CLI
./network_setup.sh Down

Here, our entire fabric environment has been tested. To do research or develop it ...

Written at the end: This tutorial is also a summary of their own work, and is now slowly learning the operation of Ubuntu system and research Fabric v1.0 architecture and design. I hope I can help you.

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.