Hyperledger Fabric1.2环境搭建(亲测)
本篇文章是博主亲测的能够成功搭建Hyperledger Fabric1.2.0环境的步骤,希望可以帮助有需要的小伙伴在短时间内少走弯路成功上岸。加油呀!
由于博主也是小菜鸡,一些语言表达可能不专业,希望大家理解!!
操作系统
首先,我安装了win11+ubuntu16.04双系统。ubuntu双系统安装参考教程
注意!博主使用的是huawei matebook13,双系统安装完成后重启出现了直接进入win的情况,这里只需按F2将win11系统改成disable,就可以成功看到开机时的系统选择界面啦!
必备工具
1、Git & curl
sudo apt install git
sudo apt install curl
2、docker-ce(执行脚本的时候需要一点时间,要耐心等待一下哦)
curl -fsSL get.docker.com -o get-docker.sh
sudo sh get-docker.sh
安装完后了一测试一下
sudo docker run hello-world
3、docker-compose
sudo apt install docker-compose
4、go linux 版本Go下载,解压到 /usr/local 目录。 /usr目录在这里哦! 执行命令
mkdir $HOME/go
修改环境配置
vi ~/.bashrc
复制如下三个环境变量(复制粘贴时需要按“i”进入插入模式,复制后,先按"ESC"切换至命令模式,然后“:wq”保存并退出。)
export GOROOT=/usr/local/go
export GOPATH=$HOME/go
export PATH=$PATH:$GOROOT/bin:$GOPATH/bin
让配置文件生效
source ~/.bashrc
下载Fabric、Fabric-samples和二进制工具(建议在home下建立新的文件夹)
bin&config、fabric1.2.0、Fabric-samples1.2.0.
下载Fabric相关镜像
首先,保存以下内容bootstrap.sh
#!/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.1.0
# if ca version not passed in, default to latest released version
CA_VERSION=1.4.6
# current version of thirdparty images (couchdb, kafka and zookeeper) released
THIRDPARTY_IMAGE_VERSION=0.4.18
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 [thirdparty_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.1.0 1.4.6 0.4.18 -s"
echo "would download docker images and binaries for Fabric v2.1.0 and Fabric CA v1.4.6"
}
# 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.6"
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
}
pullDockerImages() {
command -v docker >& /dev/null
NODOCKER=$?
if [ "${NODOCKER}" == 0 ]; then
FABRIC_IMAGES=(peer orderer ccenv tools)
case "$VERSION" in
1.*)
FABRIC_IMAGES+=(javaenv)
shift
;;
2.*)
FABRIC_IMAGES+=(nodeenv baseos javaenv)
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 "===> Pulling thirdparty docker images"
THIRDPARTY_IMAGES=(zookeeper kafka couchdb)
dockerPull "${THIRDPARTY_TAG}" "${THIRDPARTY_IMAGES[@]}"
echo
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 [ "$DOCKER" == "true" ]; then
echo
echo "Pull Hyperledger Fabric docker images"
echo
pullDockerImages
fi
运行脚本前我们需要先配置阿里云镜像加速器 进入阿里云官网,注册一个属于自己的帐号,然后依次进入“控制台”-“产品与服务”,搜索“容器镜像服务**”根据教程进行配置即可。 然后就可以执行脚本啦。出现下图就成功啦。
修改脚本权限
chmod 755 bootstrap.sh
执行脚本并指定版本号
sudo ./bootstrap.sh 1.2.0 1.2.0 0.4.10
配置环境变量 环境变量配置路径是自己存放bin的路径 例如我的bin路径是/home/hyfa/fabric/fabric-samples/bin
vi ~/.bashrc
export PATH=$PATH:$GOROOT/bin:$GOPATH/bin:/home/hyfa/fabric/fabric-samples/bin
source ~/.bashrc
激动人心的时刻到来啦!测试环境是否搭建成功。
在存放first-network所在目录下进行启动。
./byfn.sh generate
./byfn.sh up
如果你成功看到了图片中的结果,那么你就和我一样上岸啦!
!!!在这里特别鸣谢“万生世代teikin”小姐姐,让我成功上岸! 小姐姐的原教程在这里哦!
|