hyperledger fabric 1.4.4版本安装手册

系统环境

系统:centos7
内存:32G
磁盘:700G

前期准备

  • 安装git
  • 安装curl
  • 安装wget

安装nodejs

下载并解压

下载链接:https://nodejs.org/en/download/,为保证版本兼容,我这里选择的是v8.9.0版本

wget https://nodejs.org/dist/v8.9.0/node-v8.9.0-linux-x64.tar.xz
tar -xvf node-v8.9.0-linux-x64.tar.xz
cd node-v8.9.0-linux-x64

配置环境变量

vim /etc/profile
# 在最下面添加 export PATH=$PATH: 后面跟上node下bin目录的路径
export PATH=$PATH:/home/sft/node-v8.9.0-linux-x64/bin
source /etc/profile

查看是否安装成功

[root@bd225 sft]# node -v
v8.9.0

OK!安装成功!

安装golang

下载并解压

# 建议下载1.13.8以上的版本,否则编译fabric的时候会报错
wget https://dl.google.com/go/go1.13.8.linux-amd64.tar.gz
tar -xvf go1.13.8.linux-amd64.tar.gz
mv ./go /usr/local

创建GO工作目录

mkdir -p /home/go/src

设置环境变量

vim  /etc/profile
# 在最下面添加下面三行代码
export  GOROOT=/usr/local/go
export  GOPATH=/home/go
export  PATH=$PATH:$GOROOT/bin

source /etc/profile

安装docker

配置yum源

vim /etc/yum.repos.d/docker.repo
# 在文件中保存如下内容
[docker]
name=Docker
baseurl=https://yum.dockerproject.org/repo/main/centos/7/
enabled=1
gpgcheck=1
gpgkey=https://yum.dockerproject.org/gpg
# 安装所需的软件包。
yum install -y yum-utils device-mapper-persistent-data lvm2
# 使用以下命令来设置稳定的仓库。
yum-config-manager --add-repo https://download.docker.com/linux/centos/docker-ce.repo
# 安装最新版本的 Docker Engine-Community 和 containerd
yum install docker-ce docker-ce-cli containerd.io
# 启动docker,并查看docker信息
systemctl start docker
systemctl status docker
docker info
docker version   
docker -v

设置国内镜像源

  1. 选择镜像源
    • 进入阿里云的容器镜像服务
      快速链接: 容器镜像服务
    • Docker中国区官方镜像: https://registry.docker-cn.com
    • 网易: http://hub-mirror.c.163.com
    • ustc: https://docker.mirrors.ustc.edu.cn
    • 中国科技大学: https://docker.mirrors.ustc.edu.cn
  2. /etc/docker目录下找到在daemon.json文件(没有就新建),将下面内容写入
{
 "registry-mirrors": ["http://hub-mirror.c.163.com","https://registry.docker-cn.com","https://docker.mirrors.ustc.edu.cn"]
}
  1. 重启daemon
systemctl daemon-reload 
  1. 重启docker服务
systemctl restart docker 

修改默认网桥

解决安装完docker启动后ssh连不上的问题

ifconfig docker0

默认每个节点的docker网桥都是172.17.0.1/24,多节点通信则需要修改默认网关

vim /etc/docker/daemon.json
# 修改为如下内容
{
 "registry-mirrors": ["http://hub-mirror.c.163.com","https://registry.docker-cn.com","https://docker.mirrors.ustc.edu.cn"],
 "bip":"1.2.3.4/24"
}

然后重启docker

systemctl daemon-reload
systemctl restart  docker

(ip不要与宿主机器同网段,然后ssh服务即可恢复)

如果已经连接不上,则可以通过如下方式解决
登陆同网段的别的节点,然后通过ssh登陆到断网的节点。

docker network list
NETWORK ID          NAME                DRIVER              SCOPE
07504d75d110        bridge              bridge              local
aa96afbfd2e8        host                host                local
86c2c0a1fabd        none                null                local
f87c6fa2c8b9        test-net            bridge              local
# 找到导致问题的网络,然后删除即可
docker network rm test-net

安装docker-compose

# 安装python-pip
yum -y install epel-release
yum -y install python-pip
# 安装docker-compose
pip install docker-compose
# 待安装完成后,即可执行查询版本的命令
docker-compose version

安装fabric

拉取fabric编译二进制文件

