安装过程中踩了n多的坑,centos7就装了很多次。后来发现,如果选择使用桌面版的centos7,最好选择下载Everything,虽然有10G大小,但是后面遇到的问题会少一点,具体可以参考:https://blog.csdn.net/qq_39135287/article/details/83993574?utm_medium=distribute.pc_relevant.none-task-blog-BlogCommendFromMachineLearnPai2-2.channel_param&depth_1-utm_source=distribute.pc_relevant.none-task-blog-BlogCommendFromMachineLearnPai2-2.channel_param
引用了这个链接:https://blog.csdn.net/u010857052/article/details/83931500
包含了docker、docker-compose、go 、git的安装步骤,亲测可行,安装简便。其中从链接第四步开始,本人做了些改动。
其中上图的第3小步设置环境变量时,记得用su命令进入root权限下再用vim /etc/profile,否则不能保存。有前辈建议GOPATH路径最好不要设置在root文件夹下(这个随个人意愿来,不是很重要),因此本人设置如下:
export PATH=$PATH:/usr/local/go/bin
export GOROOT=/usr/local/go
export GOPATH=/home/go/yu
export GOBIN=/home/yu/go/bin
引用了这个链接第三步:https://blog.csdn.net/Sun_Hui_/article/details/100928155
创建并进入 hyperledger 目录 ,最好将$GOPATH改成绝对地址,这样可以避免错误:
mkdir -p /home/yu/go/src/github.com/hyperledger
cd /home/yu/go/src/github.com/hyperledger
下载 fabric 源码:
git clone https://github.com/hyperledger/fabric.git
将 fabric 切换至 1.4 版本:
cd fabric
git branch -a
git checkout release-1.4
下载 docker-images1.4.3共7个 镜像:
cd /gopath/src/github.com/hyperledger/fabric/scripts
./bootstrap.sh
需要注意的是,本人下载的版本是hyperledger-fabric-linux-amd64-1.4.3.tar.gz和hyperledger-fabric-ca-linux-amd64-1.4.3.tar.gz,如果下载遇到问题,可以在命令前加上sudo。
使用脚本bootstrap.sh下载文件时,可能会遇到curl: (6) Could not resolve host: nexus.hyperledger.org; 未知的错误这种报错。经查询,问题在于原bootstrap.sh文件中的链接被墙,参考这个链接:https://blog.csdn.net/qq_39800434/article/details/105094313
若是更改bootstrap.sh文件时发现文件是只读,可以使用下面的命令更改权限:
chmod -R 777 scripts/
将bootstrap.sh文件的内容改成如下所示,如果不能运行,可以到https://github.com/hyperledger/fabric/tree/master/scripts去查看最新代码:
#!/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=1.4.3
# if ca version not passed in, default to latest released version
CA_VERSION=1.4.3
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.2.1 1.4.9 -s"
echo "will download docker images and binaries for Fabric v2.2.1 and Fabric CA v1.4.9"
}
# 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 first-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 master https://github.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 master"
git checkout -q master
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://github.com/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://github.com/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
建议上午5-8点间下载,速度会快上很多,一般9点之后最好就不要下载了,速度很慢卡在中间很难受,不如早起一会顺利下完。hyperledger-fabric-linux-amd64-1.4.3.tar.gz和hyperledger-fabric-ca-linux-amd64-1.4.3.tar.gz下载完之后,还会继续拉取、下载docker相关文件,同样在上述时间段一并完成,节约时间。
接下来,继续参考:https://blog.csdn.net/u010857052/article/details/83931507的第二步。
在实例化的过程中,可能会遇到:Error: could not assemble transaction, err proposal response was not successful, error code 500, msg error starting container: error starting containe的报错,很可能是因为安装centos7时配置的内存大小和处理器数量不足。本人的配置:
最后,踩坑数次之后,终于完成: