继续浏览精彩内容
慕课网APP
程序员的梦工厂
打开
继续
感谢您的支持,我会继续努力的
赞赏金额会直接到老师账户
将二维码发送给自己后长按识别
微信支付
支付宝支付

实战-超级账本 fabric 环境搭建,创建我们的第一条网络

小锟哥哥
关注TA
已关注
手记 27
粉丝 1.6万
获赞 399
环境说明:
  • 系统 :macOS 10.13.2

文:谦益

1、安装 Node.js 以及 npm

在nodejs官网直接下载安装包就好了

https://nodejs.org/en/

2、安装Python

这里他不支持Python3.x 只支持2.7,这个还好,mac自带的Python就是2.7所以不需要处理。

3、安装docker

打开官方的下载地址:

https://www.docker.com/community-edition#/mac

找到 Download from Docker Store 点击旁边的蓝色下载箭头就能下载了。

下载后打开拖到你的应用里面就好。

4、安装go

打开 go 的官方下载地址:

https://golang.org/dl/

点击就能下载了,下载后直接打开,下一步下一步就好了。

这里我们安装的版本是1.10.1,安装完后我们需要进行一个环境变量配置:

  • 1、打开终端 cd ~ 用户主目录
  • 2、vim .bash_profile 编辑.bash_profile文件
  • 3、编辑内容如下:
    export GOPATH=这里指定go的工作目录
    export GOBIN=这里指定go的安装目录 定位到 bin 文件夹
    export PATH=$PATH:$GOBIN
  • 4、重新生效.bash_profile文件,命令如下:
    source ~/.bash_profile

    到这里你重新再启动一个终端,输入 go env就能看到最新的环境变量了。

    这里批注下:
    如果你不知道你的go安装目录在哪里,你在安装完下在的pkg包后,输入 go env就能看到默认的go环境变量配置了,此时里面的GOROOT就是安装目录。

5、执行安装脚本

从官网http://hyperledger-fabric.readthedocs.io/en/latest/install.html可以看到,安装需要执行一个脚本:

curl -sSL https://goo.gl/6wtTN5 | bash -s 1.1.0

这个脚本需要科学上网,如果不能科学上网的话,我把脚本下载下来了。

#!/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.1.0
# if ca version not passed in, default to latest released version
export CA_VERSION=$VERSION
# current version of thirdparty images (couchdb, kafka and zookeeper) released
export THIRDPARTY_IMAGE_VERSION=0.4.6
export ARCH=$(echo "$(uname -s|tr '[:upper:]' '[:lower:]'|sed 's/mingw64_nt.*/windows/')-$(uname -m | sed 's/x86_64/amd64/g')" | awk '{print tolower($0)}')
#Set MARCH variable i.e ppc64le,s390x,x86_64,i386
MARCH=`uname -m`

printHelp() {
  echo "Usage: bootstrap.sh [<version>] [<ca_version>] [-d -s -b]"
  echo
  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.1.1 -s"
  echo "would download docker images and binaries for version 1.1.1"
}

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
}

: ${CA_TAG:="$MARCH-$CA_VERSION"}
: ${FABRIC_TAG:="$MARCH-$VERSION"}
: ${THIRDPARTY_TAG:="$MARCH-$THIRDPARTY_IMAGE_VERSION"}

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} branch 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} branch 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
}

binariesInstall() {
  echo "===> Downloading version ${FABRIC_TAG} platform specific fabric binaries"
  curl https://nexus.hyperledger.org/content/repositories/releases/org/hyperledger/fabric/hyperledger-fabric/${ARCH}-${VERSION}/hyperledger-fabric-${ARCH}-${VERSION}.tar.gz | tar xz

  echo "===> Downloading version ${CA_TAG} platform specific fabric-ca-client binary"
  curl https://nexus.hyperledger.org/content/repositories/releases/org/hyperledger/fabric-ca/hyperledger-fabric-ca/${ARCH}-${VERSION}/hyperledger-fabric-ca-${ARCH}-${VERSION}.tar.gz | tar xz
  if [ $? != 0 ]; then
     echo
     echo "------> ${CA_TAG} fabric-ca-client binary is not available to download  (Avaialble 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 echo $1 | grep -q '\d'; then
  VERSION=$1;shift
  if echo $1 | grep -q '\d'; then
    CA_VERSION=$1;shift
  fi
fi

# 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

可以把这个脚本保存为 install.sh 在你要安装的目录下面,再执行:

bash ./install.sh

这个脚本会去Docker Hub上下载相应的镜像到本地的docker里面。
执行完毕后,会列出刚下载的进行。

同时,还会去下载对应平台的二进制文件,也就是bin目录。

当着脚本执行完毕我们还需要把,bin目录加到 PATH 里面,执行下面的命令:

export PATH=你下载的项目绝对地址/bin:$PATH
6、创建第一条网络

我们参照文档:

http://hyperledger-fabric.readthedocs.io/en/latest/build_network.html
  • fabric-samples/first-network目录下面:
    cd fabric-samples/first-network
  • 创建我们的第一条网络
    这里需要说明下,为了保险起见,先把之前的网络关闭了,命令如下:
    ./byfn.sh -m down

    再创建

    ./byfn.sh -m generate

当看到下面的这个提示,说明就创建成功了。

下载失败处理办法:

如果这里面的插件老是下载不全。

可以把下载地址打印出来,你根据这个地址,把文件下载到本地,在本地搭建一个环境,从本地环境下载下来。

[获取授权]

打开App,阅读手记
7人推荐
发表评论
随时随地看视频慕课网APP

热门评论

赞博主分享。推荐一个超级账本fabric的开发课程:Hyperledger Fabric Nodejs开发详解

查看全部评论