cd $GOPATH/src/github.com/hyperledger
# 文件较大,可能会耗时比较长
git clone https://github.com/hyperledger/fabric.git
cd fabric
# 查看版本号
git tag
# 切换到1.4.4版本分支下
git checkout v1.4.4
# 查看当前分支
git branch -a
# 可以看到已经切换到1.4.4下
* (分离自 v1.4.4)
  master
  remotes/origin/HEAD -> origin/master
  remotes/origin/feature/ca
  remotes/origin/feature/convergence
  remotes/origin/master
  remotes/origin/release-1.0
  remotes/origin/release-1.1
  remotes/origin/release-1.2
  remotes/origin/release-1.3
  remotes/origin/release-1.4
  remotes/origin/release-2.0
  remotes/origin/v0.6
  remotes/origin/v1.0.0-preview
# 编译
make release

安装docker镜像

cd $GOPATH/src/github.com/hyperledger/fabric/scripts
sh bootstrap.sh

bootstrap.sh实际上帮我们作了如下几件事情:

  1. 从github上克隆 hyperledger/fabric-samples并进入该目录,然后检出适当的版本
  2. 在fabric-samples目录下安装特定平台的 Hyperledger Fabric 二进制可执行文件 和配置文件
  3. 下载 指定版本的Hyperledger Fabric 的docker镜像

我这里运行sh bootstrap.sh会报错,curl: (6) Could not resolve host: nexus.hyperledger.org; 未知的错误
全部的报错信息如下:

Installing Hyperledger Fabric binaries

===> Downloading version 1.4.4 platform specific fabric binaries
===> Downloading:  https://nexus.hyperledger.org/content/repositories/releases/org/hyperledger/fabric/hyperledger-fabric/linux-amd64-1.4.4/hyperledger-fabric-linux-amd64-1.4.4.tar.gz
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
  0     0    0     0    0     0      0      0 --:--:-- --:--:-- --:--:--     0curl: (6) Could not resolve host: nexus.hyperledger.org; 未知的错误

gzip: stdin: unexpected end of file
tar: Child returned status 1
tar: Error is not recoverable: exiting now
==> There was an error downloading the binary file. Switching to incremental download.
==> Downloading file...
Failure downloading binaries (curl RC=6). Please try again and the download will resume from where it stopped.

这其实是nexus.hyperledger.org这个网站已经不再维护了,2.0.0之后的版本都是从github上直接下载了。所以运行脚本修改为如下:

#!/bin/bash
#
# Copyright IBM Corp. All Rights Reserved.
#
# SPDX-License-Identifier: Apache-2.0
#

# if version not passed in, default to latest released version
export VERSION=1.4.4
# if ca version not passed in, default to latest released version
export CA_VERSION=1.4.4
# current version of thirdparty images (couchdb, kafka and zookeeper) released
export THIRDPARTY_IMAGE_VERSION=0.4.18
export ARCH=$(echo "$(uname -s|tr '[:upper:]' '[:lower:]'|sed 's/mingw64_nt.*/windows/')-$(uname -m | sed 's/x86_64/amd64/g')")
export 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 1.4.4 -s"
  echo "would download docker images and binaries for version 1.4.4"
}

dockerFabricPull() {
  local FABRIC_TAG=$1
  for IMAGES in peer orderer ccenv javaenv tools; do
      echo "==> FABRIC IMAGE: $IMAGES"
      echo
      docker pull hyperledger/fabric-$IMAGES:$FABRIC_TAG
      docker tag hyperledger/fabric-$IMAGES:$FABRIC_TAG hyperledger/fabric-$IMAGES
  done
}

dockerThirdPartyImagesPull() {
  local THIRDPARTY_TAG=$1
  for IMAGES in couchdb kafka zookeeper; do
      echo "==> THIRDPARTY DOCKER IMAGE: $IMAGES"
      echo
      docker pull hyperledger/fabric-$IMAGES:$THIRDPARTY_TAG
      docker tag hyperledger/fabric-$IMAGES:$THIRDPARTY_TAG hyperledger/fabric-$IMAGES
  done
}

dockerCaPull() {
      local CA_TAG=$1
      echo "==> FABRIC CA IMAGE"
      echo
      docker pull hyperledger/fabric-ca:$CA_TAG
      docker tag hyperledger/fabric-ca:$CA_TAG hyperledger/fabric-ca
}

samplesInstall() {
  # 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 "===> Checking out v${VERSION} of hyperledger/fabric-samples"
    git checkout v${VERSION}
  elif [ -d fabric-samples ]; then
    # if fabric-samples repo already cloned and in current directory,
    # cd fabric-samples and checkout corresponding version
    echo "===> Checking out v${VERSION} of hyperledger/fabric-samples"
    cd fabric-samples && git checkout v${VERSION}
  else
    echo "===> Cloning hyperledger/fabric-samples repo and checkout v${VERSION}"
    git clone -b master https://github.com/hyperledger/fabric-samples.git && cd fabric-samples && git checkout v${VERSION}
  fi
}

