Setting Up a Hyperledger Fabric Environment on Linux
This post covers how to install and deploy a Fabric environment on Ubuntu and CentOS, and how to run an example that starts a Fabric network on a single machine.
1. Ubuntu
cURL
sudo apt-get install curlGit
sudo apt-get install gitNode.js
curl -sL https://deb.nodesource.com/setup_8.x | sudo -E bash -
sudo apt-get install -y nodejsDocker
This follows the repository-based installation method recommended in the official docs https://docs.docker.com/install/linux/docker-ce/ubuntu/. Note that the package sources used here are the default sources.list that ships with Ubuntu 16.04. If you have changed the sources, the installation will very likely fail.
- First, update the
aptpackage index:
sudo apt-get update- Install the packages required to use the repository:
sudo apt-get install \
apt-transport-https \
ca-certificates \
curl \
software-properties-common- Add the GPG key:
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add - Verify that the key fingerprint is 9DC8 5822 9FC7 DD38 854A E2D8 8D81 803C 0EBF CD88:
apt-key fingerprint 0EBFCD88- Add the repository
sudo add-apt-repository \
"deb [arch=amd64] https://download.docker.com/linux/ubuntu \
$(lsb_release -cs) \
stable"Update the apt-get repository information again and install Docker CE
sudo apt-get update
sudo apt-get install docker-ce- Once the installation succeeds, for convenience you can grant the current user (username)
dockerpermissions. (For this to take effect, you need to switch to the root user and back, or log out.)
sudo usermod -aG docker usernameDocker Compose
Run the following command to download it from github and make it executable:
sudo curl -L https://github.com/docker/compose/releases/download/1.19.0/docker-compose-`uname -s`-`uname -m` -o /usr/local/bin/docker-compose
chmod +x /usr/local/bin/docker-composeIf the download is slow, get it from DaoCloud instead
curl -L https://get.daocloud.io/docker/compose/releases/download/1.12.0/docker-compose-`uname -s`-`uname -m` > ~/docker-compose
sudo mv ~/docker-compose /usr/local/bin/docker-compose
chmod +x /usr/local/bin/docker-composeGo
- The version available through
apt-getis too old, so usewgetto download the latest version from the official site and save it to/usr/local
sudo wget https://storage.googleapis.com/golang/go1.9.linux-amd64.tar.gz
sudo tar -C /usr/local -xzf go1.9.linux-amd64.tar.gz- After installing, configure the environment variables:
vim ~/.profile- Add the following lines, where
GOROOTis the installation path andGOPATHis the workspace path:
export GOROOT=/usr/local/go
export PATH=$PATH:$GOROOT/bin
export GOPATH=$HOME/go
export PATH=$PATH:$GOPATH/binGOPATH, the Go workspace, is placed under the home directory ~, so you need to create the go directory:
cd ~
mkdir go2. CentOS
cURL
sudo yum install curlGit
sudo yum install gitNode.js (v8.11.3)
Download:
- http://nodejs.org/dist/v8.11.3/node-v8.11.3-linux-x64.tar.gz
- -zxvf node-v8.11.3-linux-x64.tar.gz
node-v8.11.3-linux-x64 /usr/local/src/node
- Configure the Node environment variable:
vim ~/.bash_profile
Add: export PATH=$PATH:/usr/local/src/node/binDocker (v18.03)
- Download URL (choose
docker-18.03.0-ce.tgz):
https://download.docker.com/linux/static/stable/x86_64/- Install
tar -zxvf docker-18.03.0-ce.tgz
sudo cp docker/* /usr/bin/
sudo chmod a+rw /var/run/docker.sock // grant access permission
sudo dockerd & // start the docker daemonNote: you can also install it in one step with sudo yum install docker-io
Docker Compose (v1.12.0)
curl -L https://get.daocloud.io/docker/compose/releases/download/1.12.0/docker-compose-`uname -s`-`uname -m` > ~/docker-compose
sudo mv ~/docker-compose /usr/local/bin/docker-compose
chmod +x /usr/local/bin/docker-compose // make it executableGo (v1.9)
- Install
sudo wget https://storage.googleapis.com/golang/go1.9.linux-amd64.tar.gz
sudo tar -C /usr/local -xzf go1.9.linux-amd64.tar.gz- Configure the environment variable
sudo vim ~/.bash_profile
Add: export PATH=$PATH:/usr/local/go/bin3. Deploying Fabric
Fabric source code
- First, create the directories and clone the
fabricsource code into them. Note that some tools in thefabricsource need to be compiled with Go, so the source must be cloned under theGOPATHpath. Otherwise, you will get errors when running the examples.
mkdir -p ~/go/src/github.com/hyperledger
cd ~/go/src/github.com/hyperledger
git clone https://github.com/hyperledger/fabric.git- You can switch the code to version
1.1.0
cd fabric
git checkout v1.1.0Downloading Fabric images (v1.1.0)
- Use the
DaoCloudregistry mirror:
curl -sSL https://get.daocloud.io/daotools/set_mirror.sh | sh -s http://6e4616d7.m.daocloud.io - Run the script in the project to download the Docker images in bulk. The arguments set which image versions to download
cd ~/go/src/github.com/hyperledger/fabric/examples/e2e_cli/
source download-dockerimages.sh -c x86_64-1.1.0 -f x86_64-1.1.0You can also download all the images with the following command
curl -sSL https://raw.githubusercontent.com/hyperledger/fabric/master/scripts/bootstrap.sh | bash -s 1.1.0- To pull a single image manually (using the peer image as an example):
docker pull hyperledger/fabric-peer:x86_64-1.1.0
docker tag <imageID> hyperledger/fabric-peer:latest // tag it as latestTesting the Fabric network
Here we start the e2e_cli example in Fabric to set up a simple network
- Go to the
e2e_clidirectory and run the script that starts the network:
cd ~/go/src/github.com/hyperledger/fabric/examples/e2e_cli
./network_setup.sh up- The script does the following:
- Compiles the cryptogen tool and uses it to generate certificates and private keys for the network members based on the crypto-config.yaml config file;
- Uses the configtxgen tool to generate, based on the configtx.yaml config file, the genesis block (used to start the orderer) and the channel configuration transaction (used to create the channel);
- Starts the containers defined in the docker-compose-cli.yaml config file: 4 peers + orderer + CLI;
- When the CLI container starts, it automatically runs the script
scripts/script.sh, which creates the channel, joins the peers to the channel, installs and instantiates the chaincode, and invokes the chaincode to run queries and transactions.
- Once it has run successfully, shut down the network
./network_setup.sh down
4 comments
Leave a Comment
- Previous: Hyperledger Fabric Basics
- Next: Deploying and Using Fabric CA
你这源码下载有啥用?
最后运行的example就是在源码中的,还包括网络运行所需的二进制工具、docker file、脚本等都在源码中。
你就是比特币之父?
狂跌不止