Module 4: Network Setup and Deployment

4.1 Prerequisites and Environment Setup

Before setting up a Hyperledger Fabric network, it's essential to prepare the environment with the necessary prerequisites. This section covers the requirements and setup process for a Fabric development and production environment.

Hardware and Operating System Requirements

Development Environment

For a development environment, the following minimum specifications are recommended:

  • CPU: 2 cores / 4 threads
  • RAM: 8 GB
  • Disk: 50 GB SSD
  • Operating System: Ubuntu 20.04/22.04, macOS 10.15+, or Windows 10/11 with WSL2

Production Environment

For a production environment, consider these specifications:

  • CPU: 4+ cores / 8+ threads
  • RAM: 16+ GB
  • Disk: 100+ GB SSD with high IOPS
  • Network: 1 Gbps+ with low latency
  • Operating System: Ubuntu 20.04/22.04 LTS or Red Hat Enterprise Linux 8+

Cloud Provider Considerations

When deploying in cloud environments:

  • Use compute-optimized instances for orderers and peers
  • Consider storage-optimized instances for peers with large state databases
  • Use managed Kubernetes services for container orchestration
  • Implement load balancers for high availability
  • Utilize private networks for secure communication

Software Prerequisites

The following software components are required for Hyperledger Fabric:

Core Dependencies

  1. Docker: Container runtime for Fabric components
  2. Version 20.10.x or higher
  3. Docker Compose V2

  4. Go: Programming language for Fabric and chaincode

  5. Version 1.18.x or higher
  6. Required for chaincode development in Go

  7. Node.js: For JavaScript/TypeScript chaincode and applications

  8. Version 16.x or higher
  9. npm 8.x or higher

  10. Java: For Java chaincode development

  11. OpenJDK 11 or higher
  12. Maven 3.6.x or higher

  13. Python: For client applications and scripts

  14. Version 3.8 or higher
  15. pip package manager

Additional Tools

  1. Git: Version control system
  2. Version 2.30.x or higher

  3. cURL: Command-line tool for data transfer

  4. Version 7.68.0 or higher

  5. jq: Command-line JSON processor

  6. Version 1.6 or higher

  7. GNU make: Build automation tool

  8. Version 4.2.x or higher

Installing Prerequisites on Ubuntu

Here's a step-by-step guide to install prerequisites on Ubuntu 22.04:

# Update package lists
sudo apt update
sudo apt upgrade -y

# Install basic utilities
sudo apt install -y git curl wget jq make

# Install Docker
sudo apt install -y apt-transport-https ca-certificates gnupg lsb-release
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo gpg --dearmor -o /usr/share/keyrings/docker-archive-keyring.gpg
echo "deb [arch=$(dpkg --print-architecture) signed-by=/usr/share/keyrings/docker-archive-keyring.gpg] https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable" | sudo tee /etc/apt/sources.list.d/docker.list > /dev/null
sudo apt update
sudo apt install -y docker-ce docker-ce-cli containerd.io docker-compose-plugin

# Add user to docker group
sudo usermod -aG docker $USER
newgrp docker

# Install Go
wget https://go.dev/dl/go1.18.10.linux-amd64.tar.gz
sudo rm -rf /usr/local/go
sudo tar -C /usr/local -xzf go1.18.10.linux-amd64.tar.gz
rm go1.18.10.linux-amd64.tar.gz
echo 'export PATH=$PATH:/usr/local/go/bin:$HOME/go/bin' >> ~/.profile
source ~/.profile

# Install Node.js
curl -fsSL https://deb.nodesource.com/setup_16.x | sudo -E bash -
sudo apt install -y nodejs
sudo npm install -g npm@8

# Install Java
sudo apt install -y openjdk-11-jdk maven

# Install Python
sudo apt install -y python3 python3-pip

Installing Hyperledger Fabric Binaries and Docker Images

To install Hyperledger Fabric binaries and Docker images, use the provided script:

# Create a directory for Fabric
mkdir -p ~/fabric
cd ~/fabric

# Download and run the installation script
curl -sSL https://bit.ly/2ysbOFE | bash -s -- 2.5.0 1.5.5

# Add Fabric binaries to PATH
echo 'export PATH=$PATH:$HOME/fabric/bin' >> ~/.profile
source ~/.profile

This script downloads: - Fabric CLI binaries (peer, orderer, configtxgen, etc.) - Fabric Docker images - Fabric-CA Docker images - Fabric samples repository

Setting Up Development Tools

For chaincode and application development, additional tools are helpful:

Visual Studio Code Setup

  1. Install Visual Studio Code
  2. Install extensions:
  3. Go extension
  4. Node.js extension
  5. Docker extension
  6. YAML extension
  7. IBM Blockchain Platform extension

Go Development Environment

# Install Go tools
go install golang.org/x/tools/gopls@latest
go install github.com/go-delve/delve/cmd/dlv@latest
go install honnef.co/go/tools/cmd/staticcheck@latest

Node.js Development Environment

# Install global packages
npm install -g typescript ts-node nodemon

Network Configuration Files

Before setting up a network, you'll need to prepare configuration files:

configtx.yaml

This file defines the network configuration, including: - Organizations - Capabilities - Policies - Channel profiles - Orderer configuration

crypto-config.yaml

This file defines the cryptographic material to be generated: - Organizations - Number of peers per organization - Number of users per organization - CA configuration

docker-compose.yaml

This file defines the Docker containers for: - Orderer nodes - Peer nodes - CA servers - CLI tools

Environment Variables

Set up environment variables for Fabric commands:

# Create a script to set environment variables
cat > ~/fabric/set-env.sh << EOF
#!/bin/bash

# Fabric configuration path
export FABRIC_CFG_PATH=\$HOME/fabric/config

# Peer environment variables
export CORE_PEER_TLS_ENABLED=true
export CORE_PEER_LOCALMSPID="Org1MSP"
export CORE_PEER_TLS_ROOTCERT_FILE=\$HOME/fabric/organizations/peerOrganizations/org1.example.com/peers/peer0.org1.example.com/tls/ca.crt
export CORE_PEER_MSPCONFIGPATH=\$HOME/fabric/organizations/peerOrganizations/org1.example.com/users/Admin@org1.example.com/msp
export CORE_PEER_ADDRESS=localhost:7051

# Orderer environment variables
export ORDERER_CA=\$HOME/fabric/organizations/ordererOrganizations/example.com/orderers/orderer.example.com/msp/tlscacerts/tlsca.example.com-cert.pem
EOF

chmod +x ~/fabric/set-env.sh

Troubleshooting Common Setup Issues

Docker Issues

  1. Permission denied bash sudo chmod 666 /var/run/docker.sock

  2. Docker service not running bash sudo systemctl start docker

  3. Insufficient disk space bash docker system prune -a

Network Issues

  1. Port conflicts ```bash # Check for port usage sudo netstat -tulpn | grep

# Kill process using the port sudo kill -9 ```

  1. Firewall blocking connections bash # Allow Docker traffic sudo ufw allow from 172.16.0.0/12 to any sudo ufw allow from 192.168.0.0/16 to any

Fabric Binary Issues

  1. Binary not found ```bash # Check PATH echo $PATH

# Verify binary exists ls -la ~/fabric/bin ```

  1. Wrong version ```bash # Check version peer version

# Reinstall correct version curl -sSL https://bit.ly/2ysbOFE | bash -s -- ```

By properly setting up your environment with these prerequisites, you'll have a solid foundation for developing and deploying Hyperledger Fabric networks. The next sections will guide you through the process of creating and configuring a Fabric network.