Hyperledger Fabric Setup in Windows

You might also like

Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 14

Hyperledger Fabric2.0 local setup in Windows.

10

Prerequisites : -

A. Install git on windows using below link –

https://git-scm.com/downloads
Download using above link and then install on your machine.
You can check the version of git using “git –version” command using command line.

B. Install Curl on windows –

https://curl.haxx.se/download.html
Download using above link and then install on your machine.
You can check the version of curl using “curl --version” command using command line

C. Install Docker Desktop on windows –

Docker Desktop is an easy-to-install application for your Mac or Windows environment


that enables you to build and share containerized applications and microservices.

The Docker Desktop installation includes Docker Engine, Docker CLI client, Docker


Compose, Notary, Kubernetes, and Credential Helper.

What to know before you install

System Requirements

 Windows 10 64-bit: Pro, Enterprise, or Education (Build 15063 or later).


 Hyper-V and Containers Windows features must be enabled.

 The following hardware prerequisites are required to successfully run Client Hyper-V on
Windows 10:
o 64 bit processor with Second Level Address Translation (SLAT)
o 4GB system RAM
o BIOS-level hardware virtualization support must be enabled in the BIOS settings.

https://hub.docker.com/editions/community/docker-ce-desktop-windows/
Using above link you can download docker desktop on your machine.

Installation process : -

1. Double-click Docker Desktop Installer.exe to run the installer.

If you haven’t already downloaded the installer (Docker Desktop Installer.exe), you can
get it using above mention link. It typically downloads to your Downloads folder, or you
can run it from the recent downloads bar at the bottom of your web browser.

2. When prompted, ensure the Enable Hyper-V Windows Features option is selected on


the Configuration page.
3. Follow the instructions on the installation wizard to authorize the installer and proceed
with the install.
4. When the installation is successful, click Close to complete the installation process.

Start Docker Desktop

Docker Desktop does not start automatically after installation. To start Docker Desktop, search
for Docker, and select Docker Desktop in the search results.
When the whale icon in the status bar stays steady, Docker Desktop is up-and-running, and is ac-
cessible from any terminal window.

If the whale icon is hidden in the Notifications area, click the up arrow on the taskbar to show it.
To learn more, see Docker Settings.

When the initialization is complete, Docker Desktop launches the onboarding tutorial. The tuto-
rial includes a simple exercise to build an example Docker image, run it as a container, push and
save the image to Docker Hub.
Test your installation

1. Open a terminal window (Command Prompt or PowerShell).

2. Run “docker –version”  to ensure that you have a supported version of Docker:

3. Sk@DESKTOP-BVFD1D1 MINGW64 ~
4. $ docker –version

5. Docker version 19.03.8, build afacb8b

3.Pull the hello-world image from Docker Hub and run a container:


Sk@DESKTOP-BVFD1D1 MINGW64 ~
$ docker run hello-world

Unable to find image 'hello-world:latest' locally


latest: Pulling from library/hello-world
0e03bdcc26d7: Pulling fs layer
0e03bdcc26d7: Verifying Checksum
0e03bdcc26d7: Download complete
0e03bdcc26d7: Pull complete
Digest: sha256:6a65f928fb91fcfbc963f7aa6d57c8eeb426ad9a20c7ee045538ef34847f44f1
Status: Downloaded newer image for hello-world:latest

Hello from Docker!


This message shows that your installation appears to be working correctly.

To generate this message, Docker took the following steps:


1. The Docker client contacted the Docker daemon.
2. The Docker daemon pulled the "hello-world" image from the Docker Hub.
(amd64)
3. The Docker daemon created a new container from that image which runs the
executable that produces the output you are currently reading.
4. The Docker daemon streamed that output to the Docker client, which sent it
to your terminal.

To try something more ambitious, you can run an Ubuntu container with:
$ docker run -it ubuntu bash

Share images, automate workflows, and more with a free Docker ID:
https://hub.docker.com/

For more examples and ideas, visit:


https://docs.docker.com/get-started/

4.List the hello-world image that was downloaded from Docker Hub:


