Download Hyperleadger fabric installation and more Slides Computer Science in PDF only on Docsity!
Installing the pre-requisites
PS: All these have been tried on Ubuntu 18.04 (64-bit) with a generic kernel version
1. Install docker from the https://docs.docker.com/install/linux/docker-ce/ubuntu/#upgrade-
docker-ce
2. Install docker-compose: sudo apt-get install docker-compose
3. Stay in ‘sudo’ mode: sudo su
4. Download ‘Go’ from: https://golang.org/dl/ (Choose the recent for Linux)
5. Once downloaded place the archive in the HOME directory and issue the command from
the terminal: sudo tar -C /usr/local/ -xzf go1.11.linux-amd64.tar.gz
6. Edit ~/.profile and append the lines export PATH=$PATH:/usr/local/go/bin and
export GOPATH=$HOME/go
7. Issue command: source ~/.profile
8. Install npm using: sudo apt-get install npm
9. Once the installation is done update npm using the command: npm install npm@5.6.
-g
10. For python2.7 issue the command: sudo apt-get install python and check the
version using python --version (This should outout something like: Python
2.7.15rc1)
Obtain the sample, binaries and docker-images
1. If you are inside some local subnet with an institute proxy the first thing you need to do is
configure the proxy for docker ( Note: All those who are not behind a proxy need not
to go through these steps )
a. Edit the /etc/default/docker and append the lines (here x.x.x.x:yyyy is the
respective ip:port of the institute proxy):
export http_proxy="http://x.x.x.x:yyyy/"
export https_proxy="https://x.x.x.x:yyyy/”
export ftp_proxy="ftp://x.x.x.x:yyyy/"
export socks_proxy="socks://x.x.x.x:yyyy/"
b. Then,
i. service docker restart
ii. mkdir /etc/systemd/system/docker.service.d
iii. Edit /etc/systemd/system/docker.service.d/http_proxy.conf
and append the lines:
[Service]
Environment="HTTP_PROXY=http://x.x.x.x:yyyy/"
Environment="NO_PROXY=localhost,127.0.0.0/8,10.*,docker-
registry.somecorporation.com"
iv. systemctl daemon-reload
v. systemctl show --property Environment docker (This should the
properties you have set in the file:
/etc/systemd/system/docker.service.d/http_proxy.conf)
vi. systemctl restart docker
2. Please ensure that curl is having the latest version and then run the following
command:
a. curl -sSL http://bit.ly/2ysbOFE | bash -s 1.2.0 1.2.0 0.4.
b. This will take some time and you will see logs like the following:
root@####:/home/#####/fabric-samples# curl - sSL http://bit.ly/2ysbOFE | bash - s 1.2.0 1.2.0 0.4.
Installing hyperledger/fabric-samples repo
===> Cloning hyperledger/fabric-samples repo and checkout v1.2.
Cloning into 'fabric-samples'...
remote: Counting objects: 1793, done.
remote: Compressing objects: 100% (18/18), done.
remote: Total 1793 (delta 2), reused 24 (delta 1), pack-reused 1767
Receiving objects: 100% (1793/1793), 624.41 KiB | 125.00 KiB/s, done.
Resolving deltas: 100% (866/866), done.
Note: checking out 'v1.2.0'.
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
100 4940k 100 4940k 0 0 893k 0 0:00:05 0:00:05 --:--:-- 1039k
==> Done.
c. And at the end:
===> List out hyperledger docker images
hyperledger/fabric-ca 1.2.0 66cc132bd09c 2 months ago
252MB
hyperledger/fabric-ca latest 66cc132bd09c 2 months ago
252MB
hyperledger/fabric-tools 1.2.0 379602873003 2 months ago
1.51GB
hyperledger/fabric-tools latest 379602873003 2 months ago
1.51GB
hyperledger/fabric-ccenv 1.2.0 6acf31e2d9a4 2 months ago
1.43GB
hyperledger/fabric-ccenv latest 6acf31e2d9a4 2 months ago
1.43GB
hyperledger/fabric-orderer 1.2.0 4baf7789a8ec 2 months ago
152MB
hyperledger/fabric-orderer latest 4baf7789a8ec 2 months ago
152MB
252MB
hyperledger/fabric-tools 1.2.0 379602873003 2 months ago
1.51GB
hyperledger/fabric-tools latest 379602873003 2 months ago
1.51GB
hyperledger/fabric-ccenv 1.2.0 6acf31e2d9a4 2 months ago
1.43GB
hyperledger/fabric-ccenv latest 6acf31e2d9a4 2 months ago
1.43GB
hyperledger/fabric-orderer 1.2.0 4baf7789a8ec 2 months ago
152MB
hyperledger/fabric-orderer latest 4baf7789a8ec 2 months ago
152MB
hyperledger/fabric-peer 1.2.0 82c262e65984 2 months ago
159MB
hyperledger/fabric-peer latest 82c262e65984 2 months ago
159MB
hyperledger/fabric-zookeeper 0.4.10 2b51158f3898 2 months ago
1.44GB
hyperledger/fabric-zookeeper latest 2b51158f3898 2 months ago
1.44GB
hyperledger/fabric-kafka 0.4.10 936aef6db0e6 2 months ago
1.45GB
hyperledger/fabric-kafka latest 936aef6db0e6 2 months ago
1.45GB
hyperledger/fabric-couchdb 0.4.10 3092eca241fc 2 months ago
1.61GB
hyperledger/fabric-couchdb latest 3092eca241fc 2 months ago
1.61GB
6. Once you have followed all these steps, correctly you will get the following commands:
a. cryptogen
b. configtxgen
c. configtxlator
d. peer
e. orderer
f. Idemixgen
g. fabric-ca-client
Setup the First-Network
1. Once all the steps are done. In the terminal move to the <downloaded-fabric-
folder>/first-network
2. Run: ./byfn.sh generate
root@#####:/home/#####/fabric-samples/fabric-samples/first-network# ./byfn.sh generate Generating certs and genesis block for channel 'mychannel' with CLI timeout of '10' seconds and CLI delay of '3' seconds Continue? [Y/n] y proceeding ...
/home/######/fabric-samples/fabric-samples/first-network/../bin/cryptogen ##########################################################
Generate certificates using cryptogen tool
##########################################################
- cryptogen generate --config=./crypto-config.yaml org1.example.com org2.example.com
- res=
- set +x /home/######/fabric-samples/fabric-samples/first-network/../bin/configtxgen ########################################################## ######### Generating Orderer Genesis block ############## ##########################################################
- configtxgen - profile TwoOrgsOrdererGenesis - outputBlock ./channel-artifacts/genesis.block 2018 - 09 - 11 18:48:02.279 IST [common/tools/configtxgen] main - > WARN 001 Omitting the channel ID for configtxgen is deprecated. Explicitly passing the channel ID will be required in the future, defaulting to 'testchainid'. 2018 - 09 - 11 18:48:02.279 IST [common/tools/configtxgen] main - > INFO 002 Loading configuration 2018 - 09 - 11 18:48:02.284 IST [common/tools/configtxgen/encoder] NewChannelGroup - > WARN 003 Default policy emission is deprecated, please include policy specificiations for the channel group in configtx.yaml 2018 - 09 - 11 18:48:02.284 IST [common/tools/configtxgen/encoder] NewOrdererGroup - > WARN 004 Default policy emission is deprecated, please include policy specificiations for the orderer group in configtx.yaml 2018 - 09 - 11 18:48:02.285 IST [common/tools/configtxgen/encoder] NewOrdererOrgGroup - > WARN 005 Default policy emission is deprecated, please include policy specificiations for the orderer org group OrdererOrg in configtx.yaml 2018 - 09 - 11 18:48:02.285 IST [msp] getMspConfig - > INFO 006 Loading NodeOUs 2018 - 09 - 11 18:48:02.285 IST [common/tools/configtxgen/encoder] NewOrdererOrgGroup - > WARN 007 Default policy emission is deprecated, please include policy specificiations for the orderer org group Org1MSP in configtx.yaml 2018 - 09 - 11 18:48:02.285 IST [msp] getMspConfig - > INFO 008 Loading NodeOUs 2018 - 09 - 11 18:48:02.285 IST [common/tools/configtxgen/encoder] NewOrdererOrgGroup - > WARN 009 Default policy emission is deprecated, please include policy specificiations for the orderer org group Org2MSP in configtx.yaml 2018 - 09 - 11 18:48:02.285 IST [common/tools/configtxgen] doOutputBlock - > INFO 00a Generating genesis block 2018 - 09 - 11 18:48:02.285 IST [common/tools/configtxgen] doOutputBlock - > INFO 00b Writing genesis block
- res=
- set +x #################################################################
Generating channel configuration transaction 'channel.tx'
#################################################################
- configtxgen - profile TwoOrgsChannel - outputCreateChannelTx ./channel-artifacts/channel.tx - channelID mychannel 2018 - 09 - 11 18:48:02.315 IST [common/tools/configtxgen] main - > INFO 001 Loading configuration 2018 - 09 - 11 18:48:02.322 IST [common/tools/configtxgen] doOutputChannelCreateTx - > INFO 002 Generating new channel configtx 2018 - 09 - 11 18:48:02.323 IST [common/tools/configtxgen/encoder] NewApplicationGroup - > WARN 003 Default policy emission is deprecated, please include policy specificiations for the application group in configtx.yaml 2018 - 09 - 11 18:48:02.323 IST [msp] getMspConfig - > INFO 004 Loading NodeOUs 2018 - 09 - 11 18:48:02.323 IST [common/tools/configtxgen/encoder] NewApplicationOrgGroup - > WARN 005 Default policy emission is deprecated, please include policy specificiations for the application org group Org1MSP in configtx.yaml 2018 - 09 - 11 18:48:02.323 IST [msp] getMspConfig - > INFO 006 Loading NodeOUs 2018 - 09 - 11 18:48:02.323 IST [common/tools/configtxgen/encoder] NewApplicationOrgGroup - > WARN 007 Default policy emission is deprecated, please include policy specificiations for the application org group Org2MSP in configtx.yaml 2018 - 09 - 11 18:48:02.324 IST [common/tools/configtxgen] doOutputChannelCreateTx - > INFO 008 Writing new channel tx
- res=
- set +x ################################################################# ####### Generating anchor peer update for Org1MSP ########## #################################################################
- configtxgen - profile TwoOrgsChannel - outputAnchorPeersUpdate ./channel-artifacts/Org1MSPanchors.tx - channelID mychannel - asOrg Org1MSP 2018 - 09 - 11 18:48:02.357 IST [common/tools/configtxgen] main - > INFO 001 Loading configuration 2018 - 09 - 11 18:48:02.361 IST [common/tools/configtxgen] doOutputAnchorPeersUpdate - > INFO 002 Generating anchor peer update 2018 - 09 - 11 18:48:02.361 IST [common/tools/configtxgen] doOutputAnchorPeersUpdate - > INFO 003 Writing anchor peer update
- res=
- set +x
2018 - 09 - 11 13:23:00.751 UTC [channelCmd] InitCmdFactory - > INFO 001 Endorser and orderer connections initialized 2018 - 09 - 11 13:23:01.414 UTC [channelCmd] executeJoin - > INFO 002 Successfully submitted proposal to join channel ===================== peer0.org1 joined channel 'mychannel' =====================
- peer channel join - b mychannel.block
- res=
- set +x 2018 - 09 - 11 13:23:04.528 UTC [channelCmd] InitCmdFactory - > INFO 001 Endorser and orderer connections initialized 2018 - 09 - 11 13:23:04.933 UTC [channelCmd] executeJoin - > INFO 002 Successfully submitted proposal to join channel ===================== peer1.org1 joined channel 'mychannel' =====================
- peer channel join - b mychannel.block
- res=
- set +x 2018 - 09 - 11 13:23:08.032 UTC [channelCmd] InitCmdFactory - > INFO 001 Endorser and orderer connections initialized 2018 - 09 - 11 13:23:08.484 UTC [channelCmd] executeJoin - > INFO 002 Successfully submitted proposal to join channel ===================== peer0.org2 joined channel 'mychannel' =====================
- peer channel join - b mychannel.block
- res=
- set +x 2018 - 09 - 11 13:23:11.569 UTC [channelCmd] InitCmdFactory - > INFO 001 Endorser and orderer connections initialized 2018 - 09 - 11 13:23:12.039 UTC [channelCmd] executeJoin - > INFO 002 Successfully submitted proposal to join channel ===================== peer1.org2 joined channel 'mychannel' ===================== Updating anchor peers for org1...
- peer channel update - o orderer.example.com:7050 - c mychannel - f ./channel-artifacts/Org1MSPanchors.tx --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
- res=
- set +x 2018 - 09 - 11 13:23:15.105 UTC [channelCmd] InitCmdFactory - > INFO 001 Endorser and orderer connections initialized 2018 - 09 - 11 13:23:15.125 UTC [channelCmd] update - > INFO 002 Successfully submitted channel update ===================== Anchor peers updated for org 'Org1MSP' on channel 'mychannel' ===================== Updating anchor peers for org2...
- peer channel update - o orderer.example.com:7050 - c mychannel - f ./channel-artifacts/Org2MSPanchors.tx --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
- res=
- set +x 2018 - 09 - 11 13:23:18.211 UTC [channelCmd] InitCmdFactory - > INFO 001 Endorser and orderer connections initialized 2018 - 09 - 11 13:23:18.219 UTC [channelCmd] update - > INFO 002 Successfully submitted channel update ===================== Anchor peers updated for org 'Org2MSP' on channel 'mychannel' ===================== Installing chaincode on peer0.org1...
- peer chaincode install - n mycc - v 1.0 - l golang - p github.com/chaincode/chaincode_example02/go/
- res=
- set +x 2018 - 09 - 11 13:23:21.291 UTC [chaincodeCmd] checkChaincodeCmdParams - > INFO 001 Using default escc 2018 - 09 - 11 13:23:21.291 UTC [chaincodeCmd] checkChaincodeCmdParams - > INFO 002 Using default vscc 2018 - 09 - 11 13:23:22.781 UTC [chaincodeCmd] install - > INFO 003 Installed remotely response:<status:200 payload:"OK" > ===================== Chaincode is installed on peer0.org1 ===================== Install chaincode on peer0.org2...
- peer chaincode install - n mycc - v 1.0 - l golang - p github.com/chaincode/chaincode_example02/go/
- res=
- set +x 2018 - 09 - 11 13:23:22.859 UTC [chaincodeCmd] checkChaincodeCmdParams - > INFO 001 Using default escc 2018 - 09 - 11 13:23:22.859 UTC [chaincodeCmd] checkChaincodeCmdParams - > INFO 002 Using default vscc 2018 - 09 - 11 13:23:22.970 UTC [chaincodeCmd] install - > INFO 003 Installed remotely response:<status:200 payload:"OK" > ===================== Chaincode is installed on peer0.org2 ===================== Instantiating chaincode on peer0.org2...
- peer chaincode instantiate - 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 - l golang - v 1.0 - c '{"Args":["init","a","100","b","200"]}' - P 'AND ('''Org1MSP.peer''','''Org2MSP.peer''')'
- res=
- set +x 2018 - 09 - 11 13:23:23.034 UTC [chaincodeCmd] checkChaincodeCmdParams - > INFO 001 Using default escc 2018 - 09 - 11 13:23:23.034 UTC [chaincodeCmd] checkChaincodeCmdParams - > INFO 002 Using default vscc ===================== Chaincode is instantiated on peer0.org2 on channel 'mychannel' ===================== Querying chaincode on peer0.org1... ===================== Querying on peer0.org1 on channel 'mychannel'... =====================
- peer chaincode query - C mychannel - n mycc - c '{"Args":["query","a"]}' Attempting to Query peer0.org1 ...3 secs
- res=
- set +x 100 ===================== Query successful on peer0.org1 on channel 'mychannel' ===================== Sending invoke transaction on peer0.org1 peer0.org2...
- 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 --peerAddresses peer0.org1.example.com:7051 -- tlsRootCertFiles /opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org1.example.com/peers/peer0.org1.example.c om/tls/ca.crt --peerAddresses peer0.org2.example.com:7051 --tlsRootCertFiles /opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org2.example.com/peers/peer0.org2.example.c om/tls/ca.crt - c '{"Args":["invoke","a","b","10"]}'
- res=
- set +x 2018 - 09 - 11 13:25:03.244 UTC [chaincodeCmd] chaincodeInvokeOrQuery - > INFO 001 Chaincode invoke successful. result: status: ===================== Invoke transaction successful on peer0.org1 peer0.org2 on channel 'mychannel' ===================== Installing chaincode on peer1.org2...
- peer chaincode install - n mycc - v 1.0 - l golang - p github.com/chaincode/chaincode_example02/go/
- res=
- set +x 2018 - 09 - 11 13:25:03.630 UTC [chaincodeCmd] checkChaincodeCmdParams - > INFO 001 Using default escc 2018 - 09 - 11 13:25:03.630 UTC [chaincodeCmd] checkChaincodeCmdParams - > INFO 002 Using default vscc 2018 - 09 - 11 13:25:08.526 UTC [chaincodeCmd] install - > INFO 003 Installed remotely response:<status:200 payload:"OK" > ===================== Chaincode is installed on peer1.org2 ===================== Querying chaincode on peer1.org2... ===================== Querying on peer1.org2 on channel 'mychannel'... ===================== Attempting to Query peer1.org2 ...3 secs
- peer chaincode query - C mychannel - n mycc - c '{"Args":["query","a"]}'
- res=
- set +x 90 ===================== Query successful on peer1.org2 on channel 'mychannel' ===================== ========= All GOOD, BYFN execution completed ===========
| ____| | \ | | | _
| | | | | | | | | | |__ | |\ | | || | |_____| || _| |____/
4. The corresponding condition in docker ( just an observation, no need to run ): Several
containers are created and destroyed in between.
mycc-1. root@soumya:/home/soumya# docker ps - all CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES 9932d183ff55 6649021f31af "/bin/sh - c '#(nop) …" 2 seconds ago Created lucid_mestorf root@soumya:/home/soumya# docker ps - all CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES 29313676797f ea247db5bd67 "/bin/sh - c '#(nop) …" 2 seconds ago Created ecstatic_banach root@soumya:/home/soumya# docker ps - all CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES 631aa3330e0e dev-peer0.org1.example.com-mycc-1.0-384f11f484b9302df90b453200cfb25174305fce8f53f4e94d45ee3b6cab0ce "chaincode - peer.add…" 41 seconds ago Up 37 seconds dev-peer0.org1.example.com- mycc-1. root@soumya:/home/soumya# docker ps - all CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES b5b253726a2d dev-peer1.org2.example.com-mycc-1.0-26c2ef32838554aac4f7ad6f100aca865e87959c9a126e86d764c8d01f8346ab "chaincode - peer.add…" 2 seconds ago Created dev-peer1.org2.example.com- mycc-1. dev-peer1.org2.example.com-mycc-1. root@soumya:/home/soumya# docker ps - all CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES b5b253726a2d dev-peer1.org2.example.com-mycc-1.0-26c2ef32838554aac4f7ad6f100aca865e87959c9a126e86d764c8d01f8346ab "chaincode - peer.add…" 4 minutes ago Up 4 minutes dev-peer1.org2.example.com- mycc-1.
5. Inspecting the last container ( just an observation, no need to run ):
docker inspect b5b253726a2d (b5b253726a2d is the container id)
"Config": { "Hostname": "b5b253726a2d", "Domainname": "", "User": "", "AttachStdin": false, "AttachStdout": false, "AttachStderr": false, "Tty": false, "OpenStdin": false, "StdinOnce": false, "Env": [ "CORE_CHAINCODE_LOGGING_LEVEL=info", "CORE_CHAINCODE_LOGGING_SHIM=warning", "CORE_CHAINCODE_LOGGING_FORMAT=%{color}%{time:2006- 01 - 02 15:04:05.000 MST} [%{module}] %{shortfunc} - > %{level:.4s} %{id:03x}%{color:reset} %{message}", "CORE_CHAINCODE_ID_NAME=mycc:1.0", "CORE_PEER_TLS_ENABLED=true", "CORE_TLS_CLIENT_KEY_PATH=/etc/hyperledger/fabric/client.key", "CORE_TLS_CLIENT_CERT_PATH=/etc/hyperledger/fabric/client.crt", "CORE_PEER_TLS_ROOTCERT_FILE=/etc/hyperledger/fabric/peer.crt", "PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin", "CORE_CHAINCODE_BUILDLEVEL=1.2.0" ], "Cmd": [ "chaincode", "-peer.address=peer1.org2.example.com:7052" ], "Image": "dev-peer1.org2.example.com-mycc-1.0- 26c2ef32838554aac4f7ad6f100aca865e87959c9a126e86d764c8d01f8346ab", "Volumes": null,
"WorkingDir": "", "Entrypoint": null, "OnBuild": null, "Labels": { "org.hyperledger.fabric.base.version": "0.4.10", "org.hyperledger.fabric.chaincode.id.name": "mycc", "org.hyperledger.fabric.chaincode.id.version": "1.0", "org.hyperledger.fabric.chaincode.type": "GOLANG", "org.hyperledger.fabric.version": "1.2.0" } }
6. Shutting down the network: ./byfn.sh down ---> This will kill all the
running containers.
7. Remaining experiments can be found in: https://hyperledger-
fabric.readthedocs.io/en/release-1.2/build_network.html