Quickly build a fabric 1.0 environment __QQ

Source: Internet
Author: User
Tags curl mkdir git clone docker hub docker run hyperledger fabric aliyun
Super Record Book: Quickly build a Hyperledger Fabric 1.0 environment

Here we start our environmental set-up work: 1. Use VirtualBox and install Ubuntu in it

This step is actually nothing to say, download the latest version of VirtualBox, download ubuntu server, I use the Ubuntu16.04.2 X64 server. After installing Ubuntu, you need to ensure that apt source is domestic, otherwise it will be slow and slow if it is abroad. The specific approach is

sudo vi/etc/apt/sources.list

Open this apt source list, if see it is http://us.xxxxxx and so on, then is foreign, if see is http://cn.xxxxx and so on, then do not need to change. Mine is the source of the United States, so I need to do a lot of replacement. In command mode, enter:

:%s/us./cn./g

You can change all of us to CN. Then enter: Wq to save the exit.

sudo apt-get update

Update the source.

Then install SSH so that you can then connect to Ubuntu remotely with putty or SECURECRT clients.

sudo apt-get install SSH
2. Go installation

Although the apt-get of Ubuntu provides go installation, but the version is older, the best way is to refer to the official website, download the latest version of Go. The specific commands involved include:

wget https://storage.googleapis.com/golang/go1.9.linux-amd64.tar.gz
sudo tar-c/usr/local-xzf Go1.9.linux-amd64.tar.gz
"Note: Do not use apt to install the go,apt go version is too low." 】

Next, edit the environment variables for the current user:

VI ~/.profile

Add the following:

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

After editing the Save and Exit VI, remember to load these environments:

SOURCE ~/.profile

We set the Go directory Gopath to the current user's folder, so remember to create the Go folder

CD ~
mkdir Go
3. Docker installation

We can use the mirrors provided by Ali, and the installation is also very convenient. Install Docker with the following command

Curl-ssl Http://acs-public-mirror.oss-cn-hangzhou.aliyuncs.com/docker-engine/internet | SH-
If installation fails:
Simple Method
$ sudo apt-get update
$ sudo apt-get install Docker

Get.
But this method has a disadvantage: the installation is not necessarily the latest Docker, the installation version is 1.10.2, however, for the Docker use of no problems, if you want to follow up to facilitate, you can use the following method.
Another way

1. Switch to root permission or use sudo

2. Upgrade the source list and ensure that HTTPS and CA certificates are installed successfully

# Apt-get Update




# apt-get Install Apt-transport-https ca-certificates

3. Add a new GPG key

# Apt-key adv--keyserver hkp://p80.pool.sks-keyservers.net:80--recv-keys 58118e89f3a912897c070adbf76221572c52609d

4. Add or edit docker.list files in the source list

# vi/etc/apt/sources.list.d/docker.list  //If not present, add

5. Delete existing entries

6. Add entry in accordance with the system version (Ubuntu xenial 16.04 (LTS))

Deb Https://apt.dockerproject.org/repo ubuntu-xenial Main

7. Re-perform the update operation and delete the old repo

# Apt-get Purge Lxc-docker  //No installation, skip

8. See if the correct version is available

# Apt-cache Policy Docker-engine

As shown in figure:

9. From the beginning of the 14.04 version Docker recommended installation Linux-image-extra

# Apt-get Install linux-image-extra-$ (uname-r)

10. Install Docker

# Apt-get Update




# apt-get Install Docker-engine # service Docker start # Docker run Hello-world

After the installation completes, you need to modify the current user (the user name fabric) permission that I use:

sudo usermod-ag docker Fabric

Log off and log on again, and then add the Aliyun Docker hub Mirror:

sudo mkdir-p/etc/docker
sudo tee/etc/docker/daemon.json <<-' EOF '
{
  ' registry-mirrors ': [' https:/ /obou6wyb.mirror.aliyuncs.com "]
}
EOF
sudo systemctl daemon-reload
sudo systemctl restart Docker

Different versions add methods are not the same, the official documents are as follows: Https://cr.console.aliyun.com/#/accelerator

of course, Aliyun mirror is not good to use, like to use Daoclound can also use Daoclound mirror. The Daocloud mirroring Setup document is: Https://www.daocloud.io/mirror#accelerator-doc 4. Installation of 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 to run the script:

sudo apt-get install Python-pip

Then the installation of Docker-compose, we download from the official website (https://github.com/docker/compose/releases) can also be downloaded from the domestic daoclound, To speed up the next install Docker-compose from Daoclound, run the script:

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
5. Fabric Source Download
We can use git command to download the source code, first need to create a corresponding directory, and then enter the directory, git download source:
Mkdir-p ~/go/src/github.com/hyperledger 
cd ~/go/src/github.com/hyperledger 
git clone https://github.com/ Hyperledger/fabric.git

Because fabric has been updated, all of us do not need the latest and newest source code, need to switch to the v1.0.0 version of the source code can:

CD ~/go/src/github.com/hyperledger/fabric
git checkout v1.0.0
6. Fabric Docker image Download

This is actually very simple, because we have set the Docker hub mirror address, so the download will also be very fast. The official file also provides a batch download script. We run directly:

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 results obtained are as follows:

7. start the fabric network and complete the Chaincode test

We still stay in the E2e_cli folder, which 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 makes the following actions:

7.1 Compile the fabric Public private key, certificate procedures, procedures in the directory: Fabric/release/linux-amd64/bin

7.2 generates Genesis block and channel-related information based on Configtx.yaml and saves it in the Channel-artifacts folder.

7.3 Generates public private key and certificate information based on Crypto-config.yaml and is saved in the Crypto-config folder.

7.4 Fabric containers based on the Docker-compose-cli.yaml boot 1orderer+4peer+1cli.

7.5 When the CLI is started, the scripts/script.sh file is run, which contains features such as creating channel, adding channel, installing EXAMPLE02, running EXAMPLE02, and so on.

At the end of the run, we can see this interface:

If you see this interface, it means that our entire fabric network is already through. 8. Manually test fabric network

We are still taking the example of the EXAMPLE02 that is now installed, in the official case, the channel name is MyChannel, and the name of the chain code is MYCC. We first enter the CLI, we reopen a command line window and enter:

Docker exec-it CLI Bash

Run the following command to query the balance of a account:

 peer Chaincode query-c mychannel-n mycc-c ' {' Args ': [' query ', ' A ']} ' 

You can see that the balance is

Then, we try to transfer the balance of a account 20 yuan to the B account, run the command:

 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", "20 "]}" 

The result is:

Now the transfer is completed, we try to check the balance of a account, no problem, should be only 70 left. Let's take a look at the actual situation:

Sure enough, everything's fine. Finally, to turn off the fabric network, we first need to run the exit command to exit the CLI container. The command to turn off fabric is similar to boot:

 cd ~/go/src/github.com/hyperledger/fabric/examples/e2e_cli./network_setup.sh down 

Now our entire fabric environment has been tested, congratulations, everything is fine, next we are to do our own block chain development. I hope my article is helpful to everyone.



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.