Hyperledger Fabric初識與環境搭建

目錄node

  1. Fabric簡介
  2. Fabric環境搭建
  3. Fabric目錄結構
  4. Node環境搭建

一.Fabric 簡介linux

在介紹咱們的主角Fabric以前,咱們先來介紹一下它的父項目:Hyperledger-超級帳本git

Hyperledger 項目是首個面向企業的開放區塊鏈技術的重要探索。在 Linux 基金會的支持下,吸引了包括 IBM、Intel、摩根等在內的衆多科技和金融巨頭的參與。github

1.發展歷史golang

區塊鏈已經成爲當下最受人關注的開源技術,有人說它將顛覆金融行業的將來。然而對不少人來講,區塊鏈技術難以理解和實現,並且缺少統一的規範。算法

2015 年 12 月,開源世界的旗艦——Linux 基金 會牽頭,聯合 30 家初始企業成員(包括 IBM、Accenture、Intel、J.P.Morgan、R三、DAH、DTCC、FUJITSU、HITACHI、SWIFT、Cisco 等),共同 宣告 了 Hyperledger 項目的成立。該項目試圖打造一個透明、公開、去中心化的分佈式帳本項目,做爲區塊鏈技術的開源規範和標準,讓更多的應用能更容易的創建在區塊鏈技術之上。項目官方信息網站在 hyperledger.org,docker

目前已經有超過 120 家全球知名企業和機構(大部分均爲各自行業的領導者)宣佈加入 Hyperledger 項目,其中包括 30 家來自中國本土的企業,包括艾億新融旗下的艾億數融科技公司(2016.05.19)、Onchain(2016.06.22)、比鄰雙贏(Belink)信息技術有限公司(2016.06.22)、BitSE(2016.06.22)、布比(2016.07.27)、三一重工(2016.08.30)、萬達金融(2016.09.08)、華爲(2016.10.24)等。shell

若是說以比特幣爲表明的貨幣區塊鏈技術爲 1.0,以以太坊爲表明的合同區塊鏈技術爲 2.0,那麼實現了完備的權限控制和安全保障的 Hyperledger 項目毫無疑問表明着 3.0 時代的到來。數據庫

IBM 貢獻了數萬行已有的 Open Blockchain 代碼,Digital Asset 則貢獻了企業和開發者相關資源,R3 貢獻了新的金融交易架構,Intel 也剛貢獻了跟分佈式帳本相關的代碼。npm

Hyperledger 社區由技術委員會(Technical Steering Committee,TSC)指導,首任主席由來自 IBM 開源技術部 CTO 的 Chris Ferris 擔任,管理組主席則由來自 Digital Asset Holdings 的 CEO Blythe Masters 擔任。另外,自 2016 年 5 月起,Apache 基金會創始人 Brian Behlendorf 擔任超級帳本項目的首位執行董事。2016 年 12 月,中國技術工做組 正式成立,負責本土社區組織和技術引導工做。官方網站也提供了十分詳細的 組織結構信息。

該項目的出現,實際上宣佈區塊鏈技術已經再也不是僅面向「社會實驗」性質的應用場景,它已經正式被主流機構和企業市場承認;同時,Hyperledger 首次提出和實現的完備權限管理、創新的一致性算法和可拔插、可擴展的框架,對於區塊鏈相關技術和產業的發展都將產生深遠的影響。

2.項目組成

目前主要包括三大帳本平臺項目和若干其它項目。

帳本平臺項目:

  • **Fabric:包括 Fabric、Fabric CA、Fabric SDK(包括 Node.Js、Python 和 Java 等語言)和 fabric-api、fabric-sdk-node、fabric-sdk-py 等,目標是區塊鏈的基礎核心平臺,支持 pbft 等新的 consensus 機制,支持權限管理,最先由 IBM 和 DAH 發起;https://github.com/hyperledger/fabric
  • SawToothLake:包括 arcade、core、dev-tools、validator、mktplace 等。是 Intel 主要發起和貢獻的區塊鏈平臺,支持全新的基於硬件芯片的共識機制 Proof of Elapsed Time(PoET)。
  • Iroha:帳本平臺項目,基於 C++ 實現,帶有很多面向 Web 和 Mobile 的特性,主要由 Soramitsu 發起和貢獻。

其它項目:

  • Blockchain Explorer:提供 Web 操做界面,經過界面快速查看查詢綁定區塊鏈的狀態(區塊個數、交易歷史)信息等。
  • Cello:提供"Blockchain as a Service" 功能,使用 Cello,管理員能夠輕鬆獲取和管理多條區塊鏈;應用開發者能夠無需關心如何搭建和維護區塊鏈。

項目約定共同遵照的 基本原則 爲:

  • 重視模塊化設計,包括交易、合同、一致性、身份、存儲等技術場景;
  • 代碼可讀性,保障新功能和模塊均可以很容易添加和擴展;
  • 演化路線,隨着需求的深刻和更多的應用場景,不斷增長和演化新的項目。

3.聯盟鏈VS公鏈

公鏈:

針對全部用戶

激勵機制->代幣

聯盟鏈

針對特定的組織用戶

沒有激勵機制

應用程序

數據共享

每個行業均可以組成一個聯盟

二.Fabric環境搭建

1.安裝環境

推薦在 Linux(如 Ubuntu 16.04+)或 MacOS 環境中開發代碼,並安裝以下工具。

git:用來獲取代碼。

vim: 用來進行文本編輯

curl: 部署腳本中會使用curl命令

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

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

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