# Incrementally downloads the .tar.gz file locally first, only decompressing it
# after the download is complete. This is slower than binaryDownload() but
# allows the download to be resumed.
binaryIncrementalDownload() {
      local BINARY_FILE=$1
      local URL=$2
      curl -f -s -C -L --retry 5 --retry-delay 3 - ${URL} -o ${BINARY_FILE} || rc=$?
      # Due to limitations in the current Nexus repo:
      # curl returns 33 when there's a resume attempt with no more bytes to download
      # curl returns 2 after finishing a resumed download
      # with -f curl returns 22 on a 404
      if [ "$rc" = 22 ]; then
	  # looks like the requested file doesn't actually exist so stop here
	  return 22
      fi
      if [ -z "$rc" ] || [ $rc -eq 33 ] || [ $rc -eq 2 ]; then
          # The checksum validates that RC 33 or 2 are not real failures
          echo "==> File downloaded. Verifying the md5sum..."
              tar xzf ./${BINARY_FILE} --overwrite
      else
          echo "Failure downloading binaries (curl RC=$rc). Please try again and the download will resume from where it stopped."
          exit 1
      fi
}

# This will attempt to download the .tar.gz all at once, but will trigger the
# binaryIncrementalDownload() function upon a failure, allowing for resume
# if there are network failures.
binaryDownload() {
      local BINARY_FILE=$1
      local URL=$2
      echo "===> Downloading: " ${URL}
      # Check if a previous failure occurred and the file was partially downloaded
      if [ -e ${BINARY_FILE} ]; then
          echo "==> Partial binary file found. Resuming download..."
          binaryIncrementalDownload ${BINARY_FILE} ${URL}
      else
          curl -L --retry 5 --retry-delay 3 ${URL} | tar xz || rc=$?
          if [ ! -z "$rc" ]; then
              echo "==> There was an error downloading the binary file. Switching to incremental download."
              echo "==> Downloading file..."
              binaryIncrementalDownload ${BINARY_FILE} ${URL}
	  else
	      echo "==> Done."
          fi
      fi
}

binariesInstall() {
  echo "===> Downloading version ${FABRIC_TAG} platform specific fabric binaries"
  binaryDownload ${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
   fi

  echo "===> Downloading version ${CA_TAG} platform specific fabric-ca-client binary"
  binaryDownload ${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
   fi
}

dockerInstall() {
  which docker >& /dev/null
  NODOCKER=$?
  if [ "${NODOCKER}" == 0 ]; then
	  echo "===> Pulling fabric Images"
	  dockerFabricPull ${FABRIC_TAG}
	  echo "===> Pulling fabric ca Image"
	  dockerCaPull ${CA_TAG}
	  echo "===> Pulling thirdparty docker images"
	  dockerThirdPartyImagesPull ${THIRDPARTY_TAG}
	  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 [ ! -z "$1" -a ${1:0:1} != "-" ]; then
  VERSION=$1;shift
  if [ ! -z "$1"  -a ${1:0:1} != "-" ]; then
    CA_VERSION=$1;shift
    if [ ! -z "$1"  -a ${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 "Installing hyperledger/fabric-samples repo"
  echo
  samplesInstall
fi
if [ "$BINARIES" == "true" ]; then
  echo
  echo "Installing Hyperledger Fabric binaries"
  echo
  binariesInstall
fi
if [ "$DOCKER" == "true" ]; then
  echo
  echo "Installing Hyperledger Fabric docker images"
  echo
  dockerInstall
fi

也可以科学上网手动下载之后,放到/home/go/src/github.com/hyperledger/fabric/scripts/fabric-samples目录下。之后再运行bootstrap.sh
fabric下载链接为:https://github.com/hyperledger/fabric/releases/download/v1.4.4/hyperledger-fabric-linux-amd64-1.4.4.tar.gz
fabric-ca的下载链接为:https://github.com/hyperledger/fabric-ca/releases/download/v1.4.4/hyperledger-fabric-ca-linux-amd64-1.4.4.tar.gz

启动网络

进入/home/go/src/github.com/hyperledger/fabric/scripts/fabric-samples/first-network目录,运行./byfn.sh -m up即可启动网络,启动之后可能会出现命令行断开的情况。只需要登录同网段的节点,sshfabric节点,重新启动一下网络即可。

发布了26 篇原创文章 · 获赞 1 · 访问量 6956

猜你喜欢

转载自blog.csdn.net/qq_39800434/article/details/105094313