溫馨提示×

溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊×
其他方式登錄
點(diǎn)擊 登錄注冊 即表示同意《億速云用戶服務(wù)條款》

Hyperledger Fabric初識(shí)與環(huán)境搭建

發(fā)布時(shí)間:2020-06-16 19:18:00 來源:網(wǎng)絡(luò) 閱讀:23557 作者:暗黑魔君 欄目:編程語言

目錄

  1. Fabric簡介
  2. Fabric環(huán)境搭建
  3. Fabric目錄結(jié)構(gòu)
  4. Node環(huán)境搭建

一.Fabric 簡介

在介紹我們的主角Fabric之前,我們先來介紹一下它的父項(xiàng)目:Hyperledger-超級(jí)賬本

Hyperledger 項(xiàng)目是首個(gè)面向企業(yè)的開放區(qū)塊鏈技術(shù)的重要探索。在 Linux 基金會(huì)的支持下,吸引了包括 IBM、Intel、摩根等在內(nèi)的眾多科技和金融巨頭的參與。

1.發(fā)展歷史

區(qū)塊鏈已經(jīng)成為當(dāng)下最受人關(guān)注的開源技術(shù),有人說它將顛覆金融行業(yè)的未來。然而對很多人來說,區(qū)塊鏈技術(shù)難以理解和實(shí)現(xiàn),而且缺乏統(tǒng)一的規(guī)范。

2015 年 12 月,開源世界的旗艦——Linux 基金 會(huì)牽頭,聯(lián)合 30 家初始企業(yè)成員(包括 IBM、Accenture、Intel、J.P.Morgan、R3、DAH、DTCC、FUJITSU、HITACHI、SWIFT、Cisco 等),共同 宣告 了 Hyperledger 項(xiàng)目的成立。該項(xiàng)目試圖打造一個(gè)透明、公開、去中心化的分布式賬本項(xiàng)目,作為區(qū)塊鏈技術(shù)的開源規(guī)范和標(biāo)準(zhǔn),讓更多的應(yīng)用能更容易的建立在區(qū)塊鏈技術(shù)之上。項(xiàng)目官方信息網(wǎng)站在 hyperledger.org,

目前已經(jīng)有超過 120 家全球知名企業(yè)和機(jī)構(gòu)(大部分均為各自行業(yè)的領(lǐng)導(dǎo)者)宣布加入 Hyperledger 項(xiàng)目,其中包括 30 家來自中國本土的企業(yè),包括艾億新融旗下的艾億數(shù)融科技公司(2016.05.19)、Onchain(2016.06.22)、比鄰共贏(Belink)信息技術(shù)有限公司(2016.06.22)、BitSE(2016.06.22)、布比(2016.07.27)、三一重工(2016.08.30)、萬達(dá)金融(2016.09.08)、華為(2016.10.24)等。

如果說以比特幣為代表的貨幣區(qū)塊鏈技術(shù)為 1.0,以以太坊為代表的合同區(qū)塊鏈技術(shù)為 2.0,那么實(shí)現(xiàn)了完備的權(quán)限控制和安全保障的 Hyperledger 項(xiàng)目毫無疑問代表著 3.0 時(shí)代的到來。

IBM 貢獻(xiàn)了數(shù)萬行已有的 Open Blockchain 代碼,Digital Asset 則貢獻(xiàn)了企業(yè)和開發(fā)者相關(guān)資源,R3 貢獻(xiàn)了新的金融交易架構(gòu),Intel 也剛貢獻(xiàn)了跟分布式賬本相關(guān)的代碼。

Hyperledger 社區(qū)由技術(shù)委員會(huì)(Technical Steering Committee,TSC)指導(dǎo),首任主席由來自 IBM 開源技術(shù)部 CTO 的 Chris Ferris 擔(dān)任,管理組主席則由來自 Digital Asset Holdings 的 CEO Blythe Masters 擔(dān)任。另外,自 2016 年 5 月起,Apache 基金會(huì)創(chuàng)始人 Brian Behlendorf 擔(dān)任超級(jí)賬本項(xiàng)目的首位執(zhí)行董事。2016 年 12 月,中國技術(shù)工作組 正式成立,負(fù)責(zé)本土社區(qū)組織和技術(shù)引導(dǎo)工作。官方網(wǎng)站也提供了十分詳細(xì)的 組織結(jié)構(gòu)信息。