golang 1.10+安裝成功後須要配置 $GOPATH 等環境變量。

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

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

2.配置環境變量

$ sudo vim /etc/profile

添加以下內容

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

讓配置生效

$ source /etc/profile
$ go version

3.下載源碼和鏡像

3.1 建立存放目錄

$ mkdir hyfa ;cd hyfa

3.2 下載源碼與鏡像

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

bootstrap.sh 腳本內容,默認版本爲最新的版本:1.2.0

若是須要下載不一樣的版本號,$1=指定版本號便可,如./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 執行腳本

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

(1) 下載源碼包

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

  • peer :fabric環境中的peer容器, 主要用來背書, 記帳
    peer模塊是主節點模塊,負責存儲區塊鏈數據,運行維護鏈碼

    ==> 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:主要用於對交易排序且生成區塊

orderer模塊負責對交易進行排序,並將排序好的交易打包成區塊。

==> 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環境中的工具容器, 主要用來測試客戶端

    ==> 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環境中的CA容器(fabric-ca: 用於認證, 根據配置文件中指定的路徑檢查當前用戶是否合法)

===> 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:是一個可選DB,可選, 可將Fabric中默認的DB替代爲couchDB
    Apache CouchDB是一個開源數據庫,它是一個使用JSON做爲存儲格式,JavaScript做爲查詢語言,MapReduce和HTTP做爲API的NoSQL數據庫。

    ===> 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是一個消息系統,本來開發自LinkedIn,用做LinkedIn的活動流(Activity Stream)和運營數據處理管道(Pipeline)的基礎。如今它已被多家不一樣類型的公司 做爲多種類型的數據管道和消息系統使用。

    ==> 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:主要用來做共識,在開發測試環境下可選, 通常在開發測試環境下爲單點模式

ZooKeeper曾是Hadoop的正式子項目,後發展成爲Apache頂級項目,與Hadoop密切相關但卻沒有任何依賴。它是一個針對大型應用提供高可用的數據管理、應用程序協調服務的分佈式服務框架,基於對Paxos算法的實現,使該框架保證了分佈式環境中數據的強一致性,提供的功能包括:配置維護、統一命名服務、狀態同步服務、集羣管理等。

==> 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 腳本執行結果

(1) 源碼包文件結構

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

返回結果

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

返回結果

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.再次配置環境變量

爲fabric的相關命令配置環境變量

$ sudo vim /etc/profile

添加以下內容:

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

讓配置生效

$ source /etc/profile

三.Fabric目錄結構

1.三大核心工具

fabric-samples/bin/cryptogen
        cryptogen: 根據指定的配置文件,生成組織結構及×××書的工具

fabric-samples/bin/configtxgen
        configtxgen: 主要生成三種配置文件
            1. 生成Orderer初始區塊
            2. 生成應用通道交易配置文件
            3. 錨節點更新配置文件
                錨節點: 數據交換
fabric-samples/bin/configtxlator
        configtxlator: 用來在正在運行的網絡聯盟鏈中添加一個新的組織

2.關鍵目錄

chaincode/
        Fabric示例鏈碼所在目錄
chaincode-docker-devmode/
        開啓開發測試模式
        在開發測試模式下鏈碼的存放目錄
config/
        關於orderer及peer配置信息的文件存放目錄
        configtx.yaml: 生成初始區塊及應用通道交易配置文件的參考
        core.yaml: peer配置信息的參考
        orderer.yaml: orderer配置信息的參考
fabcar/
        測試Node環境的所在目錄
        有一個小汽車的應用示例
fabric-ca/
        fabric基礎環境提供的一個簡單fabric-ca
first-network/
        與Fabric網絡相關的全部內容

3.其餘概念

聯盟:
    org1:
        peer0.org1.example.com
        peer1.org1.example.com

    org2:
        peer0.org2.example.com
        peer1.org2.example.com
應用通道:
    用於隔離不一樣聯盟之間交易

Peer節點角色:
    1. 背書節點
        -- 在fabric中只能部分節點是背書節點
    2. 記帳節點(commiter)
        -- 在fabric中全部的Peer節點都是記帳節點
    3. 錨節點
        -- 經過配置文件指定
        -- 做用: 用於跨組織交換數據

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

四.Node環境搭建

後期咱們須要使用Fabric SDK作應用程序的開發,官方雖然提供了Node.JS,Java,Go,Python等多種語言的SDK,可是因爲整個Fabric太新了,不少SDK還不成熟和完善,因此通常採用Node JS的SDK,畢竟這個是功能畢竟齊全,並且也是官方示例的時候使用的SDK。

1.安裝nvm

因爲Node版本的迭代速度很快,版本不少,不一樣項目對node的依賴不一樣,故須要切換不一樣node版本目前有n和nvm這兩個工具能夠對Node進行平滑升級,n 命令是做爲一個 node 的模塊而存在,而 nvm 是一個獨立於 node/npm 的外部 shell 腳本,所以 nvm 命令相比 n更加全面,n更有侷限性。

nvm 是 node 管理工具,有點相似管理 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服務器下載別人編寫的第三方包到本地使用。
  • 容許用戶從NPM服務器下載並安裝別人編寫的命令行程序到本地使用。
  • 容許用戶將本身編寫的包或命令行程序上傳到NPM服務器供別人使用。

    $ nvm install v8.11.1

檢查Node版本

$ node -v
v8.11.1

檢查npm版本

$ npm -v
5.6.0
相關文章
相關標籤/搜索