The environment
Different from the previous setup 1.0, virtual machines or servers are recommended.
[Note] There may be some minor issues with WSL
I am using Ubuntu1804 ali cloud server to build.
You are advised to use the root user to save time and effort.
Dependent environment: Refer to build 1.4.x environment. A reference link is provided below. Environment dependent setup
What are the updates to version 2.0 compared to version 1.0
Skip this chapter if you don’t want to. This document is an official document.
I recommend going straight to the next section, because you might not be able to read it. Here’s the official link.
Install Hyperleger Fabric 2.2.0
Solution 1: Script installation
This method is the simplest and most convenient installation method. However, downloading the image is a foreign image, so it may be slow. It is recommended to test this out first. If it can be the best, if not please refer to installation plan two.
When we thought there would be an official bootstrap.sh installation script like version 1.0, it didn’t exist. Where is the one-click setup script? The authorities took it out separately. Here you are.
Raw.githubusercontent.com/hyperledger…
The installation script is almost identical to that of 1.4.x. For script analysis, see Installation Script Analysis
Based on the previous analysis, I will modify this script to configure some domestic acceleration. Here is the accelerated bootstrap.sh installation script. The script also performs the following operations.
- Install the Docker image
- Installing binaries
- Install the official sample
Here is the optimized bootstrap.sh. (Remember to manually configure domestic Docker image acceleration yourself) copy the following contents to the working directory we just created. (Remember to start the Docker service before executing the script.) We used the official documentation recommended version 2.2.0 1.4.7
Here I created a new path /root/fabric-samples-2.x
Save the following script as bootstrap.sh and put it in the project folder you want to execute.
#!/bin/bash
#
# Copyright IBM Corp. All Rights Reserved.
#
# SPDX-License-Identifier: Apache-2.0
#
# if version not passed in, default to latest released version
VERSION=2.3.3
# if ca version not passed in, default to latest released version
CA_VERSION=1.5.2
ARCH=$(echo "$(uname -s|tr '[:upper:]' '[:lower:]'|sed 's/mingw64_nt.*/windows/')-$(uname -m | sed 's/x86_64/amd64/g')")
MARCH=$(uname -m)
printHelp() {
echo "Usage: bootstrap.sh [version [ca_version]] [options]"
echo
echo "options:"
echo "-h : this help"
echo "-d : bypass docker image download"
echo "-s : bypass fabric-samples repo clone"
echo "-b : bypass download of platform-specific binaries"
echo
echo "e.g. bootstrap.sh 2.3.3 1.5.2 -s"
echo "will download docker images and binaries for Fabric v2.3.3 and Fabric CA v1.5.2"
}
# dockerPull() pulls docker images from fabric and chaincode repositories
# note, if a docker image doesn't exist for a requested release, it will simply
# be skipped, since this script doesn't terminate upon errors.
dockerPull() {
#three_digit_image_tag is passed in, e.g. "1.4.7"
three_digit_image_tag=$1
shift
#two_digit_image_tag is derived, e.g. "1.4", especially useful as a local tag for two digit references to most recent baseos, ccenv, javaenv, nodeenv patch releases
two_digit_image_tag=$(echo "$three_digit_image_tag" | cut -d'.' -f1,2)
while [[ $# -gt 0 ]]
do
image_name="$1"
echo "====> hyperledger/fabric-$image_name:$three_digit_image_tag"
docker pull "hyperledger/fabric-$image_name:$three_digit_image_tag"
docker tag "hyperledger/fabric-$image_name:$three_digit_image_tag" "hyperledger/fabric-$image_name"
docker tag "hyperledger/fabric-$image_name:$three_digit_image_tag" "hyperledger/fabric-$image_name:$two_digit_image_tag"
shift
done
}
cloneSamplesRepo() {
# clone (if needed) hyperledger/fabric-samples and checkout corresponding
# version to the binaries and docker images to be downloaded
if [ -d test-network ]; then
# if we are in the fabric-samples repo, checkout corresponding version
echo "==> Already in fabric-samples repo"
elif [ -d fabric-samples ]; then
# if fabric-samples repo already cloned and in current directory,
# cd fabric-samples
echo "===> Changing directory to fabric-samples"
cd fabric-samples
else
echo "===> Cloning hyperledger/fabric-samples repo"
git clone -b main https://gitee.com/hyperledger/fabric-samples.git && cd fabric-samples
fi
if GIT_DIR=.git git rev-parse v${VERSION} >/dev/null 2>&1; then
echo "===> Checking out v${VERSION} of hyperledger/fabric-samples"
git checkout -q v${VERSION}
else
echo "fabric-samples v${VERSION} does not exist, defaulting to main. fabric-samples main branch is intended to work with recent versions of fabric."
git checkout -q main
fi
}
# This will download the .tar.gz
download() {
local BINARY_FILE=$1
local URL=$2
echo "===> Downloading: " "${URL}"
curl -L --retry 5 --retry-delay 3 "${URL}" | tar xz || rc=$?
if [ -n "$rc" ]; then
echo "==> There was an error downloading the binary file."
return 22
else
echo "==> Done."
fi
}
pullBinaries() {
echo "===> Downloading version ${FABRIC_TAG} platform specific fabric binaries"
download "${BINARY_FILE}" "https://hub.fastgit.org/hyperledger/fabric/releases/download/v${VERSION}/${BINARY_FILE}"
if [ $? -eq 22 ]; then
echo
echo "------> ${FABRIC_TAG} platform specific fabric binary is not available to download <----"
echo
exit
fi
echo "===> Downloading version ${CA_TAG} platform specific fabric-ca-client binary"
download "${CA_BINARY_FILE}" "https://hub.fastgit.org/hyperledger/fabric-ca/releases/download/v${CA_VERSION}/${CA_BINARY_FILE}"
if [ $? -eq 22 ]; then
echo
echo "------> ${CA_TAG} fabric-ca-client binary is not available to download (Available from 1.1.0-rc1) <----"
echo
exit
fi
}
pullDockerImages() {
command -v docker >& /dev/null
NODOCKER=$?
if [ "${NODOCKER}" == 0 ]; then
FABRIC_IMAGES=(peer orderer ccenv tools)
case "$VERSION" in
2.*)
FABRIC_IMAGES+=(baseos)
shift
;;
esac
echo "FABRIC_IMAGES:" "${FABRIC_IMAGES[@]}"
echo "===> Pulling fabric Images"
dockerPull "${FABRIC_TAG}" "${FABRIC_IMAGES[@]}"
echo "===> Pulling fabric ca Image"
CA_IMAGE=(ca)
dockerPull "${CA_TAG}" "${CA_IMAGE[@]}"
echo "===> List out hyperledger docker images"
docker images | grep hyperledger
else
echo "========================================================="
echo "Docker not installed, bypassing download of Fabric images"
echo "========================================================="
fi
}
DOCKER=true
SAMPLES=true
BINARIES=true
# Parse commandline args pull out
# version and/or ca-version strings first
if [ -n "$1" ] && [ "${1:0:1}" != "-" ]; then
VERSION=$1;shift
if [ -n "$1" ] && [ "${1:0:1}" != "-" ]; then
CA_VERSION=$1;shift
if [ -n "$1" ] && [ "${1:0:1}" != "-" ]; then
THIRDPARTY_IMAGE_VERSION=$1;shift
fi
fi
fi
# prior to 1.2.0 architecture was determined by uname -m
if [[ $VERSION =~ ^1.[0-1].* ]]; then
export FABRIC_TAG=${MARCH}-${VERSION}
export CA_TAG=${MARCH}-${CA_VERSION}
export THIRDPARTY_TAG=${MARCH}-${THIRDPARTY_IMAGE_VERSION}
else
# starting with 1.2.0, multi-arch images will be default
: "${CA_TAG:="$CA_VERSION"}"
: "${FABRIC_TAG:="$VERSION"}"
: "${THIRDPARTY_TAG:="$THIRDPARTY_IMAGE_VERSION"}"
fi
BINARY_FILE=hyperledger-fabric-${ARCH}-${VERSION}.tar.gz
CA_BINARY_FILE=hyperledger-fabric-ca-${ARCH}-${CA_VERSION}.tar.gz
# then parse opts
while getopts "h?dsb" opt; do
case "$opt" in
h|?)
printHelp
exit 0
;;
d) DOCKER=false
;;
s) SAMPLES=false
;;
b) BINARIES=false
;;
esac
done
if [ "$SAMPLES" == "true" ]; then
echo
echo "Clone hyperledger/fabric-samples repo"
echo
cloneSamplesRepo
fi
if [ "$BINARIES" == "true" ]; then
echo
echo "Pull Hyperledger Fabric binaries"
echo
pullBinaries
fi
if [ "$DOCKER" == "true" ]; then
echo
echo "Pull Hyperledger Fabric docker images"
echo
pullDockerImages
fi
Copy the code
Chmod u+x bootstrap.sh # where 2.2.0 indicates the executable script version and 1.4.7 indicates the CA version sudo./bootstrap.sh 2.2.0 1.4.7Copy the code
The result of the execution. At the same time, you can see that the related Docker image has been downloaded successfully, and the corresponding executable file exists in the bin directory.
Scheme 2: Semi-automatic installation
We only use part of the above script function —- download the Docker image function, download the fabric-Samplesa function. Other functions are downloaded manually. Speed up installation.
First let’s modify the bootstrap.sh file above. Change BINARIES to false.
Then execute the above script.
. / the bootstrap. Sh 2.2.0 1.4.7Copy the code
After execution, fabric-samples will be generated and many images will be downloaded for use
Then download the relevant files we need.
- Download binary file, version 2.2.0. Download address: github.com/hyperledger…
- Download the CA file 1.4.7. Download: github.com/hyperledger…
Copy the downloaded files to the server (or to the project folder you just created in the virtual machine)
Run the tar command to decompress the package:
Gz tar -zxvf Hyperledger-fabric-ca-linux-amd64-1.4.7.tar. gz tar -zxvf Hyperledger-fabric-linux-amd64-2.1.0.tar. gzCopy the code
At this point, two folders, bin Config, will be generated and copied to fabric-samples along with their contents. At this point we can see the following.
mv bin fabric-samples
mv config fabric-samples
Copy the code
This means that we have successfully installed it.
Test the network test it
CD test-network./network down # Use down to clean the environment./network upCopy the code
When we see this part, we have started successfully.