該項(xiàng)目的出現(xiàn),實(shí)際上宣布區(qū)塊鏈技術(shù)已經(jīng)不再是僅面向“社會(huì)實(shí)驗(yàn)”性質(zhì)的應(yīng)用場景,它已經(jīng)正式被主流機(jī)構(gòu)和企業(yè)市場認(rèn)可;同時(shí),Hyperledger 首次提出和實(shí)現(xiàn)的完備權(quán)限管理、創(chuàng)新的一致性算法和可拔插、可擴(kuò)展的框架,對于區(qū)塊鏈相關(guān)技術(shù)和產(chǎn)業(yè)的發(fā)展都將產(chǎn)生深遠(yuǎn)的影響。

2.項(xiàng)目組成

目前主要包括三大賬本平臺(tái)項(xiàng)目和若干其它項(xiàng)目。

賬本平臺(tái)項(xiàng)目:

  • **Fabric:包括 Fabric、Fabric CA、Fabric SDK(包括 Node.Js、Python 和 Java 等語言)和 fabric-api、fabric-sdk-node、fabric-sdk-py 等,目標(biāo)是區(qū)塊鏈的基礎(chǔ)核心平臺(tái),支持 pbft 等新的 consensus 機(jī)制,支持權(quán)限管理,最早由 IBM 和 DAH 發(fā)起;https://github.com/hyperledger/fabric
  • SawToothLake:包括 arcade、core、dev-tools、validator、mktplace 等。是 Intel 主要發(fā)起和貢獻(xiàn)的區(qū)塊鏈平臺(tái),支持全新的基于硬件芯片的共識(shí)機(jī)制 Proof of Elapsed Time(PoET)。
  • Iroha:賬本平臺(tái)項(xiàng)目,基于 C++ 實(shí)現(xiàn),帶有不少面向 Web 和 Mobile 的特性,主要由 Soramitsu 發(fā)起和貢獻(xiàn)。

其它項(xiàng)目:

  • Blockchain Explorer:提供 Web 操作界面,通過界面快速查看查詢綁定區(qū)塊鏈的狀態(tài)(區(qū)塊個(gè)數(shù)、交易歷史)信息等。
  • Cello:提供"Blockchain as a Service" 功能,使用 Cello,管理員可以輕松獲取和管理多條區(qū)塊鏈;應(yīng)用開發(fā)者可以無需關(guān)心如何搭建和維護(hù)區(qū)塊鏈。

項(xiàng)目約定共同遵守的 基本原則 為:

  • 重視模塊化設(shè)計(jì),包括交易、合同、一致性、身份、存儲(chǔ)等技術(shù)場景;
  • 代碼可讀性,保障新功能和模塊都可以很容易添加和擴(kuò)展;
  • 演化路線,隨著需求的深入和更多的應(yīng)用場景,不斷增加和演化新的項(xiàng)目。

3.聯(lián)盟鏈VS公鏈

公鏈:

針對所有用戶

激勵(lì)機(jī)制->代幣

聯(lián)盟鏈

針對特定的組織用戶

沒有激勵(lì)機(jī)制

應(yīng)用程序

數(shù)據(jù)共享

每一個(gè)行業(yè)都可以組成一個(gè)聯(lián)盟

二.Fabric環(huán)境搭建

1.安裝環(huán)境

推薦在 Linux(如 Ubuntu 16.04+)或 MacOS 環(huán)境中開發(fā)代碼,并安裝如下工具。

git:用來獲取代碼。

vim: 用來進(jìn)行文本編輯

curl: 部署腳本中會(huì)使用curl命令

$ sudo apt update
$ sudo apt install git vim curl -y

Docker 1.12+:用來支持容器環(huán)境,注意 MacOS 下要用 Docker for Mac。

$ sudo apt install docker.io docker-compose -y

golang 1.10+安裝成功后需要配置 $GOPATH 等環(huán)境變量。

  • Fabric1.1.0版本要求Go1.9+
  • Fabric1.0.0版本要求Go1.7+

    $ tar -zxvf go1.10.3.linux-amd64.tar.gz -C /usr/local/

2.配置環(huán)境變量

$ sudo vim /etc/profile

添加如下內(nèi)容

export GOPATH=$HOME/go
export GOROOT=/usr/local/go
export PATH=$GOROOT/bin:$PATH

讓配置生效

$ source /etc/profile
$ go version

3.下載源碼和鏡像

3.1 創(chuàng)建存放目錄

$ mkdir hyfa ;cd hyfa

3.2 下載源碼與鏡像

https://github.com/hyperledger/fabric/blob/master/scripts/bootstrap.sh

bootstrap.sh 腳本內(nèi)容,默認(rèn)版本為最新的版本:1.2.0

如果需要下載不同的版本號(hào),$1=指定版本號(hào)即可,如./bootstrap.sh 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.2.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.10
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>][-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.2.0 -s"
  echo "would download docker images and binaries for version 1.2.0"
}

dockerFabricPull() {
  local FABRIC_TAG=$1
  for IMAGES in peer orderer ccenv 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} 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
}

# 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 - ${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..."
          localMd5sum=$(md5sum ${BINARY_FILE} | awk '{print $1}')
          remoteMd5sum=$(curl -s ${URL}.md5)
          if [ "$localMd5sum" == "$remoteMd5sum" ]; then
              echo "==> Extracting ${BINARY_FILE}..."
              tar xzf ./${BINARY_FILE} --overwrite
          echo "==> Done."
              rm -f ${BINARY_FILE} ${BINARY_FILE}.md5
          else
              echo "Download failed: the local md5sum is different from the remote md5sum. Please try again."
              rm -f ${BINARY_FILE} ${BINARY_FILE}.md5
              exit 1
          fi
      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 ${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://nexus.hyperledger.org/content/repositories/releases/org/hyperledger/fabric/hyperledger-fabric/${ARCH}-${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://nexus.hyperledger.org/content/repositories/releases/org/hyperledger/fabric-ca/hyperledger-fabric-ca/${ARCH}-${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 ]; then
  VERSION=$1;shift
  if [ ! -z $1 ]; then
    CA_VERSION=$1;shift
    if [ ! -z $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

3.3 執(zhí)行腳本

$chmod +x bootstrap.sh   ; ./bootstrap.sh 

(1) 下載源碼包

  • 下載fabric壓縮包

    ===> Downloading version 1.2.0 platform specific fabric binaries
    ===> Downloading: https://nexus.hyperledger.org/content/repositories/releases/org/hyperledger/fabric/hyperledger-fabric/linux-amd64-1.2.0/hyperledger-fabric-linux-amd64-1.2.0.tar.gz
    % Total % Received % Xferd Average Speed Time Time Time Current
    Dload Upload Total Spent Left Speed
    100 39.0M 100 39.0M 0 0 482k 0 0:01:22 0:01:22 --:--:-- 450k
    ==> Done.

  • 下載fabric-ca-client壓縮包

    ===> Downloading version 1.2.0 platform specific fabric-ca-client binary
    ===> Downloading: https://nexus.hyperledger.org/content/repositories/releases/org/hyperledger/fabric-ca/hyperledger-fabric-ca/linux-amd64-1.2.0/hyperledger-fabric-ca-linux-amd64-1.2.0.tar.gz
    % Total % Received % Xferd Average Speed Time Time Time Current
    Dload Upload Total Spent Left Speed
    100 4940k 100 4940k 0 0 435k 0 0:00:11 0:00:11 --:--:-- 538k
    ==> Done.

(2)下載Fabric核心模塊鏡像

  • peer :fabric環(huán)境中的peer容器, 主要用來背書, 記賬
    peer模塊是主節(jié)點(diǎn)模塊,負(fù)責(zé)存儲(chǔ)區(qū)塊鏈數(shù)據(jù),運(yùn)行維護(hù)鏈碼

    ==> FABRIC IMAGE: peer

    1.2.0: Pulling from hyperledger/fabric-peer
    b234f539f7a1: Pull complete
    55172d420b43: Pull complete
    5ba5bbeb6b91: Pull complete
    43ae2841ad7a: Pull complete
    f6c9c6de4190: Pull complete
    c6af77e36488: Pull complete
    964f7f4f22f3: Pull complete
    d4a3f4cfba3d: Pull complete
    73782018d902: Pull complete
    039eb34e730e: Pull complete
    Digest: sha256:949b38bad9496d7694b54d30b90b72653804d761a44d721c4dc7a16a5cbcabe8
    Status: Downloaded newer image for hyperledger/fabric-peer:1.2.0

  • order:主要用于對交易排序且生成區(qū)塊

orderer模塊負(fù)責(zé)對交易進(jìn)行排序,并將排序好的交易打包成區(qū)塊。

==> FABRIC IMAGE: orderer

1.2.0: Pulling from hyperledger/fabric-orderer
b234f539f7a1: Already exists 
55172d420b43: Already exists 
5ba5bbeb6b91: Already exists 
43ae2841ad7a: Already exists 
f6c9c6de4190: Already exists 
c6af77e36488: Already exists 
964f7f4f22f3: Already exists 
d4a3f4cfba3d: Already exists 
8d0e11f5a0f7: Pull complete 
0bda0f004d88: Pull complete 
Digest: sha256:1a8cbe6abef245432730035d08ea1d1aa54a50717136fa3be58f8af4570ad57e
Status: Downloaded newer image for hyperledger/fabric-orderer:1.2.0
  • ccenv:針對Go語言的容器

    ==> FABRIC IMAGE: ccenv

    1.2.0: Pulling from hyperledger/fabric-ccenv
    b234f539f7a1: Already exists
    55172d420b43: Already exists
    5ba5bbeb6b91: Already exists
    43ae2841ad7a: Already exists
    f6c9c6de4190: Already exists
    c6af77e36488: Already exists
    964f7f4f22f3: Already exists
    13cd31405e09: Pull complete
    e03b35c19d96: Pull complete
    96c2920985e3: Pull complete
    e91461be8304: Pull complete
    950c3368692b: Pull complete
    c5de8d20c137: Pull complete
    5536b64bc67b: Pull complete
    Digest: sha256:0a7fb37111cafce79cf89ca8d1af5ca6f721e60a8bd1b2b93521e671e3348af2
    Status: Downloaded newer image for hyperledger/fabric-ccenv:1.2.0

  • tools:fabric環(huán)境中的工具容器, 主要用來測試客戶端

    ==> FABRIC IMAGE: tools

    1.2.0: Pulling from hyperledger/fabric-tools
    b234f539f7a1: Already exists
    55172d420b43: Already exists
    5ba5bbeb6b91: Already exists
    43ae2841ad7a: Already exists
    f6c9c6de4190: Already exists
    c6af77e36488: Already exists
    964f7f4f22f3: Already exists
    13cd31405e09: Already exists
    e03b35c19d96: Already exists
    96c2920985e3: Already exists
    e91461be8304: Already exists
    314928def9dd: Pull complete
    d5b68ae13f8d: Pull complete
    dde25187799d: Pull complete
    Digest: sha256:284f997b33d6745b52d378f8c7ba1a208b8c13633f3ef63e68377b1986077cb6
    Status: Downloaded newer image for hyperledger/fabric-tools:1.2.0

(3)下載Fabric的CA鏡像

Fabric環(huán)境中的CA容器(fabric-ca: 用于認(rèn)證, 根據(jù)配置文件中指定的路徑檢查當(dāng)前用戶是否合法)

===> Pulling fabric ca Image
==> FABRIC CA IMAGE

1.2.0: Pulling from hyperledger/fabric-ca
b234f539f7a1: Already exists 
55172d420b43: Already exists 
5ba5bbeb6b91: Already exists 
43ae2841ad7a: Already exists 
f6c9c6de4190: Already exists 
c6af77e36488: Already exists 
964f7f4f22f3: Already exists 
f7a6370a6f7f: Pull complete 
37cc94e973b2: Pull complete 
a80e45d2f608: Pull complete 
8feb19f73d3a: Pull complete 
5f3ea048e0c0: Pull complete 
Digest: sha256:0a6f8b3af8537fa725dc40d09565c77b1b284f848f653c32cb4125b3134a8726
Status: Downloaded newer image for hyperledger/fabric-ca:1.2.0

(4) 下載第三方鏡像

  • couchdb:是一個(gè)可選DB,可選, 可將Fabric中默認(rèn)的DB替代為couchDB
    Apache CouchDB是一個(gè)開源數(shù)據(jù)庫,它是一個(gè)使用JSON作為存儲(chǔ)格式,JavaScript作為查詢語言,MapReduce和HTTP作為API的NoSQL數(shù)據(jù)庫。

    ===> Pulling thirdparty docker images
    ==> THIRDPARTY DOCKER IMAGE: couchdb

    0.4.10: Pulling from hyperledger/fabric-couchdb
    b234f539f7a1: Already exists
    55172d420b43: Already exists
    5ba5bbeb6b91: Already exists
    43ae2841ad7a: Already exists
    f6c9c6de4190: Already exists
    c6af77e36488: Already exists
    964f7f4f22f3: Already exists
    13cd31405e09: Already exists
    e03b35c19d96: Already exists
    96c2920985e3: Already exists
    e91461be8304: Already exists
    6a752ce8f7fe: Pull complete
    a49e2cb854b0: Pull complete
    493b25e70e6d: Pull complete
    2721753a3e7c: Pull complete
    adede0f2a5f1: Pull complete
    9eb593f76305: Pull complete
    bb49a3450e11: Pull complete
    929b9bb5d788: Pull complete
    Digest: sha256:d7eb3fd24acafaeaaae94a44659409270b89bd599d017cf9d5b75d8f21438b51
    Status: Downloaded newer image for hyperledger/fabric-couchdb:0.4.10

  • kafka :
    Kafka是一個(gè)消息系統(tǒng),原本開發(fā)自LinkedIn,用作LinkedIn的活動(dòng)流(Activity Stream)和運(yùn)營數(shù)據(jù)處理管道(Pipeline)的基礎(chǔ)。現(xiàn)在它已被多家不同類型的公司 作為多種類型的數(shù)據(jù)管道和消息系統(tǒng)使用。

    ==> THIRDPARTY DOCKER IMAGE: kafka

    0.4.10: Pulling from hyperledger/fabric-kafka
    b234f539f7a1: Already exists
    55172d420b43: Already exists
    5ba5bbeb6b91: Already exists
    43ae2841ad7a: Already exists
    f6c9c6de4190: Already exists
    c6af77e36488: Already exists
    964f7f4f22f3: Already exists
    13cd31405e09: Already exists
    e03b35c19d96: Already exists
    96c2920985e3: Already exists
    e91461be8304: Already exists
    146aa6695f33: Pull complete
    954e41d8cd46: Pull complete
    9d750070047f: Pull complete
    Digest: sha256:7c07db5b38ca3259528b3e53691ecd273e44d1521218aa8f3a5dc34ab6947ff5
    Status: Downloaded newer image for hyperledger/fabric-kafka:0.4.10

  • zookeeper:主要用來作共識(shí),在開發(fā)測試環(huán)境下可選, 一般在開發(fā)測試環(huán)境下為單點(diǎn)模式

ZooKeeper曾是Hadoop的正式子項(xiàng)目,后發(fā)展成為Apache頂級(jí)項(xiàng)目,與Hadoop密切相關(guān)但卻沒有任何依賴。它是一個(gè)針對大型應(yīng)用提供高可用的數(shù)據(jù)管理、應(yīng)用程序協(xié)調(diào)服務(wù)的分布式服務(wù)框架,基于對Paxos算法的實(shí)現(xiàn),使該框架保證了分布式環(huán)境中數(shù)據(jù)的強(qiáng)一致性,提供的功能包括:配置維護(hù)、統(tǒng)一命名服務(wù)、狀態(tài)同步服務(wù)、集群管理等。

==> THIRDPARTY DOCKER IMAGE: zookeeper

0.4.10: Pulling from hyperledger/fabric-zookeeper
b234f539f7a1: Already exists 
55172d420b43: Already exists 
5ba5bbeb6b91: Already exists 
43ae2841ad7a: Already exists 
f6c9c6de4190: Already exists 
c6af77e36488: Already exists 
964f7f4f22f3: Already exists 
13cd31405e09: Already exists 
e03b35c19d96: Already exists 
96c2920985e3: Already exists 
e91461be8304: Already exists 
c335e6e59168: Pull complete 
016e000b0cc8: Pull complete 
e716b0c9790c: Pull complete 
390f47e71470: Pull complete 
Digest: sha256:151fe67421663fe860c1aba4b80877a22b6b8fa18cbc97990c309c603cd6f5f1
Status: Downloaded newer image for hyperledger/fabric-zookeeper:0.4.10

3.4 腳本執(zhí)行結(jié)果

(1) 源碼包文件結(jié)構(gòu)

bruce@ubuntu:~$ls hyfa/fabric-samples/ -l

返回結(jié)果

total 76
drwxrwxr-x 5 bruce bruce  4096 Jul 10 00:59 balance-transfer
drwxrwxr-x 4 bruce bruce  4096 Jul 10 00:59 basic-network
drwxrwxr-x 2  1001  1001  4096 Jul  3 13:41 bin
drwxrwxr-x 8 bruce bruce  4096 Jul 10 00:59 chaincode
drwxrwxr-x 3 bruce bruce  4096 Jul 10 00:59 chaincode-docker-devmode
-rw-rw-r-- 1 bruce bruce   597 Jul 10 00:59 CODE_OF_CONDUCT.md
drwxrwxr-x 2  1001  1001  4096 Jul  3 12:04 config
-rw-rw-r-- 1 bruce bruce   961 Jul 10 00:59 CONTRIBUTING.md
drwxrwxr-x 2 bruce bruce  4096 Jul 10 00:59 fabcar
drwxrwxr-x 3 bruce bruce  4096 Jul 10 00:59 fabric-ca
drwxrwxr-x 6 bruce bruce  4096 Jul 10 00:59 first-network
drwxrwxr-x 4 bruce bruce  4096 Jul 10 00:59 high-throughput
-rw-rw-r-- 1 bruce bruce  3095 Jul 10 00:59 Jenkinsfile
-rw-rw-r-- 1 bruce bruce 11358 Jul 10 00:59 LICENSE
-rw-rw-r-- 1 bruce bruce   470 Jul 10 00:59 MAINTAINERS.md
-rw-rw-r-- 1 bruce bruce  1229 Jul 10 00:59 README.md
drwxrwxr-x 3 bruce bruce  4096 Jul 10 00:59 scripts

(2) 查看docker鏡像

bruce@ubuntu:~$ sudo docker images

返回結(jié)果

REPOSITORY                     TAG                 IMAGE ID            CREATED             SIZE
hyperledger/fabric-ca          1.2.0               66cc132bd09c        6 days ago          252MB
hyperledger/fabric-ca          latest              66cc132bd09c        6 days ago          252MB
hyperledger/fabric-tools       1.2.0               379602873003        6 days ago          1.51GB
hyperledger/fabric-tools       latest              379602873003        6 days ago          1.51GB
hyperledger/fabric-ccenv       1.2.0               6acf31e2d9a4        6 days ago          1.43GB
hyperledger/fabric-ccenv       latest              6acf31e2d9a4        6 days ago          1.43GB
hyperledger/fabric-orderer     1.2.0               4baf7789a8ec        6 days ago          152MB
hyperledger/fabric-orderer     latest              4baf7789a8ec        6 days ago          152MB
hyperledger/fabric-peer        1.2.0               82c262e65984        6 days ago          159MB
hyperledger/fabric-peer        latest              82c262e65984        6 days ago          159MB
hyperledger/fabric-zookeeper   0.4.10              2b51158f3898        11 days ago         1.44GB
hyperledger/fabric-zookeeper   latest              2b51158f3898        11 days ago         1.44GB
hyperledger/fabric-kafka       0.4.10              936aef6db0e6        11 days ago         1.45GB
hyperledger/fabric-kafka       latest              936aef6db0e6        11 days ago         1.45GB
hyperledger/fabric-couchdb     0.4.10              3092eca241fc        11 days ago         1.61GB
hyperledger/fabric-couchdb     latest              3092eca241fc        11 days ago         1.61GB

4.再次配置環(huán)境變量

為fabric的相關(guān)命令配置環(huán)境變量

$ sudo vim /etc/profile

添加如下內(nèi)容:

FabricSampleDir="/home/bruce/hyfa/fabric-samples"
export PATH=${FabricSampleDir}/bin:$PATH

讓配置生效

$ source /etc/profile

三.Fabric目錄結(jié)構(gòu)

1.三大核心工具

fabric-samples/bin/cryptogen
        cryptogen: 根據(jù)指定的配置文件,生成組織結(jié)構(gòu)及×××?xí)墓ぞ?
fabric-samples/bin/configtxgen
        configtxgen: 主要生成三種配置文件
            1. 生成Orderer初始區(qū)塊
            2. 生成應(yīng)用通道交易配置文件
            3. 錨節(jié)點(diǎn)更新配置文件
                錨節(jié)點(diǎn): 數(shù)據(jù)交換
fabric-samples/bin/configtxlator
        configtxlator: 用來在正在運(yùn)行的網(wǎng)絡(luò)聯(lián)盟鏈中添加一個(gè)新的組織

2.關(guān)鍵目錄

chaincode/
        Fabric示例鏈碼所在目錄
chaincode-docker-devmode/
        開啟開發(fā)測試模式
        在開發(fā)測試模式下鏈碼的存放目錄
config/
        關(guān)于orderer及peer配置信息的文件存放目錄
        configtx.yaml: 生成初始區(qū)塊及應(yīng)用通道交易配置文件的參考
        core.yaml: peer配置信息的參考
        orderer.yaml: orderer配置信息的參考
fabcar/
        測試Node環(huán)境的所在目錄
        有一個(gè)小汽車的應(yīng)用示例
fabric-ca/
        fabric基礎(chǔ)環(huán)境提供的一個(gè)簡單fabric-ca
first-network/
        與Fabric網(wǎng)絡(luò)相關(guān)的所有內(nèi)容

3.其他概念

聯(lián)盟:
    org1:
        peer0.org1.example.com
        peer1.org1.example.com

    org2:
        peer0.org2.example.com
        peer1.org2.example.com
應(yīng)用通道:
    用于隔離不同聯(lián)盟之間交易

Peer節(jié)點(diǎn)角色:
    1. 背書節(jié)點(diǎn)
        -- 在fabric中只能部分節(jié)點(diǎn)是背書節(jié)點(diǎn)
    2. 記賬節(jié)點(diǎn)(commiter)
        -- 在fabric中所有的Peer節(jié)點(diǎn)都是記賬節(jié)點(diǎn)
    3. 錨節(jié)點(diǎn)
        -- 通過配置文件指定
        -- 作用: 用于跨組織交換數(shù)據(jù)

背書: 在fabric中, 就是簽名的概念

四.Node環(huán)境搭建

后期我們需要使用Fabric SDK做應(yīng)用程序的開發(fā),官方雖然提供了Node.JS,Java,Go,Python等多種語言的SDK,但是由于整個(gè)Fabric太新了,很多SDK還不成熟和完善,所以一般采用Node JS的SDK,畢竟這個(gè)是功能畢竟齊全,而且也是官方示例的時(shí)候使用的SDK。

1.安裝nvm

由于Node版本的迭代速度很快,版本很多,不同項(xiàng)目對node的依賴不同,故需要切換不同node版本目前有n和nvm這兩個(gè)工具可以對Node進(jìn)行平滑升級(jí),n 命令是作為一個(gè) node 的模塊而存在,而 nvm 是一個(gè)獨(dú)立于 node/npm 的外部 shell 腳本,因此 nvm 命令相比 n更加全面,n更有局限性。

nvm 是 node 管理工具,有點(diǎn)類似管理 Ruby 的 rvm,如果是需要管理 Windows 下的 node,官方推薦是使用 nvmw 或 nvm-windows 。

$ sudo apt update
$ curl -o- https://raw.githubusercontent.com/creationix/nvm/v0.33.10/install.sh | bash

$ export NVM_DIR="$HOME/.nvm"
$ [ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh" 

2.安裝Node與npm

NPM是隨同NodeJS一起安裝的包管理工具,能解決NodeJS代碼部署上的很多問題,常見的使用場景有以下幾種:

  • 允許用戶從NPM服務(wù)器下載別人編寫的第三方包到本地使用。
  • 允許用戶從NPM服務(wù)器下載并安裝別人編寫的命令行程序到本地使用。
  • 允許用戶將自己編寫的包或命令行程序上傳到NPM服務(wù)器供別人使用。

    $ nvm install v8.11.1

檢查Node版本

$ node -v
v8.11.1

檢查npm版本

$ npm -v
5.6.0
向AI問一下細(xì)節(jié)

免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點(diǎn)不代表本網(wǎng)站立場,如果涉及侵權(quán)請聯(lián)系站長郵箱:is@yisu.com進(jìn)行舉報(bào),并提供相關(guān)證據(jù),一經(jīng)查實(shí),將立刻刪除涉嫌侵權(quán)內(nèi)容。

AI