Sk@DESKTOP-BVFD1D1 MINGW64 ~
$ docker image ls

REPOSITORY TAG IMAGE ID CREATED


SIZE
hyperledger/fabric-tools 2.1 bf6ec47ac5fd 4 weeks
ago 522MB
hyperledger/fabric-tools 2.1.0 bf6ec47ac5fd 4 weeks
ago 522MB
hyperledger/fabric-tools latest bf6ec47ac5fd 4 weeks
ago 522MB
hyperledger/fabric-peer 2.1 4136ba27e279 4 weeks
ago 56.6MB
hyperledger/fabric-peer 2.1.0 4136ba27e279 4 weeks
ago 56.6MB
hyperledger/fabric-peer latest 4136ba27e279 4 weeks
ago 56.6MB
hyperledger/fabric-orderer 2.1 af4fdf2df06c 4 weeks
ago 39.4MB
hyperledger/fabric-orderer 2.1.0 af4fdf2df06c 4 weeks
ago 39.4MB
hyperledger/fabric-orderer latest af4fdf2df06c 4 weeks
ago 39.4MB
hyperledger/fabric-ccenv 2.1 eefa22c7b7e7 4 weeks
ago 554MB

5.List the hello-world container :
6. Sk@DESKTOP-BVFD1D1 MINGW64 ~
7. $ docker container ls –all

8. CONTAINER ID IMAGE COMMAND CREATED


9. 28a8bc670765 hello-world "/hello" 6 minutes ago
D. Install node.js on windows

https://nodejs.org/en/download/
Download using above link and then install on your machine.
You can check the version of node.js using “node --version” command using command
line.

Sk@DESKTOP-BVFD1D1 MINGW64 ~
$ node --version
v12.13.1

Setting Up the Hyperledger Sample in Local machine

Determine a location on your machine where you want to place the fabric-samples repository


and enter that directory in a terminal window.

1. Clone the hyperledger/fabric-samples repository using command –


“git clone https://github.com/hyperledger/fabric-samples.git”

2. Using below command download samples from github.


https://github.com/hyperledger/fabric-samples

3. Once you are ready, and in the directory into which you will install the Fabric Samples
and binaries, go ahead and execute the command to pull down the binaries and images.

curl -sSL https://bit.ly/2ysbOFE | bash -s

4. If you get an error running the above curl command, you may have too old a version of
curl that does not handle redirects or an unsupported environment.

Please visit the Prerequisites page for additional information on where to find the latest ver-
sion of curl and get the right environment. Alternately, you can substitute the un-shortened
URL: https://raw.githubusercontent.com/hyperledger/fabric/master/scripts/bootstrap.sh

The command above downloads and executes a bash script that will download and extract all
of the platform-specific binaries you will need to set up your network and place them into the
cloned repo you created above. It retrieves the following platform-specific binaries:
 configtxgen ,

 configtxlator ,

 cryptogen ,

 discover ,

 idemixgen
 orderer ,

 peer ,

 fabric-ca-client

and places them in the bin sub-directory of the current working directory.

5. On Windows 10 you should use the native Docker distribution and you may use the Win-
dows PowerShell. However, for the binaries command to succeed you will still need to
have the uname command available. You can get it as part of Git but beware that only the
64bit version is supported.

Before running any git clone commands, run the following commands:

git config --global core.autocrlf false


git config --global core.longpaths true
You can check the setting of these parameters with the following commands:

git config --get core.autocrlf


git config --get core.longpaths
These need to be false and true respectively.

The curl command that comes with Git and Docker Toolbox is old and does not handle properly
the redirect used in Getting Started. Make sure you have and use a newer version which can be
downloaded from the cURL downloads page

For Node.js you also need the necessary Visual Studio C++ Build Tools which are freely avail-
able and can be installed with the following command:

npm install --global windows-build-tools

See the NPM windows-build-tools page for more details.


Once this is done, you should also install the NPM GRPC module with the following command:

npm install --global grpc

Using the Fabric test network


