3.安装fabric 二进制源码程序

本文详细介绍了如何搭建HyperledgerFabric环境,包括下载和安装fabric二进制源码,生成身份信息文件和系统通道文件,以及启动网络节点。还提供了在无法访问官网时的替代下载方法,以及手动下载和配置所需的各种组件。此外,文章还强调了解决启动Fabric网络时可能出现的问题,如找不到特定镜像,并给出了相应的解决方案。
摘要由CSDN通过智能技术生成

章节目录

1.hyperledger-fabric 介绍和资料整理
2.服务环境准备
3.安装fabric 二进制源码程序
4.生成fabric身份信息文件(证书)
5.生成系统通道初始区块文件
6.启动配置网络节点 docker-compose启动文件
7.将组织加入通道
8.安装合约
configtx.yaml 详解
crypto-config.yaml配置详解

3.安装fabric 二进制源码程序

1.下载bootstrap.sh 文件,安装应用

下载二进制文件和镜像官网提示命令:

curl -sSL https://bit.ly/2ysbOFE | bash -s

官网地址无法访问,可以通过浏览器可直接打开 https://bit.ly/2ysbOFE 查看脚本(科学上网),浏览器打开的内容与fabric/script中的bootstrap.sh是一样的

bootstrap.sh 文件github地址:

https://raw.githubusercontent.com/hyperledger/fabric/master/scripts/bootstrap.sh

将此文件下载到对应的项目录下使用。

在这里插入图片描述

如果没有科学上网的同学,可以直接使用下面的的脚本代码,保存为bootstrap.sh 文件使用。

./bootstrap.sh -sb

注:执行此脚本,下载二进制源码和镜像慢或下载失败的话,可以查看后面 2~6 子目录的内容,进行手动下载安装。

#!/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.4.4
# if ca version not passed in, default to latest released version
CA_VERSION=1.5.5
ARCH=$(echo "$(uname -s|tr '[:upper:]' '[:lower:]'|sed 's/mingw64_nt.*/windows/')-$(uname -m |sed 's/x86_64/amd64/g')" |sed 's/darwin-arm64/darwin-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.4.4 1.5.5 -s"
    echo "will download docker images and binaries for Fabric v2.4.4 and Fabric CA v1.5.5"
}

# 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://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 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://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

2.下载fabric-sample源码

在这里插入图片描述

手动输入命令下载源码

git clone https://gitee.com/guandw/fabric-samples.git

如果已经克隆了我的仓库的fabric-samples下面的这步操作就不用看了。

3. 拉取二进制文件

先来看看脚本文件里面是怎么样操作的

在这里插入图片描述

3.1.fabric​二进制文件下载

​ https://github.com/hyperledger/fabric/releases(根据自己对应版本的脚本文件里的地址下载对应版本二进制文件)

在这里插入图片描述
​​​​

选取对应的操作系统,一般就是linux 右键复制链接后,直接用wget命令

wget https://github.com/hyperledger/fabric/releases/download/v2.5.3/hyperledger-fabric-linux-amd64-2.5.3.tar.gz

3.2.fabric-ca 二进制文件下载

下载地址:发布 ·Hyperledger/fabric-ca (github.com)

https://github.com/hyperledger/fabric-ca/releases/ (根据自己的版本进行下载)
在这里插入图片描述

同样右键复制链接 使用wget

wget https://github.com/hyperledger/fabric-ca/releases/download/v1.5.6/hyperledger-fabric-ca-linux-amd64-1.5.6.tar.gz

3.3.解压这俩文件

tar zvxf xxxxxx(你下载压缩文件)

tar zvxf xxxxxx(你下载压缩文件)

解压后有lib和config文件移动到自己项目目录下

mv bin/ /home/hyperledgerFabric/qkl_01/

mv confing/ /home/hyperledgerFabric/qkl_01/

在这里插入图片描述

配置环境变量

export PATH=$PATH:/home/hyperledgerFabric/qkl_01/bin

4.从docker官网上拉取镜像

在这里插入图片描述

需要从docker官网上拉取2.4.4的peer 、orderer、 ccenv、 tools、ca、-baseos资源镜像,挂载docker 容器里,这里拉取的镜像无法直接使用,可以借助他的脚本来拉取镜像。
在这里插入图片描述

因为我们已经手动下载了fabric-sample源码、fabric、fabric-ca二进制文件了,所以不需要再下载,注释掉文件中的

#cloneSamplesRepo​ 和 #pullBinaries​ 两个;只需要 pullDockerImages​ 拉取pull peer 、orderer、 ccenv、 tools、ca、-baseos资源镜像就可以。

最后执行脚本命令,拉取安装镜像

./bootstrap.sh -sb

在这里插入图片描述

拉取安装完后镜像如下:

在这里插入图片描述

5.问题解决

启动Fabric first-network 时出现ERROR: manifest for hyperledger/fabric-tools:latest not found: manifest unknown: manifest unknown

在这里插入图片描述

docker镜像官网:https://hub.docker.com/search?q=hyperledger

`#下载该镜像
docker pull hyperledger/fabric-tools:1.4.11
然后修改本地的Tags为latest;
docker tag hyperledger/fabric-tools:1.4.11 hyperledger/fabric-tools:latest`

注:如果出现脚本拉取失败,缺少对应的镜像版本的,都可以通过去docker镜像官网手动方式获取。

6.整理fabric需要的所有镜像名称

docker pull  hyperledger/fabric-ca:x.x.x
docker pull hyperledger/fabric-tools:x.x.x 
docker pull hyperledger/fabric-peer:x.x.x
docker pull hyperledger/fabric-orderer:x.x.x
docker pull hyperledger/fabric-ccenv:x.x.x
docker pull hyperledger/fabric-baseos:x.x.x
docker pull hyperledger/fabric-javaenv:x.x.x
docker pull busybox:x.x.x

6.1 镜像版本控制

bootstrap.sh 脚本中fabric、ca对应控制版本,可以根据自己实际情况修改

在这里插入图片描述

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值