Setting up a hyperledger fabric blockchain cluster without using docker containers

anoop vijayan maniankara
Cloudronics
Published in
5 min readDec 11, 2019

This article was originally published by me in UpCloud’s blog.

Hyperledger Fabric is an enterprise-grade permissioned distributed ledger framework for developing solutions and applications. Its modular and versatile design satisfies a broad range of industry use cases. It offers a unique approach to a consensus that enables performance at scale while preserving privacy.

This step by step guide goes through what is needed to set up Hyperledger Fabric on an server with systemd. Note that, this setup does not use Docker. This is also a good learner guide on understanding how Hyperledger Fabric works from an administrators perspective.

Environment setup

This article explains a minimal setup with 2 hosts, but each services can live in the same/different host based on users choice. Also inorder to keep it simple, TLS is omitted in the setup, hence do not try it in production.

Node specifications

Admin and Peer node(s)

The following instructions are applicable to both the above nodes:

  1. (Optional) Add the ips of nodes to if DNS resolution is not available. In this case, I am using an example domain car.com
export ADMIN_IP=192.168.10.142
export PEER_IP=192.168.10.143
echo "$ADMIN_IP orderer.car.com" | sudo tee -a /etc/hosts
echo "$PEER_IP peer0.org1.car.com" | sudo tee -a /etc/hosts

2. Install golang 1.13 and add go environment variables

sudo add-apt-repository ppa:longsleep/golang-backports
sudo apt install golang-go -y
echo 'export GOPATH=$HOME/go' | tee -a ~/.bashrc
echo 'export GOBIN=$GOPATH/bin' | tee -a ~/.bashrc
source ~/.bashrc

3. Download and install hyperledger fabric binaries (version 1.4.3) to /usr/local/bin