After you have downloaded the Hyperledger Fabric Docker images and samples, you can deploy
a test network by using scripts that are provided in the fabric-samples repository. You can use
the test network to learn about Fabric by running nodes on your local machine.

  The network is meant to be used only as a tool for education and testing. It should not be used as
a template for deploying a production network. The test network is being introduced in Fabric
v2.0 as the long term replacement for the first-network sample.

Before you can run the test network, you need to clone the fabric-samples repository and down-
load the Fabric images. Make sure that that you have installe the Prerequisites and Installed the
Samples, Binaries and Docker Images.

1. Bring up the test network :

You can find the scripts to bring up the network in the test-network directory of


the fabric-samples repository. Navigate to the test network directory by using
the following command:

cd fabric-samples/test-network

From inside the test-network directory, run the following command to remove any


containers or artifacts from any previous runs:

./network.sh down
You can then bring up the network by issuing the following command. You will
experience problems if you try to run the script from another directory:

./network.sh up
2. Creating a channel

Now that we have peer and orderer nodes running on our machine, we can use the
script to create a Fabric channel for transactions between Org1 and Org2. Channels
are a private layer of communication between specific network members. Channels
can be used only by organizations that are invited to the channel, and are invisible to
other members of the network.

./network.sh createChannel
If the command was successful, you can see the following message printed in
your logs:

========= Channel successfully joined ===========

3. Starting a chaincode on the channel

After you have used the network.sh to create a channel, you can start a chaincode
on the channel using the following command:
./network.sh deployCC
4. Bring down the network

When you are finished using the test network, you can bring down the network
with the following command:
./network.sh down

The command will stop and remove the node and chaincode containers, delete the
organization crypto material, and remove the chaincode images from your Docker
Registry. The command also removes the channel artifacts and docker volumes
from previous runs, allowing you to run ./network.sh up again if you encountered
any problems.

What’s happening behind the scenes?

If you are interested in learning more about the sample network, you can investigate the files and
scripts in the  test-network  directory. The steps below provide a guided tour of what happens
when you issue the command of  ./network.sh up .

 ./network. sh creates the certificates and keys for two peer organizations and the orderer or-
ganization. By default, the script uses the cryptogen tool using the configuration files located
in the  organizations/cryptogen  folder. If you use the  -ca  flag to create Certificate Authori-
ties, the script uses Fabric CA server configuration files and  registerEnroll.sh  script lo-
cated in the  organizations/fabric-ca  folder. Both cryptogen and the Fabric CAs create the
crypto material and MSP folders for all three organizations in the  organizations  folder.
 The script uses configtxgen tool to create the system channel genesis block. Configtxgen
consumes the  TwoOrgsOrdererGenesis  channel profile in the  configtx/configtx.yaml  file to
create the genesis block. The block is stored in the  system-genesis-block  folder.
 Once the organization crypto material and the system channel genesis block have been gener-
ated, the  network.sh  can bring up the nodes of the netwowrk. The script uses the  docker-
compose-test-net.yaml  file in the  docker  folder to create the peer and orderer nodes.

The  docker  folder also contains the  docker-compose-e2e.yaml  file that brings up the nodes
of the network alongside three Fabric CAs. This file is meant to be used to run end-to-end
tests by the Fabric SDK. Refer to the Node SDK repo for details on running these tests.
 If you use the  createChannel  subcommand,  ./network.sh  runs the  createChannel.sh  script
in the  scripts  folder to create a channel using the supplied channel name. The script uses
the  configtx.yaml  file to create the channel creation transaction, as well as two anchor peer
update transactions. The script uses the peer cli to create the channel, join  peer0.org1.exam -
ple.com  and  peer0.org2.example.com  to the channel, and make both of the peers anchor

peers.
 If you issue the  deployCC  command,  ./network.sh  runs the  deployCC.sh  script to install
the fabcar chaincode on both peers and then define then chaincode on the channel. Once the
chaincode definition is committed to the channel, the peer cli initializes the chainocde using
the  Init  and invokes the chaincode to put initial data on the ledger.

You might also like