This laboratory covers a Blockchain implementation running on an IBM LinuxONE Server. Second, you will learn how to deploy a Hyperledger Fabric using Dockers Containers. Originally presented at IBM Systems Technical University, Sao Paulo, Atibaia, 2016.
Dev Dives: Streamline document processing with UiPath Studio Web
Lab Exercise: IBM Blockchain runs also on LinuxONE, see it in action!
1. Anderson Weber Bassani | IBM
Lab Exercise: IBM Blockchain runs also on
LinuxONE, see it in action!
Anderson W. Bassani
abassani@br.ibm.com
Introduction:
This laboratory covers a Blockchain implementation running on an IBM LinuxONE
Server. Second, you will learn how to deploy a Hyperledger Fabric using Dockers
Containers.
2. Exercises Guide
2
Exercise instructions
In this exercise you will complete the following tasks:
__ 1. First, watch a Blockchain Implementation running on IBM LinuxONE
__ a. What is Blockchain and why to run on IBM LinuxONE
__ b. Blockchain Terminology
__ c. Architecture
__ d. Demonstration
__ 2. Second, create your own Linux on z virtual server and deploy a Hyperledger Fabric
__ a. Sign up for a LinuxONE Community Cloud trial account
__ b. Log on, create a SSH key pair, and deploy a virtual server instance
__ c. Setup PuTTY to use a private key
__ d. Access the virtual server with Secure Shell (SSH)
__ e. Build the Hyperledger Fabric
__ f. Create a four-peer network
__ g. Deploy the example smart contract application
3. Anderson Weber Bassani | IBM
Task 1
__ 3. First, watch a Blockchain Implementation running on IBM LinuxONE
__ a. What is Blockchain and why to run on IBM LinuxONE
Blockchain Terminology:
Business Networks
Transfer of assets within a Business Network
Assets – tangible, intangible, and digital
Transaction on this context
Shared Business Ledgers
The Database versus The Ledger – similar to systems of records
Consensus Algorithms, Consensus problem
Byzantine Generals problem, Cryptography
IBM’s Point of View – Open Source, Open Standard, Open Governance
Hyperledger Project – like Linux, Java, OpenStack
IBM’s Engagement – Conversations, Demonstrations, POT’s, POC’s
Image: Blockchain on z Systems use case for Trade Finance/Logistics
Watch the full demonstration at:
https://www.youtube.com/watch?v=EqZr4LPQIWk
4. Exercises Guide
4
Image: A Business Network example
Image: The integration with existing Business Process
7. Anderson Weber Bassani | IBM
Task 2
__ 4. Second, create your own Linux on z virtual server and deploy a Hyperledger Fabric
__ a. Sign up for a LinuxONE Community Cloud trial account
Important: On this Laboratory, you now can skip to Step 7: Build the Hyperledger Fabric
on page 25.
The instructor already created one Linux server and a private key for each group.
Ask the instructor your Group Number, from 01 to 12.
Besides that fact, the IBM LinuxONE Community Cloud is available on the internet, so you
can reproduce all the steps on your company or at home!
Step 1: Registration
If you have not done so already, register at
http://www.ibm.com/linuxone/try
for a 120-day trial account. You will receive an email containing credentials to access the
LinuxONE Community Cloud self-service portal. This is where you can start exploring all
our available services.
Image: The email with the credentials to access the LinuxONE Cloud
8. Exercises Guide
8
Step 2: Log on to the self-service portal
The portal URL and account credentials can be found in the email sent from
“LinuxONE Community Cloud” with subject “Registration successful”.
__ 1. Click on URL
__ 2. Type in your account name and password.
__ 2. Click on Sign in. The LinuxONE Community Cloud initial screen will open.
9. Anderson Weber Bassani | IBM
Step 3: Create an SSH key pair
Virtual server instances require SSH key pairs for user authentication. Password is
disabled for SSH. You must create one or import an existing public key to be used for
instance deployment.
__ 1. At the home page, click on your account name to display a list of options.
10. Exercises Guide
10
__ 2. Select Manage SSH Key Pairs.
__ 3. To import an existing SSH public key:
__ a. Click on Import
__ b. Provide a name for this key
__ c. Click on Browse to select a file from your local file system
__ d. Click on Upload your public key
__ 4. To create a new SSH key pair:
__ a. Click on Create
__ b. Provide a name for this key. The instructor already created one key pair for each
group. The key name is blockchainXX, where XX is the group number from 01 to 12.
11. Anderson Weber Bassani | IBM
Image: the Key Name for the first group
__ c. Click on Create a new key pair
__ d. Save the generated key. In this example, save the blockchain01.pem private key.
Note: Take care in storing this private key. There is no way to retrieve this key once it has been
saved.
12. Exercises Guide
12
Step 4: Deploy a Virtual Server Instance
__ 1. Click Home to go back to the home page
__ 2. Click on Manage Instances from the Virtual Servers tile.
__ 3. Click on Create.
__ 4. Fill in all required information:
__ a. On Step 1 Session: Enter Instance Details, fill the Instance name and
Instance description of your server. Pay attention on Instance Description field, only
English characters are allowed.
__ b. On Step 2: Select an Image, select RHEL 7.2 image where we will create the
Hyperledger Fabric afterwards.
__ c. On Step 3: Select a Flavor, click LinuxONE-Medium. The option will be
highlighted.
13. Anderson Weber Bassani | IBM
__ d. Select an SSH key. If you have not created or imported a key yet, click on
Create / Import (Refer to Step 3: Create an SSH key pair) before continuing. In the image
below, the blockchain01 key was selected.
__ 4. Create the instance.
__ a. Verify your selection. The Current Selection field present a summary of the
options selected.
__ b. Make any changes if necessary
__ c. Click on Create.
__ d. Wait until your instance be deployed.
14. Exercises Guide
14
Image: The Instances screen and status information.
When the instance deployment is complete, the server status will become “Active”.
You can click on View details to display additional information about this instance.
Image: The Instance Status after a successful deployment
Image: View details
15. Anderson Weber Bassani | IBM
Step 5: Access virtual server with Secure Shell (SSH)
Login for the root user is disabled. You must log in with the “linux1” user. This
user has full sudo privilege.
Linux and Mac OS X Users: Follow the instructions below if your workstation have these
operating systems installed
__ 1. Make sure your key has a file permission of 600. Run this command to change it if
necessary:
chmod 600 <yourkey>.pem
__ 2. Run this command from a terminal to connect to your deployed instance.
16. Exercises Guide
16
ssh -i <yourkey>.pem linux1@<instance IP address>
Where:
<yourkey>.pem is the key you created / imported earlier in Step 3: Create an SSH
key pair.
<instance IP address> is the IP address assigned to your deployed instance.
Windows Users: Follow the instructions below if your workstation have Windows installed
__ 1. You have to use an SSH client. A popular and free SSH client is PuTTY. You can
download PuTTY from this website: http://www.putty.org/ .
__ 2. Set up PuTTY on Windows to use SSH private key.
__ a. Download PuTTYgen from this website
http://www.chiark.greenend.org.uk/~sgtatham/putty/download.html
__ b. Save the puttygen.exe (183 KB) binary file
__ c. Double click to execute the PUTTYGEN program. Click Run.
18. Exercises Guide
18
__ e. Let’s protect the private key. Click File > Load private key
__ f. Select the folded that contains your private key, select All Files (the PuTTY try to
locate PuTTY Private Key Files with extension .ppk). Select the blockchainXX.pem private
key. Click Open.
19. Anderson Weber Bassani | IBM
__ g. Click OK button to acknowledge the successful notice
__ h. Enter a key passphrase and confirm it.
Important: The key passphrase that was used for all the Groups = stu2016
20. Exercises Guide
20
__ i. Click Save private key. Each Group have one blockchainXX.ppk private key, so no one is
able to connect on a different virtual machine.
Note: the protected private key file (.ppk) just created is needed by PuTTY.
__ j. Let’s now set up the PuTTY with the protected private key already created. Start
PuTTY.
21. Anderson Weber Bassani | IBM
__ k. Select Connection->SSH->Auth and Click Browse to select the protected private key file
(.ppk)
22. Exercises Guide
22
__ l. Select Connection->Data and enter linux1 in the Auto-login username textbox
23. Anderson Weber Bassani | IBM
__ m. Select Session and enter the IP address for your image in the Host Name textbox. On the
Saved Session, insert your Group name (blockchainXX). Click Save.
25. Anderson Weber Bassani | IBM
__ o. Enter the passphrase for the protected private key.
Hint: The passphrase is stu2016
__ p. Welcome to Bash! You will receive the Welcome to LinuxONE Community Cloud!
Screen.
Step 6: Manage your virtual server instance
You can use the self-service portal to:
1. Create an instance
2. Stop an instance
3. Start an instance
4. Delete an instance
Important: Read the important information below about your virtual server instance
1. The root user login is disabled.
2. You must log in with the user “linux1” with your SSH private key.
26. Exercises Guide
26
3. The “linux1” user has full sudo privilege.
4. There is a 42 GB user disk mounted at /data.
5. Firewall is enabled. Only the SSH port is open. Modify the firewall rules if you need
other ports opened.
6. Your server will be shut off if it is inactive for more than 7 days. You can start it using
the self-service portal.
Note: About your LinuxONE Community Cloud account
1. Your LinuxONE Community cloud trial allows you to deploy one (1) virtual server. You
may delete this server and deploy another instance using other images in the catalog.
2. Your server will be deleted and trial account will be cancelled if your server is shut off
for more than 30 days.
3. You must abide to these terms of use (https://developer.ibm.com/linuxone/terms-of-
use/) which you have agreed during registration. Any misuse will result in immediate
revoke of access to the cloud.
27. Anderson Weber Bassani | IBM
Step 7: Build the Hyperledger Fabric (estimate time = 11 minutes)
__ 1. Log on to your virtual server with the ‘linux1’ user.
ssh -i <ssh key> linux1@<server IP address>
Or use an SSH client like PuTTY
Table: Hostname and IP Addresses
Hostname IP Address
blockchain01 148.100.5.105
blockchain02 148.100.5.118
blockchain03 148.100.5.154
blockchain04 148.100.5.155
blockchain05 148.100.5.127
blockchain06 148.100.5.132
blockchain07 148.100.5.159
blockchain08 148.100.5.160
blockchain09 148.100.5.142
blockchain10 148.100.5.144
blockchain11 148.100.5.161
blockchain12 148.100.5.153
__ 2. Switch to root user.
28. Exercises Guide
28
sudo -i
__ 3. Create a new directory under /data.
mkdir /data/docker
__ 4. Create a symbolic link to the /data/docker directory.
ln -s /data/docker /var/lib/docker
__ 5. Switch to the /root directory.
cd /root
__ 6. Get the hyperledger fabric build script and save it to a file.
wget
https://raw.githubusercontent.com/harrijk/docs/master/z
SystemsFabricBuild.sh
__ 7. Run the script to build the hyperledger fabric.
. zSystemsFabricBuild.sh
__ 8. The script will print the following message to the screen when complete:
Cleanup Docker artifacts
5060467d937a
eb2dfef3e4cc
957156e7b57f
9eab3b31a85f
fbc0388343ff
29. Anderson Weber Bassani | IBM
brunswickheads/openchain-peer latest
dc53061bd3e5 6 months ago 1.256 GB
Untagged: brunswickheads/openchain-peer:latest
*** DONE ***
The Hyperledger Fabric and its supporting components
have been successfully installed.
30. Exercises Guide
30
Step 8: Create a four-peer network (estimate time = 5 minutes)
__ 1. The build process returned your session to the linux1 user. Switch to root user.
sudo -i
__ 2. Switch to the following directory.
cd $GOPATH/src/github.com/hyperledger/fabric/build/bin
__ 3. Use Docker Compose to define four peers in the chain and set up the containers.
Get the docker-compose.yml file using the following command:
wget
https://raw.githubusercontent.com/cheeye/blockchain/mas
ter/docker-compose.yml
The docker-compose.yml file contains the following configuration:
[root@blockchainXX]# cat docker-compose.yml
vp0:
image: hyperledger/fabric-peer
environment:
- CORE_PEER_ID=vp0
- CORE_PEER_ADDRESSAUTODETECT=true
- CORE_VM_ENDPOINT=http://172.17.0.1:2375
- CORE_LOGGING_LEVEL=DEBUG
command: peer node start
vp1:
extends:
service: vp0
environment:
- CORE_PEER_ID=vp1
31. Anderson Weber Bassani | IBM
- CORE_PEER_DISCOVERY_ROOTNODE=vp0:30303
links:
- vp0
vp2:
extends:
service: vp0
environment:
- CORE_PEER_ID=vp2
- CORE_PEER_DISCOVERY_ROOTNODE=vp0:30303
links:
- vp0
vp3:
extends:
service: vp0
environment:
- CORE_PEER_ID=vp3
- CORE_PEER_DISCOVERY_ROOTNODE=vp0:30303
links:
- vp0
__ 4. Start the four peers in Docker containers.
docker-compose up
Note: Allow the above command to continue to run in this shell.
32. Exercises Guide
32
Step 9: Deploy the example smart contract application (estimate time = 5 minutes)
__ 1. Start a second shell session with root access.
__ a. Log on to your virtual server with the ‘linux1’ user.
ssh -i <ssh key> linux1@<server IP address>
Or use an SSH client like PuTTY
__ b. Switch to root user.
sudo -i
__ 2. Switch to the following directory:
cd $GOPATH/src/github.com/hyperledger/fabric/build/bin
__ 3. Issue the following command to deploy the example smart contract application,
initialize the contract, and propagate to all peers. Variables ‘a’ and ‘b’ represent “account”
numbers initialized to 100 and 200, respectively.
NAME=`CORE_PEER_ADDRESS=172.17.0.2:30303 ./peer
chaincode deploy -p
github.com/hyperledger/fabric/examples/chaincode/go/cha
incode_example02 -c '{"Function":"init", "Args":
["a","100", "b", "200"]}'`
__ 4. The smart contract deployment is complete when all 4 peers have a status of
“Up…”. Issue this command to monitor the status:
docker ps -a
__ 5. Work with the smart contract and interact with the Blockchain by issuing the
following commands.
33. Anderson Weber Bassani | IBM
__ a. To query account b:
CORE_PEER_ADDRESS=172.17.0.2:30303 ./peer chaincode
query -n $NAME -c '{"Function": "query", "Args":
["b"]}'
The result should be 200.
__ b. To query account a:
CORE_PEER_ADDRESS=172.17.0.2:30303 ./peer chaincode
query -n $NAME -c '{"Function": "query","Args": ["a"]}'
The result should be 100.
__ c. To transfer 10 units from account a to account b:
CORE_PEER_ADDRESS=172.17.0.2:30303 ./peer chaincode
invoke -n $NAME -c '{"Function": "invoke","Args": ["a",
"b", "10"]}'
__ d. To query account b
CORE_PEER_ADDRESS=172.17.0.2:30303 ./peer chaincode
query -n $NAME -c '{"Function": "query", "Args":
["b"]}'
The result should be 210.
__ e. To query account a
CORE_PEER_ADDRESS=172.17.0.2:30303 ./peer chaincode
query -n $NAME -c '{"Function": "query","Args": ["a"]}'
The result should be 90.
34. Exercises Guide
34
Exercise review and wrap-up
Having completed this exercise, you should be able to:
Describe of blockchain is and how does it integrates in the existing business
processes
Describe blockchain major components
Deploy a Linux on z virtual server on IBM Community Cloud
Install the Hyperledger Fabric using Docker Containers
Install and test a smart contract
Next steps:
Explore the additional bibliography on the Appendix below, like
https://www.ibm.com/blockchain/getting-started.html
35. Anderson Weber Bassani | IBM
Appendix – Bibliography
Here it is some addition materials and references:
1) IBM and Blockchain - https://www.ibm.com/blockchain
2) IBM LinuxONE Community Cloud - https://developer.ibm.com/linuxone/
3) Hyperledger Project - https://www.hyperledger.org/
4) PuTTY Set up
https://developer.ibm.com/linuxone/wp-content/uploads/sites/57/2016/02/PUTTY-Set-
up.pdf
5) Deploy a Virtual Server on LinuxONE – Quick Start Guide
https://developer.ibm.com/linuxone/wp-content/uploads/sites/57/virtual-servers-quick-
start.pdf
6) LinuxONE Terms of Use
https://developer.ibm.com/linuxone/terms-of-use/
https://developer.ibm.com/linuxone/linuxone-community-cloud-terms-conditions/
7) Blockchain Quick Start Guide
https://developer.ibm.com/linuxone/wp-content/uploads/sites/57/blockchain-quick-start.pdf
8) Donna's Dillenberger's YouTube video:
https://www.youtube.com/watch?v=EqZr4LPQIWk
9) https://docs.docker.com/engine/userguide/intro/
10) https://github.com/harrijk/docs
11) https://raw.githubusercontent.com/harrijk/docs/master/zSystemsFabricBuild.sh
12) https://raw.githubusercontent.com/cheeye/blockchain/master/docker-compose.yml
36. Exercises Guide
36
13) https://github.com/hyperledger/fabric/blob/master/docs/Setup/Network-setup.md
14) Steps to setup Blockchain (Hyperledger Fabric 0.6) development environment on Ubuntu
https://www.ibm.com/developerworks/community/blogs/8d277a63-4204-4fd3-8cb8-
b7cb222cd522/entry/Steps_to_setup_Blockchain_Hyperledger_Fabric_0_6_development_environ
ment_on_Ubuntu?lang=en
15) Docker Hub - https://hub.docker.com/r/ibmblockchain/hyperledger-fabric/
16) An introduction text about Blockchain
https://www.ibm.com/developerworks/cloud/library/cl-blockchain-basics-intro-bluemix-
trs/index.html
17) Blockchain Terminology
https://www.ibm.com/developerworks/cloud/library/cl-blockchain-basics-glossary-bluemix-
trs/index.html
18) Hyperledger Fabric – Link to Protocol Specification -
https://github.com/hyperledger/fabric/blob/master/docs/protocol-spec.md
37. Anderson Weber Bassani | IBM
Appendix – Handy Commands
Stop all Docker containers
docker stop $(docker ps -a -q)
Removes all Docker instances
docker rm -f $(docker ps -a -q)
Removes all Docker images
docker rmi -f $(docker images -q)
38. Exercises Guide
38
With gratitude
This humble instructor could not complete this laboratory without the help of these teams:
IBM Poughkeepsie Customer Center
IBM LinuxONE Community Cloud
IBM Systems Lab Services – Brazil
Sandra Russell
Eugene Ong
Eva Yan