mkdir ~/fabric && cd ~/fabric
curl -sSL http://bit.ly/2ysbOFE | bash -s -- 2.0.0-beta 1.4.4 0.4.18
sudo cp ~/fabric/fabric-samples/bin/* /usr/local/bin/

4. Build the fabric-ca server and install to /usr/local/bin

go get -u github.com/hyperledger/fabric-ca/cmd/...
sudo cp $GOBIN/fabric-ca-server /usr/local/bin/

5. Make the necessary destination directories for orderer, peerOrg1, users, fabric and configtx.

sudo mkdir -p /etc/hyperledger/{configtx,fabric,config,msp}
sudo mkdir -p /etc/hyperledger/msp/{orderer,peerOrg1,users}

6. Download the orderer-config archive and extract it under /etc/hyperledger/fabric. This contains MSP for orderer to start.

curl -sSLO https://raw.githubusercontent.com/cloudronics/startFiles/master/orderer-config.tar.gz
sudo tar -zxvf orderer-config.tar.gz -C /etc/hyperledger/fabric/

Admin node

Generate configs genesis block etc.

  1. Download the crypto-config and configtx yaml.
curl -sSLO https://raw.githubusercontent.com/cloudronics/startFiles/master/crypto-config.yaml
curl -sSLO https://raw.githubusercontent.com/cloudronics/startFiles/master/configtx.yaml

2. Generate cryto-config, this will create necessary certificates for our car.com network

cryptogen generate --config=./crypto-config.yaml

3. Generate genesis block for the orderer.

mkdir config
configtxgen -profile OneOrgOrdererGenesis -outputBlock ./config/genesis.block -channelID carsales-sys-channel

4. Generate channel configuration transaction.

configtxgen -profile OneOrgChannel -outputCreateChannelTx ./config/carsales.tx -channelID carsales

5. Generate anchor peer transaction.

configtxgen -asOrg Org1MSP -channelID carsales -profile OneOrgChannel -outputAnchorPeersUpdate ./config/Org1MSPanchors.tx

6. Copy the generated configuration files to the Hyperledger directory.

sudo cp config/* /etc/hyperledger/configtx/

7. Also, copy the generated crypto-configs to their respective MSP directories.

sudo cp -r crypto-config/ordererOrganizations/car.com/orderers/orderer.car.com/* /etc/hyperledger/msp/orderer/
sudo cp -r crypto-config/peerOrganizations/org1.car.com/peers/peer0.org1.car.com/* /etc/hyperledger/msp/peerOrg1/
sudo cp -r crypto-config/peerOrganizations/org1.car.com/users/* /etc/hyperledger/msp/users

Install Fabric-CA and Orderer service

  1. Create a fabric-ca service by making the following service file.
cat > fabric-ca.service << EOF
# Service definition for Hyperledger fabric-ca server
[Unit]
Description=hyperledger fabric-ca server - Certificate Authority for hyperledger fabric
Documentation=https://hyperledger-fabric-ca.readthedocs.io/
Wants=network-online.target
After=network-online.target
[Service]
Type=simple
Restart=on-failure
Environment=FABRIC_LOGGING_SPEC=INFO
Environment=FABRIC_CA_HOME=/etc/hyperledger/fabric-ca-server
Environment=FABRIC_CA_SERVER_HOME=/etc/hyperledger/fabric-ca-server
Environment=CA_CFG_PATH=/etc/hyperledger/fabric-ca
ExecStart=/usr/local/bin/fabric-ca-server start -b admin:adminpw
[Install]
WantedBy=multi-user.target
EOF

2. Create a fabric orderer service by making the following service file.

cat > fabric-orderer.service << EOF
# Service definition for Hyperledger fabric orderer server
[Unit]
Description=hyperledger fabric-orderer server - Orderer for hyperledger fabric
Documentation=https://hyperledger-fabric.readthedocs.io/
Wants=network-online.target
After=network-online.target
[Service]
Type=simple
Restart=on-failure
Environment=FABRIC_LOGGING_SPEC=INFO
Environment=CA_CFG_PATH=/etc/hyperledger/fabric-ca
Environment=ORDERER_GENERAL_LISTENADDRESS=0.0.0.0
Environment=ORDERER_GENERAL_GENESISMETHOD=file
Environment=ORDERER_GENERAL_GENESISFILE=/etc/hyperledger/configtx/genesis.block
Environment=ORDERER_GENERAL_LOCALMSPID=OrdererMSP
Environment=ORDERER_GENERAL_LOCALMSPDIR=/etc/hyperledger/msp/orderer/msp
Environment=ORDERER_GENERAL_LISTENADDRESS=0.0.0.0
ExecStart=/usr/local/bin/orderer start
[Install]
WantedBy=multi-user.target
EOF

2. Then move the service file, enable, start and verify the fabric-ca service is running.

sudo mv fabric-ca.service /etc/systemd/system/
sudo systemctl enable fabric-ca.service
sudo systemctl start fabric-ca.service
sudo mv fabric-orderer.service /etc/systemd/system/
sudo systemctl enable fabric-orderer.service
sudo systemctl start fabric-orderer.service
systemctl status fabric-ca.service
systemctl status fabric-orderer.service

3. The output of successfully running fabric services would look something like the example for fabric-ca service below.

* fabric-ca.service - hyperledger fabric-ca server - Certificate Authority for hyperledger fabric
Loaded: loaded (/etc/systemd/system/fabric-ca.service; enabled; vendor preset: enabled)
Active: active (running) since Wed 2019-07-03 09:49:06 UTC; 5s ago
Docs: https://hyperledger-fabric-ca.readthedocs.io/
Main PID: 22133 (fabric-ca-serve)
Tasks: 4 (limit: 1109)
CGroup: /system.slice/fabric-ca.service
`-22133 /usr/local/bin/fabric-ca-server start -b admin:adminpw

Peer node

Copy crypto configs from Admin node

  1. Set the ip address of the admin host
export ADMIN_IP=192.168.10.142

2. Copy the config and crypto-config from the admin node to the peer.

sudo rsync -r $USER@$ADMIN_IP:/home/ubuntu/fabric/crypto-config/peerOrganizations/org1.car.com/peers/peer0.org1.car.com/* /etc/hyperledger/msp/peerOrg1/
sudo rsync -r $USER@$ADMIN_IP:/home/ubuntu/fabric/crypto-config/peerOrganizations/org1.car.com/users/ /etc/hyperledger/msp/users
sudo rsync -r $USER@$ADMIN_IP:/etc/hyperledger/fabric/msp/ /etc/hyperledger/fabric/msp
sudo scp $USER@$ADMIN_IP:/home/ubuntu/fabric/fabric-samples/config/* /etc/hyperledger/configtx/
sudo scp $USER@$ADMIN_IP:/home/ubuntu/fabric/fabric-samples/bin/peer /usr/local/bin
sudo scp $USER@$ADMIN_IP:/etc/hyperledger/fabric/core.yaml /etc/hyperledger/fabric/
sudo scp $USER@$ADMIN_IP:/etc/hyperledger/configtx/carsales.tx /etc/hyperledger/configtx/carsales.tx

3. (Optional) If you have to use identity file via rsync then use rsync -Pav -e 'ssh -i <identity file>' -r $USER@$ADMIN_HOST:/home/.....

Install Peer0 service

Next, create the following service file on the peer node.

cat > fabric-peer0-org1.service << EOF
# Service definition for Hyperledger fabric peer server
[Unit]
Description=hyperledger fabric-peer0-org1 server - Peer0/Org1 for hyperledger fabric
Documentation=https://hyperledger-fabric.readthedocs.io/
Wants=network-online.target
After=network-online.target
[Service]
Type=simple
Restart=on-failure
Environment=FABRIC_LOGGING_SPEC=INFO
Environment=FABRIC_CFG_PATH=/etc/hyperledger/fabric
Environment=CORE_PEER_ID=peer0.org1.car.com
Environment=CORE_LOGGING_PEER=info
Environment=CORE_CHAINCODE_LOGGING_LEVEL=info
Environment=CORE_PEER_LOCALMSPID=Org1MSP
Environment=CORE_PEER_MSPCONFIGPATH=/etc/hyperledger/msp/peerOrg1/msp
Environment=CORE_PEER_ADDRESS=peer0.org1.car.com:7051
ExecStart=/usr/local/bin/peer node start
[Install]
WantedBy=multi-user.target
EOF

2. Get the service running.

sudo mv fabric-peer0-org1.service /etc/systemd/system/
sudo systemctl enable fabric-peer0-org1.service
sudo systemctl start fabric-peer0-org1.service
systemctl status fabric-peer0-org1.service

Create a carssales channel and join peer0

  1. The following must be done as root, switch to the root user.
sudo su -

2. Export the necessary variables.

echo 'export CORE_PEER_MSPCONFIGPATH=/etc/hyperledger/msp/users/Admin\@org1.car.com/msp' | tee -a ~/.bashrc
echo 'export CORE_PEER_LOCALMSPID=Org1MSP' | tee -a ~/.bashrc
echo 'export CORE_PEER_ADDRESS=peer0.org1.car.com:7051' | tee -a ~/.bashrc
echo 'export CORE_PEER_ID=peer0.org1.car.com' | tee -a ~/.bashrc
source ~/.bashrc

3. Verify if peer’s channels can be listed. No errors nor channels to be reported here.

peer channel list

4. Create the channel with a peer channel.

peer channel create -o orderer.car.com:7050 -c carsales -f /etc/hyperledger/configtx/carsales.tx

5. Then, join the peer0 to that channel with peer channel join command.

peer channel join -b carsales.block

6. Lastly, verify that the peer joined the channel successfully. You should see carsales listed now.

peer channel list

Clean up

  1. Stop services, disable and remove remove service files
sudo systemctl stop fabric-ca.service
sudo systemctl stop fabric-orderer.service
sudo systemctl stop fabric-peer0-org1.service
sudo systemctl disable fabric-ca.service
sudo systemctl disable fabric-orderer.service
sudo systemctl disable fabric-peer0-org1.service
rm -f /etc/systemd/system/fabric-ca.service
rm -f /etc/systemd/system/fabric-orderer.service
rm -f /etc/systemd/system/fabric-peer0-org1.service

2. Remove golang

sudo apt remove golang

3. Remove orderer and peer entries if present in /etc/hosts

4. Remove relevant entries in ~/.bashrc

5. Remove ~/faric , /etc/hyperledger folders

rm -rf ~/fabric
sudo rm -rf /etc/hyperledger

6. Remove relevant entries from /usr/local/bin/

Conclusion

Now a hyperledger fabric cluster is setup with 1 org and 1 peer.

Terms and Glossary:

  1. Official docs: https://hyperledger-fabric.readthedocs.io/en/release-1.4/glossary.html
  2. Simplified hacknoon’s glossary: https://hackernoon.com/hyperledger-fabric-the-20-most-important-terms-made-simple-2753f925db4

References:

  1. First version of the original article : https://upcloud.com/community/tutorials/hyperledger-fabric-systemd/

2. Hyperledger fabric read the docs — https://hyperledger-fabric.readthedocs.io/en/release-1.4/index.html

3. Hyperledger fabric certificate authority read the docs — https://hyperledger-fabric-ca.readthedocs.io/en/release-
1.4/index.html

4. File references: https://github.com/cloudronics/startFiles

--

--